You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2015/08/05 17:00:49 UTC

svn commit: r1694239 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/core/ solr/core/src/java/org/apache/solr/request/ solr/core/src/java/org/apache/solr/security/ solr/core/src/java/org/apache/solr/servlet/ ...

Author: noble
Date: Wed Aug  5 15:00:48 2015
New Revision: 1694239

URL: http://svn.apache.org/r1694239
Log:
SOLR-7849: Solr-managed inter-node authentication when authentication enabled

Added:
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/HttpClientInterceptorPlugin.java
      - copied unchanged from r1694217, lucene/dev/trunk/solr/core/src/java/org/apache/solr/security/HttpClientInterceptorPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java
      - copied unchanged from r1694217, lucene/dev/trunk/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthenticationPlugin.java
      - copied unchanged from r1694217, lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/MockAuthenticationPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/PKIAuthenticationIntegrationTest.java
      - copied unchanged from r1694217, lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/PKIAuthenticationIntegrationTest.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java
      - copied, changed from r1694217, lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java
Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/CoreContainer.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/AuthenticationPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/CryptoKeys.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthorizationPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java
    lucene/dev/branches/branch_5x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/Base64.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Aug  5 15:00:48 2015
@@ -116,6 +116,8 @@ New Features
 
 * SOLR-7769: Add bin/post -p alias for -port parameter.  (ehatcher)
 
+* SOLR-7849: Solr-managed inter-node authentication when authentication enabled (Noble Paul)
+
 Bug Fixes
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/CoreContainer.java Wed Aug  5 15:00:48 2015
@@ -52,6 +52,8 @@ import org.apache.solr.logging.MDCLoggin
 import org.apache.solr.request.SolrRequestHandler;
 import org.apache.solr.security.AuthorizationPlugin;
 import org.apache.solr.security.AuthenticationPlugin;
+import org.apache.solr.security.HttpClientInterceptorPlugin;
+import org.apache.solr.security.PKIAuthenticationPlugin;
 import org.apache.solr.update.UpdateShardHandler;
 import org.apache.solr.util.DefaultSolrThreadFactory;
 import org.apache.solr.util.FileUtils;
