commit
90b5dd60fd
1 changed files with 15 additions and 3 deletions
|
@ -43,9 +43,21 @@ public class KeystoreUtil {
|
||||||
|
|
||||||
public static KeyStore loadKeyStore(String filename, String password) throws Exception {
|
public static KeyStore loadKeyStore(String filename, String password) throws Exception {
|
||||||
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
InputStream trustStream = (filename.startsWith(GenericConstants.PROTOCOL_CLASSPATH))
|
InputStream trustStream = null;
|
||||||
?KeystoreUtil.class.getResourceAsStream(filename.replace(GenericConstants.PROTOCOL_CLASSPATH, ""))
|
if (filename.startsWith(GenericConstants.PROTOCOL_CLASSPATH)) {
|
||||||
:new FileInputStream(new File(filename));
|
String resourcePath = filename.replace(GenericConstants.PROTOCOL_CLASSPATH, "");
|
||||||
|
if (Thread.currentThread().getContextClassLoader() != null) {
|
||||||
|
trustStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
|
||||||
|
}
|
||||||
|
if (trustStream == null) {
|
||||||
|
trustStream = KeystoreUtil.class.getResourceAsStream(resourcePath);
|
||||||
|
}
|
||||||
|
if (trustStream == null) {
|
||||||
|
throw new RuntimeException("Unable to find key store in classpath");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
trustStream = new FileInputStream(new File(filename));
|
||||||
|
}
|
||||||
trustStore.load(trustStream, password.toCharArray());
|
trustStore.load(trustStream, password.toCharArray());
|
||||||
trustStream.close();
|
trustStream.close();
|
||||||
return trustStore;
|
return trustStore;
|
||||||
|
|
Loading…
Reference in a new issue