diff --git a/core/src/main/java/org/keycloak/util/KeystoreUtil.java b/core/src/main/java/org/keycloak/util/KeystoreUtil.java index 76e0f1d940..6c715a2c31 100755 --- a/core/src/main/java/org/keycloak/util/KeystoreUtil.java +++ b/core/src/main/java/org/keycloak/util/KeystoreUtil.java @@ -2,6 +2,7 @@ package org.keycloak.util; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.security.KeyStore; /** @@ -9,14 +10,16 @@ import java.security.KeyStore; * @version $Revision: 1 $ */ public class KeystoreUtil { + + private static final String PROTOCOL_CLASSPATH = "classpath:"; + public static KeyStore loadKeyStore(String filename, String password) throws Exception { - KeyStore trustStore = KeyStore.getInstance(KeyStore - .getDefaultType()); - File truststoreFile = new File(filename); - FileInputStream trustStream = new FileInputStream(truststoreFile); + KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); + InputStream trustStream = (filename.startsWith(PROTOCOL_CLASSPATH)) + ?KeystoreUtil.class.getResourceAsStream(filename.replace(PROTOCOL_CLASSPATH, "")) + :new FileInputStream(new File(filename)); trustStore.load(trustStream, password.toCharArray()); trustStream.close(); return trustStore; } - }