KEYCLOAK-829 Adjustment to KetstoreUtil to support loading keystore from classpath
This commit is contained in:
parent
c0f377c8c7
commit
7c9e3f4555
1 changed files with 8 additions and 5 deletions
|
@ -2,6 +2,7 @@ package org.keycloak.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,14 +10,16 @@ import java.security.KeyStore;
|
||||||
* @version $Revision: 1 $
|
* @version $Revision: 1 $
|
||||||
*/
|
*/
|
||||||
public class KeystoreUtil {
|
public class KeystoreUtil {
|
||||||
|
|
||||||
|
private static final String PROTOCOL_CLASSPATH = "classpath:";
|
||||||
|
|
||||||
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
|
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
.getDefaultType());
|
InputStream trustStream = (filename.startsWith(PROTOCOL_CLASSPATH))
|
||||||
File truststoreFile = new File(filename);
|
?KeystoreUtil.class.getResourceAsStream(filename.replace(PROTOCOL_CLASSPATH, ""))
|
||||||
FileInputStream trustStream = new FileInputStream(truststoreFile);
|
: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