@@ -60,6 +62,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.solr.security.AuthenticationPlugin.AUTHENTICATION_PLUGIN_PROP;
 
 
 /**
@@ -93,6 +96,8 @@ public class CoreContainer {
   protected CollectionsHandler collectionsHandler = null;
   private InfoHandler infoHandler;
 
+  private PKIAuthenticationPlugin pkiAuthenticationPlugin;
+
   protected Properties containerProperties;
 
   private ConfigSetService coreConfigService;
@@ -123,8 +128,6 @@ public class CoreContainer {
   public static final String COLLECTIONS_HANDLER_PATH = "/admin/collections";
   public static final String INFO_HANDLER_PATH = "/admin/info";
 
-  final public static String AUTHENTICATION_PLUGIN_PROP = "authenticationPlugin";
-
   private PluginBag<SolrRequestHandler> containerHandlers = new PluginBag<>(SolrRequestHandler.class, null);
 
   private boolean asyncSolrCoreLoad;
@@ -263,9 +266,15 @@ public class CoreContainer {
     }
     if (authenticationPlugin != null) {
       authenticationPlugin.init(authenticationConfig);
+      addHttpConfigurer(authenticationPlugin);
+    }
+  }
 
+  private void addHttpConfigurer(Object authcPlugin) {
+    log.info("addHttpConfigurer()");//TODO no commit
+    if (authcPlugin instanceof HttpClientInterceptorPlugin) {
       // Setup HttpClient to use the plugin's configurer for internode communication
-      HttpClientConfigurer configurer = authenticationPlugin.getDefaultConfigurer();
+      HttpClientConfigurer configurer = ((HttpClientInterceptorPlugin) authcPlugin).getClientConfigurer();
       HttpClientUtil.setConfigurer(configurer);
 
       // The default http client of the core container's shardHandlerFactory has already been created and
@@ -273,9 +282,14 @@ public class CoreContainer {
       // http client configurer to set it up for internode communication.
       log.info("Reconfiguring the shard handler factory and update shard handler.");
       if (getShardHandlerFactory() instanceof HttpShardHandlerFactory) {
-        ((HttpShardHandlerFactory)getShardHandlerFactory()).reconfigureHttpClient(configurer);
+        ((HttpShardHandlerFactory) getShardHandlerFactory()).reconfigureHttpClient(configurer);
       }
       getUpdateShardHandler().reconfigureHttpClient(configurer);
+    } else {
+      if (pkiAuthenticationPlugin != null) {
+        log.info("PKIAuthenticationPlugin is managing internode requests");
+        addHttpConfigurer(pkiAuthenticationPlugin);
+      }
     }
   }
 
@@ -316,6 +330,10 @@ public class CoreContainer {
     return containerProperties;
   }
 
+  public PKIAuthenticationPlugin getPkiAuthenticationPlugin() {
+    return pkiAuthenticationPlugin;
+  }
+
   //-------------------------------------------------------------------
   // Initialization / Cleanup
   //-------------------------------------------------------------------
@@ -347,6 +365,7 @@ public class CoreContainer {
     hostName = cfg.getNodeName();
 
     zkSys.initZooKeeper(this, solrHome, cfg.getCloudConfig());
+    if(isZooKeeperAware())  pkiAuthenticationPlugin = new PKIAuthenticationPlugin(this, zkSys.getZkController().getNodeName());
 
     initializeAuthenticationPlugin();
 
@@ -360,6 +379,8 @@ public class CoreContainer {
     containerHandlers.put(INFO_HANDLER_PATH, infoHandler);
     coreAdminHandler   = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
     containerHandlers.put(CORES_HANDLER_PATH, coreAdminHandler);
+    if(pkiAuthenticationPlugin != null)
+      containerHandlers.put(PKIAuthenticationPlugin.PATH, pkiAuthenticationPlugin.getRequestHandler());
 
     coreConfigService = ConfigSetService.createConfigSetService(cfg, loader, zkSys.zkController);
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java Wed Aug  5 15:00:48 2015
@@ -25,6 +25,7 @@ import org.apache.solr.common.params.Sol
 import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.core.SolrCore;
 
+import java.security.Principal;
 import java.util.Map;
 
 /**
@@ -97,6 +98,8 @@ public interface SolrQueryRequest {
   public Map<String,Object> getJSON();
 
   public void setJSON(Map<String,Object> json);
+
+  public Principal getUserPrincipal();
 }
 
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java Wed Aug  5 15:00:48 2015
@@ -27,6 +27,7 @@ import org.apache.solr.common.util.Conte
 import org.apache.solr.core.SolrCore;
 
 import java.io.Closeable;
+import java.security.Principal;
 import java.util.Map;
 import java.util.HashMap;
 
@@ -175,4 +176,8 @@ public abstract class SolrQueryRequestBa
     this.json = json;
   }
 
+  @Override
+  public Principal getUserPrincipal() {
+    return null;
+  }
 }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/AuthenticationPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/AuthenticationPlugin.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/AuthenticationPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/AuthenticationPlugin.java Wed Aug  5 15:00:48 2015
@@ -1,11 +1,19 @@
 package org.apache.solr.security;
 
 import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
 import java.io.Closeable;
+import java.io.IOException;
+import java.nio.file.attribute.UserPrincipal;
+import java.security.Principal;
 import java.util.Map;
 
+import org.apache.http.auth.BasicUserPrincipal;
 import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
 
 /*
@@ -31,11 +39,27 @@ import org.apache.solr.client.solrj.impl
  */
 public abstract class AuthenticationPlugin implements Closeable {
 
+  final public static String AUTHENTICATION_PLUGIN_PROP = "authenticationPlugin";
+
   /**
    * This is called upon loading up of a plugin, used for setting it up.
    * @param pluginConfig Config parameters, possibly from a ZK source
    */
   public abstract void init(Map<String, Object> pluginConfig);
+
+  protected void forward(String user, ServletRequest  req, ServletResponse rsp,
+                                    FilterChain chain) throws IOException, ServletException {
+    if(user != null) {
+      final Principal p = new BasicUserPrincipal(user);
+      req = new HttpServletRequestWrapper((HttpServletRequest) req) {
+        @Override
+        public Principal getUserPrincipal() {
+          return p;
+        }
+      };
+    }
+    chain.doFilter(req,rsp);
+  }
  
   /**
    * This method must authenticate the request. Upon a successful authentication, this 
@@ -51,13 +75,5 @@ public abstract class AuthenticationPlug
   public abstract void doAuthenticate(ServletRequest request, ServletResponse response,
       FilterChain filterChain) throws Exception;
 
-  /**
-   * 
-   * @return Returns an instance of a HttpClientConfigurer to be used for configuring the
-   * httpclients for use with SolrJ clients.
-   * 
-   * @lucene.experimental
-   */
-  public abstract HttpClientConfigurer getDefaultConfigurer();
 
 }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java Wed Aug  5 15:00:48 2015
