gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject gora git commit: GORA-262 Add support for HTTPClient authentication in gora-solr
Date Tue, 19 May 2015 17:28:00 GMT
Repository: gora
Updated Branches:
  refs/heads/master 534b65942 -> 9540273d8


GORA-262 Add support for HTTPClient authentication in gora-solr


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/9540273d
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/9540273d
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/9540273d

Branch: refs/heads/master
Commit: 9540273d85d38835b651c76286e499d7aa418c16
Parents: 534b659
Author: Lewis John McGibbney <lewis.j.mcgibbney@jpl.nasa.gov>
Authored: Tue May 19 10:30:02 2015 -0700
Committer: Lewis John McGibbney <lewis.j.mcgibbney@jpl.nasa.gov>
Committed: Tue May 19 10:30:02 2015 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../org/apache/gora/solr/store/SolrStore.java   | 65 ++++++++++++++++++--
 gora-solr/src/test/conf/gora.properties         |  4 +-
 3 files changed, 66 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/9540273d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 94987d3..c156e88 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,8 @@
 Apache Gora 0.6.1 Release - 02/03/2015 (dd/mm/yyyy)
 Release Report - http://s.apache.org/l69 
 
+* GORA-262 Add support for HTTPClient authentication in gora-solr (Furkan KAMACI via lewismc)
+
 * GORA-384 Provide documentation on Gora Shims layer (lewismc)
 
 * GORA-415 hadoop-client dependency should be optional in gora-core (hsaputra via lewismc)

http://git-wip-us.apache.org/repos/asf/gora/blob/9540273d/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java
----------------------------------------------------------------------
diff --git a/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java b/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java
index a8c025b..f89762c 100644
--- a/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java
+++ b/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java
@@ -43,12 +43,10 @@ import org.apache.gora.store.impl.DataStoreBase;
 import org.apache.gora.util.AvroUtils;
 import org.apache.gora.util.IOUtils;
 import org.apache.hadoop.util.StringUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.CloudSolrServer;
-import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer;
-import org.apache.solr.client.solrj.impl.HttpSolrServer;
-import org.apache.solr.client.solrj.impl.LBHttpSolrServer;
+import org.apache.solr.client.solrj.impl.*;
 import org.apache.solr.client.solrj.request.CoreAdminRequest;
 import org.apache.solr.client.solrj.response.CoreAdminResponse;
 import org.apache.solr.client.solrj.response.QueryResponse;
@@ -92,6 +90,27 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K,
T>
    */
   protected static final String SOLR_SOLRJSERVER_IMPL = "solr.solrjserver";
 
