From 38876c22093f14dc0c6aae3de3287185ee93cd7f Mon Sep 17 00:00:00 2001 From: Anshum Gupta Date: Thu, 21 May 2015 17:21:44 +0000 Subject: [PATCH] SOLR-7274: Stop forwarding Authorization, Host, and Accept headers for SPNego to work. Also fixed an exception forwarding from SDF and reconfigure SDF's httpClient after authentication has been initialized. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1680931 13f79535-47bb-0310-9956-ffa450edef68 --- .../handler/component/HttpShardHandlerFactory.java | 4 +--- .../java/org/apache/solr/servlet/HttpSolrCall.java | 6 +++++- .../org/apache/solr/servlet/SolrDispatchFilter.java | 12 +++++++++++- .../org/apache/solr/update/UpdateShardHandler.java | 4 +--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java index 6aae2e1140d..203e779716a 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java @@ -194,9 +194,7 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org. */ public void reconfigureHttpClient(HttpClientConfigurer configurer) { log.info("Reconfiguring the default client with: " + configurer); - synchronized (this.defaultClient) { - configurer.configure((DefaultHttpClient)this.defaultClient, getClientParams()); - } + configurer.configure((DefaultHttpClient)this.defaultClient, getClientParams()); } protected ThreadPoolExecutor getThreadPoolExecutor(){ diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java index 3434f2902ac..d4574d9be5b 100644 --- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java +++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java @@ -511,7 +511,11 @@ public class HttpSolrCall { for (Enumeration e = req.getHeaderNames(); e.hasMoreElements(); ) { String headerName = e.nextElement(); - method.addHeader(headerName, req.getHeader(headerName)); + if (!"host".equalsIgnoreCase(headerName) + && !"authorization".equalsIgnoreCase(headerName) + && !"accept".equalsIgnoreCase(headerName)) { + method.addHeader(headerName, req.getHeader(headerName)); + } } // These headers not supported for HttpEntityEnclosingRequests if (method instanceof HttpEntityEnclosingRequest) { diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index f5d8ef55bef..db7963dc1b7 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -24,6 +24,7 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; @@ -36,6 +37,8 @@ import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.solr.client.solrj.impl.HttpClientConfigurer; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -106,6 +109,13 @@ public class SolrDispatchFilter extends BaseSolrFilter { this.cores = createCoreContainer(solrHome, extraProperties); + if (this.cores.getAuthenticationPlugin() != null) { + HttpClientConfigurer configurer = this.cores.getAuthenticationPlugin().getDefaultConfigurer(); + if (configurer != null) { + configurer.configure((DefaultHttpClient)httpClient, new ModifiableSolrParams()); + } + } + log.info("user.dir=" + System.getProperty("user.dir")); } catch( Throwable t ) { @@ -248,7 +258,7 @@ public class SolrDispatchFilter extends BaseSolrFilter { }); } catch (Exception e) { e.printStackTrace(); - throw new SolrException(ErrorCode.SERVER_ERROR, "Error during request authentication, "+e); + throw new SolrException(ErrorCode.SERVER_ERROR, "Error during request authentication, ", e); } } // failed authentication? 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 ff84c35ccd5..0273b0a428c 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java @@ -90,9 +90,7 @@ public class UpdateShardHandler { public void reconfigureHttpClient(HttpClientConfigurer configurer) { log.info("Reconfiguring the default client with: " + configurer); - synchronized (client) { - configurer.configure((DefaultHttpClient)client, getClientParams()); - } + configurer.configure((DefaultHttpClient)client, getClientParams()); } public ClientConnectionManager getConnectionManager() {