From 7c9e3f4555fe45a2341364769b54c458c707257f Mon Sep 17 00:00:00 2001 From: Timon Veenstra Date: Thu, 6 Nov 2014 21:43:49 +0100 Subject: [PATCH] KEYCLOAK-829 Adjustment to KetstoreUtil to support loading keystore from classpath --- .../main/java/org/keycloak/util/KeystoreUtil.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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; } - }