ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class clazz = loader.loadClass(keyStoreProvider);
Class[] ctorSig = {String.class};
Constructor ctor = clazz.getConstructor(ctorSig);
Object[] ctorArgs = {keyStoreProviderArgument};
Provider provider = (Provider) ctor.newInstance(ctorArgs);
keyStore = KeyStore.getInstance(keyStoreType, provider);
}
else
keyStore = KeyStore.getInstance(keyStoreType, keyStoreProvider);
}
else
keyStore = KeyStore.getInstance(keyStoreType);
InputStream is = null;
if ((!"PKCS11".equalsIgnoreCase(keyStoreType) || !"PKCS11IMPLKS".equalsIgnoreCase(keyStoreType)) && keyStoreURL != null)
{
is = keyStoreURL.openStream();
}
keyStore.load(is, keyStorePassword);
if (keyStoreAlias != null && !keyStore.isKeyEntry(keyStoreAlias))
{
throw new IOException("Cannot find key entry with alias " + keyStoreAlias + " in the keyStore");
}
String algorithm = null;
if (keyMgrFactoryAlgorithm != null)
algorithm = keyMgrFactoryAlgorithm;
else
algorithm = KeyManagerFactory.getDefaultAlgorithm();
if (keyMgrFactoryProvider != null)
keyMgr = KeyManagerFactory.getInstance(algorithm, keyMgrFactoryProvider);
else
keyMgr = KeyManagerFactory.getInstance(algorithm);
keyMgr.init(keyStore, keyStorePassword);
if (keyStoreAlias != null)
{
KeyManager[] keyManagers = keyMgr.getKeyManagers();
for (int i = 0; i < keyManagers.length; i++)
{
keyManagers[i] = new SecurityKeyManager((X509KeyManager) keyManagers[i], keyStoreAlias, clientAlias);
}
}
}
if (trustStorePassword != null)
{
if (trustStoreProvider != null)
{
if (trustStoreProviderArgument != null)
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class clazz = loader.loadClass(trustStoreProvider);
Class[] ctorSig = {String.class};
Constructor ctor = clazz.getConstructor(ctorSig);
Object[] ctorArgs = {trustStoreProviderArgument};
Provider provider = (Provider) ctor.newInstance(ctorArgs);
trustStore = KeyStore.getInstance(trustStoreType, provider);
}
else
trustStore = KeyStore.getInstance(trustStoreType, trustStoreProvider);
}