cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject cxf git commit: [CXF-6094] Cache the default KeyManagers, only warn once if there is an issue, and check for file existence before even attempting so no warning at all if not there.
Date Mon, 10 Nov 2014 20:38:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 316ce8676 -> 58e6563da


[CXF-6094] Cache the default KeyManagers, only warn once if there is an issue, and check for
file existence before even attempting so no warning at all if not there.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/58e6563d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/58e6563d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/58e6563d

Branch: refs/heads/master
Commit: 58e6563da54fd3237a9a1d21a2cf7115740795a2
Parents: 316ce86
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Nov 10 15:28:45 2014 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Nov 10 15:38:35 2014 -0500

----------------------------------------------------------------------
 .../apache/cxf/configuration/jsse/SSLUtils.java | 42 +++++++++++++++-----
 1 file changed, 32 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/58e6563d/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java b/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
index f399fe9..dff171d 100644
--- a/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
+++ b/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
@@ -22,6 +22,7 @@ package org.apache.cxf.configuration.jsse;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.lang.reflect.Method;
@@ -76,6 +77,8 @@ public final class SSLUtils {
         Arrays.asList(new String[] {".*_NULL_.*",
                                     ".*_anon_.*",
                                     ".*_DES_.*"});
+    
+    private static volatile KeyManager[] defaultManagers;
 
     private SSLUtils() {
     }    
@@ -148,23 +151,42 @@ public final class SSLUtils {
     }
 
     public static KeyManager[] getDefaultKeyStoreManagers(Logger log) {
+        if (defaultManagers == null) {
+            loadDefaultKeyManagers(log);
+        }
+        if (defaultManagers.length == 0) {
+            return null;
+        }
+        return defaultManagers;
+    }
+    private static synchronized void loadDefaultKeyManagers(Logger log) {
+        if (defaultManagers != null) {
+            return;
+        }
+            
         String location = getKeystore(null, log);
         String keyStorePassword = getKeystorePassword(null, log);
         String keyPassword = getKeyPassword(null, log);
         FileInputStream fis = null;
         
         try {
-            KeyManagerFactory kmf = 
-                KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 

-            KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
-            
-            fis = new FileInputStream(location);
-            ks.load(fis, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
-            kmf.init(ks, (keyPassword != null) ? keyPassword.toCharArray() : null);
-            return kmf.getKeyManagers();
+            File file = new File(location);
+            if (file.exists()) {
+                KeyManagerFactory kmf = 
+                    KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
 
+                KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+                
+                fis = new FileInputStream(file);
+                ks.load(fis, (keyStorePassword != null) ? keyStorePassword.toCharArray()
: null);
+                kmf.init(ks, (keyPassword != null) ? keyPassword.toCharArray() : null);
+                defaultManagers = kmf.getKeyManagers();
+            } else {
+                log.log(Level.FINER, "No default keystore {0}", location);
+                defaultManagers = new KeyManager[0];
+            }
         } catch (Exception e) {
-            log.warning("Default key managers cannot be initialized: " + e.getMessage());
-            return null;
+            log.log(Level.WARNING, "Default key managers cannot be initialized: " + e.getMessage(),
e);
+            defaultManagers = new KeyManager[0];
         } finally {
             if (fis != null) {
                 try {


Mime
View raw message