You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2016/01/12 10:11:08 UTC

svn commit: r1724179 - in /lucene/dev/branches/lucene_solr_5_4: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/core/ solr/core/src/java/org/apache/solr/security/ solr/solrj/ solr/solrj/src/java/org/apache/solr/client/solrj/impl/ solr/solrj/src/...

Author: jpountz
Date: Tue Jan 12 09:11:08 2016
New Revision: 1724179

URL: http://svn.apache.org/viewvc?rev=1724179&view=rev
Log:
SOLR-8373: KerberosPlugin: Using multiple nodes on same machine leads clients to fetch TGT for every request

Added:
    lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrPortAwareCookieSpecFactory.java
      - copied unchanged from r1721679, lucene/dev/branches/lucene_solr_5_3/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrPortAwareCookieSpecFactory.java
    lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SolrPortAwareCookieSpecTest.java
      - copied unchanged from r1721679, lucene/dev/branches/lucene_solr_5_3/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SolrPortAwareCookieSpecTest.java
Modified:
    lucene/dev/branches/lucene_solr_5_4/   (props changed)
    lucene/dev/branches/lucene_solr_5_4/solr/   (props changed)
    lucene/dev/branches/lucene_solr_5_4/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_5_4/solr/core/   (props changed)
    lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/CoreContainer.java
    lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
    lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java
    lucene/dev/branches/lucene_solr_5_4/solr/solrj/   (props changed)
    lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java

Modified: lucene/dev/branches/lucene_solr_5_4/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_4/solr/CHANGES.txt?rev=1724179&r1=1724178&r2=1724179&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_4/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_5_4/solr/CHANGES.txt Tue Jan 12 09:11:08 2016
@@ -467,6 +467,9 @@ Bug Fixes
 
 * SOLR-8460: /analysis/field could throw exceptions for custom attributes. (David Smiley, Uwe Schindler)
 
+* SOLR-8373: KerberosPlugin: Using multiple nodes on same machine leads clients to
+  fetch TGT for every request (Ishan Chattopadhyaya via noble)
+
 ==================  5.3.1 ==================
 
 Bug Fixes

Modified: lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1724179&r1=1724178&r2=1724179&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/CoreContainer.java Tue Jan 12 09:11:08 2016
@@ -278,10 +278,14 @@ public class CoreContainer {
     SecurityPluginHolder<AuthenticationPlugin> old = authenticationPlugin;
     SecurityPluginHolder<AuthenticationPlugin> authenticationPlugin = null;
 
-    // Initialize the filter
+    // Initialize the plugin
     if (pluginClassName != null) {
       authenticationPlugin = new SecurityPluginHolder<>(readVersion(authenticationConfig),
-          getResourceLoader().newInstance(pluginClassName, AuthenticationPlugin.class));
+          getResourceLoader().newInstance(pluginClassName,
+              AuthenticationPlugin.class,
+              null,
+              new Class[]{CoreContainer.class},
+              new Object[]{this}));
     }
     if (authenticationPlugin != null) {
       authenticationPlugin.plugin.init(authenticationConfig);

Modified: lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java?rev=1724179&r1=1724178&r2=1724179&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java (original)
+++ lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java Tue Jan 12 09:11:08 2016
@@ -622,7 +622,7 @@ public class SolrResourceLoader implemen
     return obj;
   }
 
