Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-1189 -- Support providing username and password for basic HTTP authentication in Java replication

Shalin Shekhar Mangarda44adc8207a
diff --git a/CHANGES.txt b/CHANGES.txt
index d93aaa5cceb..417010e4fbe 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -232,6 +232,9 @@ New Features
58. SOLR-1204: Enhance SpellingQueryConverter to handle UTF-8 instead of ASCII only (Michael Ludwig via shalin)
+59. SOLR-1189: Support providing username and password for basic HTTP authentication in Java replication
+ (Matthew Gregg, shalin)
+
Optimizations
----------------------
1. SOLR-374: Use IndexReader.reopen to save resources by re-using parts of the
diff --git a/src/java/org/apache/solr/handler/SnapPuller.java b/src/java/org/apache/solr/handler/SnapPuller.java
index 75482eb0209..1f95beac7ea 100644
--- a/src/java/org/apache/solr/handler/SnapPuller.java
+++ b/src/java/org/apache/solr/handler/SnapPuller.java
@@ -17,6 +17,7 @@
package org.apache.solr.handler;
import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.index.IndexCommit;
@@ -103,6 +104,8 @@ public class SnapPuller {
private static HttpClient client;
// HttpClient for this instance if connectionTimeout or readTimeout has been specified
private final HttpClient myHttpClient;
+ private static final String HTTP_BASIC_AUTH_USER = "httpBasicAuthUser";
+ private static final String HTTP_BASIC_AUTH_PASSWORD = "httpBasicAuthPassword";
private static synchronized HttpClient createHttpClient(String connTimeout, String readTimeout) {
if (connTimeout == null && readTimeout == null && client != null) return client;
@@ -132,7 +135,13 @@ public class SnapPuller {
useExternal = EXTERNAL.equals(compress);
String connTimeout = (String) initArgs.get(HTTP_CONN_TIMEOUT);
String readTimeout = (String) initArgs.get(HTTP_READ_TIMEOUT);
+ String httpBasicAuthUser = (String) initArgs.get(HTTP_BASIC_AUTH_USER);
+ String httpBasicAuthPassword = (String) initArgs.get(HTTP_BASIC_AUTH_PASSWORD);
myHttpClient = createHttpClient(connTimeout, readTimeout);
+ if (httpBasicAuthUser != null && httpBasicAuthPassword != null) {
+ myHttpClient.getState().setCredentials(AuthScope.ANY,
+ new UsernamePasswordCredentials(httpBasicAuthUser, httpBasicAuthPassword));
+ }
if (pollInterval != null && pollInterval > 0) {
startExecutorService();
} else {