You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/09/20 07:50:21 UTC

lucene-solr:jira/http2: SOLR-12644: Setting credential for updateOnlyClient and setting basic auth for request

Repository: lucene-solr
Updated Branches:
  refs/heads/jira/http2 d6409336b -> 4cc995c61


SOLR-12644: Setting credential for updateOnlyClient and setting basic auth for request


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4cc995c6
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4cc995c6
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4cc995c6

Branch: refs/heads/jira/http2
Commit: 4cc995c61b88f3af3aecdc170497017d56fb61de
Parents: d640933
Author: Cao Manh Dat <da...@apache.org>
Authored: Thu Sep 20 14:50:13 2018 +0700
Committer: Cao Manh Dat <da...@apache.org>
Committed: Thu Sep 20 14:50:13 2018 +0700

----------------------------------------------------------------------
 .../src/java/org/apache/solr/core/CoreContainer.java    |  1 +
 .../java/org/apache/solr/update/UpdateShardHandler.java |  6 ++++++
 .../apache/solr/security/BasicAuthIntegrationTest.java  |  5 +++++
 .../apache/solr/client/solrj/impl/Http2SolrClient.java  | 12 +++++++++++-
 4 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4cc995c6/solr/core/src/java/org/apache/solr/core/CoreContainer.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 7643996..c1d9c58 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -401,6 +401,7 @@ public class CoreContainer {
       HttpClientBuilderPlugin builderPlugin = ((HttpClientBuilderPlugin) authcPlugin);
       SolrHttpClientBuilder builder = builderPlugin.getHttpClientBuilder(HttpClientUtil.getHttpClientBuilder());
       shardHandlerFactory.setSecurityBuilder(builder);
+      updateShardHandler.setSecurityBuilder(builder);
 
       // The default http client of the core container's shardHandlerFactory has already been created and
       // configured using the default httpclient configurer. We need to reconfigure it using the plugin's

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4cc995c6/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
index ff3d9d1..4c9e703 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
@@ -30,6 +30,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.solr.client.solrj.impl.Http2SolrClient;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ExecutorUtil;
@@ -248,4 +249,9 @@ public class UpdateShardHandler implements SolrMetricProducer, SolrInfoBean {
     return connectionTimeout;
   }
 
+  public void setSecurityBuilder(SolrHttpClientBuilder builder) {
+    if (builder != null) {
+      builder.applyHttp2Configurator(updateOnlyClient);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4cc995c6/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
index 95d243d..fd03b31 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
@@ -194,6 +194,11 @@ public class BasicAuthIntegrationTest extends SolrCloudTestCase {
 
       executeCommand(baseUrl + authzPrefix, cl,"{set-permission : { name : update , role : admin}}", "harry", "HarryIsUberCool");
 
+      UpdateRequest del = new UpdateRequest().deleteByQuery("*:*");
+      del.setBasicAuthCredentials("harry","HarryIsUberCool");
+      del.setCommitWithin(10);
+      del.process(cluster.getSolrClient(), COLLECTION);
+
       SolrInputDocument doc = new SolrInputDocument();
       doc.setField("id","4");
       UpdateRequest update = new UpdateRequest();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4cc995c6/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 57a0dd7..dfaf362 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -58,6 +58,7 @@ import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.params.UpdateParams;
+import org.apache.solr.common.util.Base64;
 import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.ObjectReleaseTracker;
@@ -169,7 +170,7 @@ public class Http2SolrClient extends SolrClient {
     } else {
       httpClient = builder.httpClient;
     }
-    if (builder.beginListener != null) this.beginListener = builder.beginListener;
+    if (builder.beginListener != null) setBeginListener(builder.beginListener);
     if (!httpClient.isStarted()) {
       try {
         httpClient.start();
@@ -269,6 +270,7 @@ public class Http2SolrClient extends SolrClient {
                                       OnComplete onComplete,
                                       boolean returnStream) throws IOException, SolrServerException {
     Request req = makeRequest(solrRequest, collection);
+    setBasicAuthHeader(solrRequest, req);
     if (listenerFactory != null) {
       HttpListenerFactory.RequestResponseListener listener = listenerFactory.get();
       req.onRequestBegin(listener);
@@ -351,6 +353,14 @@ public class Http2SolrClient extends SolrClient {
     this.listenerFactory = listenerFactory;
   }
 
+  private void setBasicAuthHeader(SolrRequest solrRequest, Request req) throws UnsupportedEncodingException {
+    if (solrRequest.getBasicAuthUser() != null && solrRequest.getBasicAuthPassword() != null) {
+      String userPass = solrRequest.getBasicAuthUser() + ":" + solrRequest.getBasicAuthPassword();
+      String encoded = Base64.byteArrayToBase64(userPass.getBytes(UTF_8));
+      req.header("Authorization", "Basic " + encoded);
+    }
+  }
+
   private Request makeRequest(SolrRequest solrRequest, String collection)
       throws SolrServerException, IOException {
     if (solrRequest.getBasePath() == null && serverBaseUrl == null)