+  /** Whether to use secured Solr client or not.
+   * Available options include <b>true</b>, and <b>false</b>.
+   * Defined in <code>gora.properties</code>
+   * This value must be of type <b>boolean</b>.
+   */
+  protected static final String SOLR_SERVER_USER_AUTH = "solr.solrjserver.user_auth";
+
+  /** Solr client username.
+   * Solr client user authentication should be enabled for this property.
+   * Defined in <code>gora.properties</code>
+   * This value must be of type <b>String</b>.
+   */
+  protected static final String SOLR_SERVER_USERNAME = "solr.solrjserver.username";
+
+  /** Solr client password.
+   * Solr client user authentication should be enabled for this property.
+   * Defined in <code>gora.properties</code>
+   * This value must be of type <b>String</b>.
+   */
+  protected static final String SOLR_SERVER_PASSWORD = "solr.solrjserver.password";
+
   /** A batch commit unit for SolrDocument's used when making (commit) calls to Solr.
    * Should be defined in <code>gora.properties</code>. 
    * A default value of 1000 is used if this value is absent. This value must be of type
<b>Integer</b>.
@@ -128,6 +147,12 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K,
T>
 
   private SolrServer server, adminServer;
 
+  private boolean serverUserAuth;
+
+  private String serverUsername;
+
+  private String serverPassword;
+
   private ArrayList<SolrInputDocument> batch;
 
   private int batchSize = DEFAULT_BATCH_SIZE;
@@ -173,6 +198,14 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K,
T>
         SOLR_SCHEMA_PROPERTY, null);
     solrJServerImpl = DataStoreFactory.findProperty(properties, this, 
         SOLR_SOLRJSERVER_IMPL, "http");
+    serverUserAuth = DataStoreFactory.findBooleanProperty(properties, this,
+        SOLR_SERVER_USER_AUTH, "false");
+    if (serverUserAuth) {
+      serverUsername = DataStoreFactory.findProperty(properties, this,
+          SOLR_SERVER_USERNAME, null);
+      serverPassword = DataStoreFactory.findProperty(properties, this,
+          SOLR_SERVER_PASSWORD, null);
+    }
     LOG.info("Using Solr server at " + solrServerUrl);
     String solrJServerType = ((solrJServerImpl == null || solrJServerImpl.equals(""))?"http":solrJServerImpl);
     // HttpSolrServer - denoted by "http" in properties
@@ -180,11 +213,27 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K,
T>
       LOG.info("Using HttpSolrServer Solrj implementation.");
       this.adminServer = new HttpSolrServer(solrServerUrl);
       this.server = new HttpSolrServer( solrServerUrl + "/" + mapping.getCoreName() );
+      if (serverUserAuth) {
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((HttpSolrServer) adminServer).getHttpClient(),
+            serverUsername, serverPassword);
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((HttpSolrServer) server).getHttpClient(),
+            serverUsername, serverPassword);
+      }
       // CloudSolrServer - denoted by "cloud" in properties
     } else if (solrJServerType.toString().toLowerCase().equals("cloud")) {
       LOG.info("Using CloudSolrServer Solrj implementation.");
       this.adminServer = new CloudSolrServer(solrServerUrl);
       this.server = new CloudSolrServer( solrServerUrl + "/" + mapping.getCoreName() );
+      if (serverUserAuth) {
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((CloudSolrServer) adminServer).getLbServer().getHttpClient(),
+            serverUsername, serverPassword);
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((CloudSolrServer) server).getLbServer().getHttpClient(),
+            serverUsername, serverPassword);
+      }
     } else if (solrJServerType.toString().toLowerCase().equals("concurrent")) {
       LOG.info("Using ConcurrentUpdateSolrServer Solrj implementation.");
       this.adminServer = new ConcurrentUpdateSolrServer(solrServerUrl, 1000, 10);
@@ -203,6 +252,14 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K,
T>
       } catch (MalformedURLException e) {
         e.printStackTrace();
       }
+      if (serverUserAuth) {
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((LBHttpSolrServer) adminServer).getHttpClient(),
+            serverUsername, serverPassword);
+        HttpClientUtil.setBasicAuth(
+            (DefaultHttpClient) ((LBHttpSolrServer) server).getHttpClient(),
+            serverUsername, serverPassword);
+      }
     }
     if (autoCreateSchema) {
       createSchema();

http://git-wip-us.apache.org/repos/asf/gora/blob/9540273d/gora-solr/src/test/conf/gora.properties
----------------------------------------------------------------------
diff --git a/gora-solr/src/test/conf/gora.properties b/gora-solr/src/test/conf/gora.properties
index e53fc95..27403e2 100644
--- a/gora-solr/src/test/conf/gora.properties
+++ b/gora-solr/src/test/conf/gora.properties
@@ -1,5 +1,4 @@
 # Licensed to the Apache Software Foundation (ASF) under one or more
-gora.solrstore.solr.solrjserver=http
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
 # The ASF licenses this file to You under the Apache License, Version 2.0
@@ -17,3 +16,6 @@ gora.solrstore.solr.solrjserver=http
 gora.solrstore.solr.url=http://localhost:9876/solr
 gora.datastore.solr.commit_within=0
 gora.solrstore.solr.solrjserver=http
+gora.solrstore.solr.solrjserver.user_auth=false
+#gora.solrstore.solr.solrjserver.username=solr-user
+#gora.solrstore.solr.solrjserver.password=solr-password


Mime
View raw message