[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.
Conflicts:
core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/19df69f2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/19df69f2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/19df69f2
Branch: refs/heads/2.7.x-fixes
Commit: 19df69f2e0a33d6b1805b57a5b7e1ce0abf1bea8
Parents: f3279ea
Author: Daniel Kulp <[email protected]>
Authored: Mon Nov 10 15:28:45 2014 -0500
Committer: Daniel Kulp <[email protected]>
Committed: Mon Nov 10 18:50:16 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/19df69f2/api/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
b/api/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
index 2918cec..81994f8 100644
--- a/api/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
+++ b/api/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;
@@ -75,6 +76,8 @@ public final class SSLUtils {
private static final List<String> DEFAULT_CIPHERSUITE_FILTERS_EXCLUDE =
Arrays.asList(new String[] {".*_NULL_.*",
".*_anon_.*"});
+
+ private static volatile KeyManager[] defaultManagers;
private SSLUtils() {
}
@@ -147,23 +150,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 {