- 
+
 
   public <T> T newInstance(String cName, Class<T> expectedType, String [] subPackages, Class[] params, Object[] args){
     Class<? extends T> clazz = findClass(cName, expectedType, subPackages);
@@ -634,8 +634,19 @@ public class SolrResourceLoader implemen
     T obj = null;
     try {
 
-      Constructor<? extends T> constructor = clazz.getConstructor(params);
-      obj = constructor.newInstance(args);
+      Constructor<? extends T> constructor = null;
+      try {
+        constructor = clazz.getConstructor(params);
+        obj = constructor.newInstance(args);
+      } catch (NoSuchMethodException e) {
+        //look for a zero arg constructor if the constructor args do not match
+        try {
+          constructor = clazz.getConstructor();
+          obj = constructor.newInstance();
+        } catch (NoSuchMethodException e1) {
+          throw e;
+        }
+      }
 
     } catch (Error err) {
       log.error("Loading Class " + cName + " ("+clazz.getName() + ") triggered serious java error: "

Modified: lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java?rev=1724179&r1=1724178&r2=1724179&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java (original)
+++ lucene/dev/branches/lucene_solr_5_4/solr/core/src/java/org/apache/solr/security/KerberosPlugin.java Tue Jan 12 09:11:08 2016
@@ -29,8 +29,10 @@ import javax.servlet.descriptor.JspConfi
 import org.apache.commons.collections.iterators.IteratorEnumeration;
 import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
 import org.apache.solr.client.solrj.impl.Krb5HttpClientConfigurer;
+import org.apache.solr.cloud.ZkController;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.core.CoreContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,12 +59,18 @@ public class KerberosPlugin extends Auth
   HttpClientConfigurer kerberosConfigurer = new Krb5HttpClientConfigurer();
   Filter kerberosFilter = new KerberosFilter();
   
-  final String NAME_RULES_PARAM = "solr.kerberos.name.rules";
-  final String COOKIE_DOMAIN_PARAM = "solr.kerberos.cookie.domain";
-  final String COOKIE_PATH_PARAM = "solr.kerberos.cookie.path";
-  final String PRINCIPAL_PARAM = "solr.kerberos.principal";
-  final String KEYTAB_PARAM = "solr.kerberos.keytab";
-  final String TOKEN_VALID_PARAM = "solr.kerberos.token.valid";
+  public static final String NAME_RULES_PARAM = "solr.kerberos.name.rules";
+  public static final String COOKIE_DOMAIN_PARAM = "solr.kerberos.cookie.domain";
+  public static final String COOKIE_PATH_PARAM = "solr.kerberos.cookie.path";
+  public static final String PRINCIPAL_PARAM = "solr.kerberos.principal";
+  public static final String KEYTAB_PARAM = "solr.kerberos.keytab";
+  public static final String TOKEN_VALID_PARAM = "solr.kerberos.token.valid";
+  public static final String COOKIE_PORT_AWARE_PARAM = "solr.kerberos.cookie.portaware";
+  private final CoreContainer coreContainer;
+
+  public KerberosPlugin(CoreContainer coreContainer) {
+    this.coreContainer = coreContainer;
+  }
 
   @Override
   public void init(Map<String, Object> pluginConfig) {
@@ -71,11 +79,27 @@ public class KerberosPlugin extends Auth
       params.put("type", "kerberos");
       putParam(params, "kerberos.name.rules", NAME_RULES_PARAM, "DEFAULT");
       putParam(params, "token.valid", TOKEN_VALID_PARAM, "30");
-      putParam(params, "cookie.domain", COOKIE_DOMAIN_PARAM, null);
       putParam(params, "cookie.path", COOKIE_PATH_PARAM, "/");
       putParam(params, "kerberos.principal", PRINCIPAL_PARAM, null);
       putParam(params, "kerberos.keytab", KEYTAB_PARAM, null);
 
+      // Special handling for the "cookie.domain" based on whether port should be
+      // appended to the domain. Useful for situations where multiple solr nodes are
+      // on the same host.
+      String usePortStr = System.getProperty(COOKIE_PORT_AWARE_PARAM, null);
+      boolean needPortAwareCookies = (usePortStr == null) ? false: Boolean.parseBoolean(usePortStr);
+
+      if (!needPortAwareCookies || !coreContainer.isZooKeeperAware()) {
+        putParam(params, "cookie.domain", COOKIE_DOMAIN_PARAM, null);
+      } else { // we need port aware cookies and we are in SolrCloud mode.
+        String host = System.getProperty(COOKIE_DOMAIN_PARAM, null);
+        if (host==null) {
+          throw new SolrException(ErrorCode.SERVER_ERROR, "Missing required parameter '"+COOKIE_DOMAIN_PARAM+"'.");
+        }
+        int port = coreContainer.getZkController().getHostPort();
+        params.put("cookie.domain", host + ":" + port);
+      }
+      
       log.info("Params: "+params);
 
       FilterConfig conf = new FilterConfig() {

Modified: lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java?rev=1724179&r1=1724178&r2=1724179&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java (original)
+++ lucene/dev/branches/lucene_solr_5_4/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Krb5HttpClientConfigurer.java Tue Jan 12 09:11:08 2016
@@ -40,6 +40,7 @@ import org.apache.http.impl.auth.SPNegoS
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.params.ClientPNames;
 import org.apache.solr.common.params.SolrParams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -93,6 +94,10 @@ public class Krb5HttpClientConfigurer ex
           }
         };
 
+        SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();
+        httpClient.getCookieSpecs().register(cookieFactory.POLICY_NAME, cookieFactory);
+        httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookieFactory.POLICY_NAME);
+        
         httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, useJaasCreds);
 
         httpClient.addRequestInterceptor(bufferedEntityInterceptor);