@@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory;
  * limitations under the License.
  */
 
-public class KerberosPlugin extends AuthenticationPlugin {
+public class KerberosPlugin extends AuthenticationPlugin implements HttpClientInterceptorPlugin {
   static final Logger log = LoggerFactory.getLogger(KerberosPlugin.class);
 
   HttpClientConfigurer kerberosConfigurer = new Krb5HttpClientConfigurer();
@@ -121,7 +121,7 @@ public class KerberosPlugin extends Auth
   }
 
   @Override
-  public HttpClientConfigurer getDefaultConfigurer() {
+  public HttpClientConfigurer getClientConfigurer() {
     return kerberosConfigurer;
   }
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java Wed Aug  5 15:00:48 2015
@@ -104,6 +104,7 @@ import org.apache.solr.security.Authoriz
 import org.apache.solr.security.AuthorizationContext.CollectionRequest;
 import org.apache.solr.security.AuthorizationContext.RequestType;
 import org.apache.solr.security.AuthorizationResponse;
+import org.apache.solr.security.PKIAuthenticationPlugin;
 import org.apache.solr.servlet.SolrDispatchFilter.Action;
 import org.apache.solr.servlet.cache.HttpCacheHeaderUtil;
 import org.apache.solr.servlet.cache.Method;
@@ -417,7 +418,7 @@ public class HttpSolrCall {
        1. Authorization is enabled, and
        2. The requested resource is not a known static file
         */
-      if (cores.getAuthorizationPlugin() != null) {
+      if (cores.getAuthorizationPlugin() != null && shouldAuthorize()) {
         AuthorizationContext context = getAuthCtx();
         log.info(context.toString());
         AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);
@@ -484,6 +485,15 @@ public class HttpSolrCall {
 
   }
 
+  private boolean shouldAuthorize() {
+    if(PKIAuthenticationPlugin.PATH.equals(path)) return false;
+    //admin/info/key is the path where public key is exposed . it is always unsecured
+    if( cores.getPkiAuthenticationPlugin() != null && req.getUserPrincipal() != null){
+      return cores.getPkiAuthenticationPlugin().needsAuthorization(req);
+    }
+    return true;
+  }
+
   void destroy() {
     try {
       if (solrReq != null) {

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java Wed Aug  5 15:00:48 2015
@@ -24,7 +24,6 @@ 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;
@@ -34,16 +33,11 @@ import java.util.concurrent.atomic.Atomi
 import java.util.regex.Matcher;
 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.http.client.HttpClient;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.NodeConfig;
@@ -52,6 +46,7 @@ import org.apache.solr.core.SolrResource
 import org.apache.solr.core.SolrXmlConfig;
 import org.apache.solr.request.SolrRequestInfo;
 import org.apache.solr.security.AuthenticationPlugin;
+import org.apache.solr.security.PKIAuthenticationPlugin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,7 +61,7 @@ public class SolrDispatchFilter extends
   protected volatile CoreContainer cores;
 
   protected String abortErrorMessage = null;
-  protected final CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
+  protected HttpClient httpClient;
   private ArrayList<Pattern> excludePatterns;
 
   /**
@@ -112,14 +107,7 @@ public class SolrDispatchFilter extends
       ExecutorUtil.addThreadLocalProvider(SolrRequestInfo.getInheritableThreadLocalProvider());
 
       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());
-        }
-      }
-
+      this.httpClient = cores.getUpdateShardHandler().getHttpClient();
       log.info("user.dir=" + System.getProperty("user.dir"));
     }
     catch( Throwable t ) {
@@ -180,13 +168,9 @@ public class SolrDispatchFilter extends
   
   @Override
   public void destroy() {
-    try {
-      if (cores != null) {
-        cores.shutdown();
-        cores = null;
-      }
-    } finally {
-      IOUtils.closeQuietly(httpClient);
+    if (cores != null) {
+      cores.shutdown();
+      cores = null;
     }
   }
   
@@ -198,7 +182,7 @@ public class SolrDispatchFilter extends
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
     if (!(request instanceof HttpServletRequest)) return;
 
-    AtomicReference<ServletRequest> wrappedRequest = new AtomicReference();
+    AtomicReference<ServletRequest> wrappedRequest = new AtomicReference<>();
     if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been sent
       return;
     }
@@ -254,6 +238,10 @@ public class SolrDispatchFilter extends
     if (authenticationPlugin == null) {
       return true;
     } else {
+      //special case when solr is securing inter-node requests
+      String header = ((HttpServletRequest) request).getHeader(PKIAuthenticationPlugin.HEADER);
+      if (header != null && cores.getPkiAuthenticationPlugin() != null)
+        authenticationPlugin = cores.getPkiAuthenticationPlugin();
       try {
         log.debug("Request to authenticate: {}, domain: {}, port: {}", request, request.getLocalName(), request.getLocalPort());
         // upon successful authentication, this should call the chain's next filter.

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java Wed Aug  5 15:00:48 2015
@@ -29,6 +29,7 @@ import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
+import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -158,7 +159,7 @@ public class SolrRequestParsers
     // Pick the parser from the request...
     ArrayList<ContentStream> streams = new ArrayList<>(1);
     SolrParams params = parser.parseParamsAndFillStreams( req, streams );
-    SolrQueryRequest sreq = buildRequestFrom( core, params, streams, getRequestTimer(req) );
+    SolrQueryRequest sreq = buildRequestFrom(core, params, streams, getRequestTimer(req), req);
 
     // Handlers and login will want to know the path. If it contains a ':'
     // the handler could use it for RESTful URLs
@@ -170,14 +171,13 @@ public class SolrRequestParsers
     }
     return sreq;
   }
-  
-  public SolrQueryRequest buildRequestFrom( SolrCore core, SolrParams params, Collection<ContentStream> streams ) throws Exception
-  {
-    return buildRequestFrom( core, params, streams, new RTimer() );
+
+  public SolrQueryRequest buildRequestFrom(SolrCore core, SolrParams params, Collection<ContentStream> streams) throws Exception {
+    return buildRequestFrom(core, params, streams, new RTimer(), null);
   }
 
-  private SolrQueryRequest buildRequestFrom( SolrCore core, SolrParams params, Collection<ContentStream> streams, RTimer requestTimer ) throws Exception
-  {
+  private SolrQueryRequest buildRequestFrom(SolrCore core, SolrParams params, Collection<ContentStream> streams,
+                                            RTimer requestTimer, final HttpServletRequest req) throws Exception {
     // The content type will be applied to all streaming content
     String contentType = params.get( CommonParams.STREAM_CONTENTTYPE );
       
@@ -222,8 +222,13 @@ public class SolrRequestParsers
         streams.add( stream );
       }
     }
-    
-    SolrQueryRequestBase q = new SolrQueryRequestBase( core, params, requestTimer ) { };
+
+    SolrQueryRequestBase q = new SolrQueryRequestBase(core, params, requestTimer) {
+      @Override
+      public Principal getUserPrincipal() {
+        return req == null ? null : req.getUserPrincipal();
+      }
+    };
     if( streams != null && streams.size() > 0 ) {
       q.setContentStreams( streams );
     }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/CryptoKeys.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/CryptoKeys.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/CryptoKeys.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/CryptoKeys.java Wed Aug  5 15:00:48 2015
@@ -24,12 +24,16 @@ import javax.crypto.spec.IvParameterSpec
 import javax.crypto.spec.SecretKeySpec;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.security.GeneralSecurityException;
 import java.security.InvalidKeyException;
 import java.security.KeyFactory;
+import java.security.KeyPairGenerator;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
 import java.security.PublicKey;
+import java.security.SecureRandom;
 import java.security.Signature;
 import java.security.SignatureException;
 import java.security.spec.X509EncodedKeySpec;
@@ -252,4 +256,91 @@ public final class CryptoKeys {
     }
   }
 
+  public static PublicKey deserializeX509PublicKey(String pubKey) {
+    try {
+      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64.base64ToByteArray(pubKey));
+      return keyFactory.generatePublic(publicKeySpec);
+    } catch (Exception e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e);
+    }
+  }
+
+  public static byte[] decryptRSA(byte[] buffer, PublicKey pubKey) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+    Cipher rsaCipher = null;
+    try {
+      rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
+    } catch (Exception e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e);
+    }
+    rsaCipher.init(Cipher.DECRYPT_MODE, pubKey);
+    return rsaCipher.doFinal(buffer, 0, buffer.length);
+
+  }
+
+  public static class RSAKeyPair {
+    private final String pubKeyStr;
+    private final PublicKey publicKey;
+    private final PrivateKey privateKey;
+    private final SecureRandom random = new SecureRandom();
+
+
+    public RSAKeyPair() {
+      KeyPairGenerator keyGen = null;
+      try {
+        keyGen = KeyPairGenerator.getInstance("RSA");
+      } catch (NoSuchAlgorithmException e) {
+        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+      }
+      keyGen.initialize(512);
+      java.security.KeyPair keyPair = keyGen.genKeyPair();
+      privateKey = keyPair.getPrivate();
+      publicKey = keyPair.getPublic();
+
+      X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(
+          publicKey.getEncoded());
+
+      pubKeyStr = Base64.byteArrayToBase64(x509EncodedKeySpec.getEncoded());
+    }
+
+    public String getPublicKeyStr() {
+      return pubKeyStr;
+    }
+
+    public byte[] encrypt(ByteBuffer buffer) {
+      try {
+        Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
+        rsaCipher.init(Cipher.ENCRYPT_MODE, privateKey);
+        return rsaCipher.doFinal(buffer.array(),buffer.position(), buffer.limit());
+      } catch (Exception e) {
+        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e);
+      }
+    }
+    public byte[] signSha256(byte[] bytes) throws InvalidKeyException, SignatureException {
+      Signature dsa = null;
+      try {
+        dsa = Signature.getInstance("SHA256withRSA");
+      } catch (NoSuchAlgorithmException e) {
+        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+      }
+      dsa.initSign(privateKey);
+      dsa.update(bytes,0,bytes.length);
+      return dsa.sign();
+
+    }
+
+  }
+
+  public static void main(String[] args) throws Exception {
+    RSAKeyPair keyPair = new RSAKeyPair();
+    System.out.println(keyPair.getPublicKeyStr());
+    PublicKey pk = deserializeX509PublicKey(keyPair.getPublicKeyStr());
+    byte[] payload = "Hello World!".getBytes(StandardCharsets.UTF_8);
+    byte[] encrypted = keyPair.encrypt(ByteBuffer.wrap(payload));
+    String cipherBase64 = Base64.byteArrayToBase64(encrypted);
+    System.out.println("encrypted: "+ cipherBase64);
+    System.out.println("signed: "+ Base64.byteArrayToBase64(keyPair.signSha256(payload)));
+    System.out.println("decrypted "+  new String(decryptRSA(encrypted , pk), StandardCharsets.UTF_8));
+  }
+
 }

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java Wed Aug  5 15:00:48 2015
@@ -35,6 +35,7 @@ import org.apache.lucene.util.LuceneTest
 import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.security.AuthenticationPlugin;
+import org.apache.solr.security.HttpClientInterceptorPlugin;
 import org.apache.solr.util.RevertDefaultThreadHandlerRule;
 import org.junit.ClassRule;
 import org.junit.Rule;
@@ -108,7 +109,7 @@ public class TestAuthenticationFramework
     super.tearDown();
   }
   
-  public static class MockAuthenticationPlugin extends AuthenticationPlugin {
+  public static class MockAuthenticationPlugin extends AuthenticationPlugin implements HttpClientInterceptorPlugin {
     private static Logger log = LoggerFactory.getLogger(MockAuthenticationPlugin.class);
 
     public static String expectedUsername = "solr";
@@ -133,7 +134,7 @@ public class TestAuthenticationFramework
     }
 
     @Override
-    public HttpClientConfigurer getDefaultConfigurer() {
+    public HttpClientConfigurer getClientConfigurer() {
       return new MockClientConfigurer();
     }
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthorizationPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthorizationPlugin.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthorizationPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/MockAuthorizationPlugin.java Wed Aug  5 15:00:48 2015
@@ -20,19 +20,34 @@ package org.apache.solr.security;
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.function.Predicate;
 
+import org.apache.solr.common.SolrException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class MockAuthorizationPlugin implements AuthorizationPlugin{
 
   private Logger log = LoggerFactory.getLogger(MockAuthorizationPlugin.class);
-  HashSet<String> denyUsers;
-  
+  static final HashSet<String> denyUsers = new HashSet<>();
+  static Predicate<AuthorizationContext> predicate;
+
   @Override
   public AuthorizationResponse authorize(AuthorizationContext context) {
-    log.info("User request: " + context.getParams().get("uname"));
-    if(denyUsers.contains(context.getParams().get("uname")))
+    String uname = context.getUserPrincipal()== null? null : context.getUserPrincipal().getName();
+    if(predicate != null){
+      try {
+        predicate.test(context);
+        return new AuthorizationResponse(200);
+      } catch (SolrException e) {
+        return new AuthorizationResponse(e.code());
+      }
+    }
+
+
+    if(uname == null) uname = context.getParams().get("uname");
+    log.info("User request: " + uname);
+    if(denyUsers.contains(uname))
       return new AuthorizationResponse(403);
     else
       return new AuthorizationResponse(200);
@@ -40,9 +55,6 @@ public class MockAuthorizationPlugin imp
 
   @Override
   public void init(Map<String, Object> initInfo) {
-    denyUsers = new HashSet();
-    denyUsers.add("user1");
-    denyUsers.add("user2");
   }
 
   @Override

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java Wed Aug  5 15:00:48 2015
@@ -45,6 +45,8 @@ public class TestAuthorizationFramework
 
   @Test
   public void authorizationFrameworkTest() throws Exception {
+    MockAuthorizationPlugin.denyUsers.add("user1");
+    MockAuthorizationPlugin.denyUsers.add("user1");
     waitForThingsToLevelOut(10);
     log.info("Starting test");
     ModifiableSolrParams params = new ModifiableSolrParams();
@@ -60,4 +62,11 @@ public class TestAuthorizationFramework
     } catch (Exception e) {}
     log.info("Ending test");
   }
+
+  @Override
+  public void distribTearDown() throws Exception {
+    super.distribTearDown();
+    MockAuthorizationPlugin.denyUsers.clear();
+
+  }
 }

Copied: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java (from r1694217, lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java?p2=lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java&p1=lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java&r1=1694217&r2=1694239&rev=1694239&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java Wed Aug  5 15:00:48 2015
@@ -78,7 +78,7 @@ public class TestPKIAuthenticationPlugin
   }
 
   public void test() throws Exception {
-    AtomicReference<Principal> principal = new AtomicReference<>();
+    final AtomicReference<Principal> principal = new AtomicReference<>();
     String nodeName = "node_x_233";
 
     final MockPKIAuthenticationPlugin mock = new MockPKIAuthenticationPlugin(null, nodeName);

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/Base64.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/Base64.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/Base64.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/Base64.java Wed Aug  5 15:00:48 2015
@@ -52,6 +52,10 @@ public class Base64 {
           35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
   };
 
+  public static String byteArrayToBase64(byte[] a) {
+    return byteArrayToBase64(a, 0, a.length);
+  }
+
   public static String byteArrayToBase64(byte[] a, int offset, int len) {
     int aLen = len;
     int numFullGroups = aLen / 3;

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java?rev=1694239&r1=1694238&r2=1694239&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java Wed Aug  5 15:00:48 2015
@@ -193,6 +193,7 @@ public class ExecutorUtil {
       super.execute(new Runnable() {
         @Override
         public void run() {
+          isServerPool.set(Boolean.TRUE);
           if (ctx != null) {
             for (int i = 0; i < providersCopy.size(); i++) providersCopy.get(i).set(ctx.get(i));
           }
@@ -214,6 +215,7 @@ public class ExecutorUtil {
             log.error("Uncaught exception {} thrown by thread: {}", t, currentThread.getName(), submitterStackTrace);
             throw t;
           } finally {
+            isServerPool.remove();
             if (threadContext != null && !threadContext.isEmpty()) {
               MDC.setContextMap(threadContext);
             } else {
@@ -228,4 +230,11 @@ public class ExecutorUtil {
       });
     }
   }
+
+  private static final ThreadLocal<Boolean> isServerPool = new ThreadLocal<>();
+
+  public static boolean isSolrServerThread() {
+    return Boolean.TRUE.equals(isServerPool.get());
+  }
+
 }