Refactor to address https://issues.apache.org/bugzilla/show_bug.cgi?id=48208#c13
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 8 Mar 2011 11:15:37 +0000 (11:15 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 8 Mar 2011 11:15:37 +0000 (11:15 +0000)
Don't configure a TrustManagerFactory instance if it isn't going to be used.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1079323 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java

index e518149..7fa6fab 100644 (file)
@@ -566,6 +566,19 @@ public class JSSESocketFactory implements ServerSocketFactory {
         throws Exception {
         String crlf = endpoint.getCrlFile();
         
+        String className = endpoint.getTrustManagerClassName();
+        if(className != null && className.length() > 0) {
+             ClassLoader classLoader = getClass().getClassLoader();
+             Class<?> clazz = classLoader.loadClass(className);
+             if(!(TrustManager.class.isAssignableFrom(clazz))){
+                throw new InstantiationException(sm.getString(
+                        "jsse.invalidTrustManagerClassName", className));
+             }
+             Object trustManagerObject = clazz.newInstance();
+             TrustManager trustManager = (TrustManager) trustManagerObject;
+             return new TrustManager[]{ trustManager };
+        }    
+
         TrustManager[] tms = null;
         
         KeyStore trustStore = getTrustStore(keystoreType, keystoreProvider);
@@ -574,7 +587,7 @@ public class JSSESocketFactory implements ServerSocketFactory {
                 TrustManagerFactory tmf =
                     TrustManagerFactory.getInstance(algorithm);
                 tmf.init(trustStore);
-                tms = getTrustManagers(tmf);
+                tms = tmf.getTrustManagers();
             } else {
                 TrustManagerFactory tmf =
                     TrustManagerFactory.getInstance(algorithm);
@@ -583,7 +596,7 @@ public class JSSESocketFactory implements ServerSocketFactory {
                 ManagerFactoryParameters mfp =
                     new CertPathTrustManagerParameters(params);
                 tmf.init(mfp);
-                tms = getTrustManagers(tmf);
+                tms = tmf.getTrustManagers();
             }
         }
         
@@ -591,35 +604,6 @@ public class JSSESocketFactory implements ServerSocketFactory {
     }
 
     /**
-     * Gets the TrustManagers either from Connector's
-     * <code>trustManagerClassName</code> attribute (if set) else from the
-     * {@link TrustManagerFactory}.
-     * @return The TrustManagers to use for this connector.
-     * @throws NoSuchAlgorithmException 
-     * @throws ClassNotFoundException 
-     * @throws IllegalAccessException 
-     * @throws InstantiationException 
-    */
-   protected TrustManager[] getTrustManagers(TrustManagerFactory tmf)
-           throws NoSuchAlgorithmException, ClassNotFoundException,
-           InstantiationException, IllegalAccessException {
-
-       String className = endpoint.getTrustManagerClassName();
-       if(className != null && className.length() > 0) {
-            ClassLoader classLoader = getClass().getClassLoader();
-            Class<?> clazz = classLoader.loadClass(className);
-            if(!(TrustManager.class.isAssignableFrom(clazz))){
-               throw new InstantiationException(sm.getString(
-                       "jsse.invalidTrustManagerClassName", className));
-            }
-            Object trustManagerObject = clazz.newInstance();
-            TrustManager trustManager = (TrustManager) trustManagerObject;
-            return new TrustManager[]{ trustManager };
-        }      
-       return tmf.getTrustManagers();
-   }
-
-    /**
      * Return the initialization parameters for the TrustManager.
      * Currently, only the default <code>PKIX</code> is supported.
      *