org.jsslutils.keystores
Class KeyStoreLoader

java.lang.Object
  extended by org.jsslutils.keystores.KeyStoreLoader

public final class KeyStoreLoader
extends java.lang.Object

This class is a factory that provides methods for loading a KeyStore.

Author:
Bruno Harbulot

Constructor Summary
KeyStoreLoader()
           
 
Method Summary
protected  KeyStoreLoader clone()
          KeyStoreLoaders are likely to contain sensitive information; cloning is therefore not allowed.
static KeyStoreLoader getKeyStoreDefaultLoader()
          Builds a new KeyStoreLoader initialised with the values passed in the javax.net.ssl.keyStore, javax.net.ssl.keyStoreType, javax.net.ssl.keyStoreProvider and javax.net.ssl.keyStorePassword system properties, for using the KeyStore as a key store (as opposed to a trust store).
static KeyStoreLoader getTrustStoreDefaultLoader()
          Builds a new KeyStoreLoader initialised with the values passed in the javax.net.ssl.trustStore, javax.net.ssl.trustStoreType, javax.net.ssl.trustStoreProvider and javax.net.ssl.trustStorePassword system properties, for using the KeyStore as a trust store.
 java.security.KeyStore loadKeyStore()
          Loads a KeyStore according to the parameters initialised using the setters.
 java.security.KeyStore loadKeyStore(char[] password)
          Loads a KeyStore according to the parameters initialised using the setters.
 void setKeyStoreInputStream(java.io.InputStream keyStoreInputStream)
          Sets the KeyStore InputStream.
 void setKeyStorePassword(char[] keyStorePassword)
          Set the KeyStore password.
 void setKeyStorePassword(java.lang.String keyStorePassword)
          Set the KeyStore password.
 void setKeyStorePasswordCallbackHandler(javax.security.auth.callback.CallbackHandler keyStorePasswordCallbackHandler)
          Sets the KeyStore password CallbackHander (used to get the password if no password is provided).
 void setKeyStorePath(java.lang.String keyStorePath)
          Sets the KeyStore path.
 void setKeyStoreProvider(java.lang.String keyStoreProvider)
          Sets the KeyStore provider.
 void setKeyStoreProviderArgFile(java.lang.String keyStoreProviderArgFile)
          Sets the KeyStore provider argument file name.
 void setKeyStoreProviderArgText(java.lang.String keyStoreProviderArgText)
          Sets the KeyStore provider argument text content (UTF-8).
 void setKeyStoreProviderClass(java.lang.String keyStoreProviderClass)
          Sets the KeyStore provider class name.
 void setKeyStoreType(java.lang.String keyStoreType)
          Sets the KeyStore type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyStoreLoader

public KeyStoreLoader()
Method Detail

setKeyStorePath

public void setKeyStorePath(java.lang.String keyStorePath)
Sets the KeyStore path.

Parameters:
keyStorePath - the KeyStore path

setKeyStoreInputStream

public void setKeyStoreInputStream(java.io.InputStream keyStoreInputStream)
Sets the KeyStore InputStream. If null, falls back to KeyStore path. This InputStream will be closed by loadKeyStore(char[]) .

Parameters:
keyStoreInputStream - the KeyStore InputStream

setKeyStoreType

public void setKeyStoreType(java.lang.String keyStoreType)
Sets the KeyStore type.

Parameters:
keyStoreType - the KeyStore type

setKeyStoreProvider

public void setKeyStoreProvider(java.lang.String keyStoreProvider)
Sets the KeyStore provider.

Parameters:
keyStoreProvider - the KeyStore provider

setKeyStoreProviderClass

public void setKeyStoreProviderClass(java.lang.String keyStoreProviderClass)
Sets the KeyStore provider class name.

Parameters:
keyStoreProviderClass - the KeyStore provider class name

setKeyStoreProviderArgFile

public void setKeyStoreProviderArgFile(java.lang.String keyStoreProviderArgFile)
Sets the KeyStore provider argument file name.

Parameters:
keyStoreProviderArgFile - the KeyStore provider argument file name

setKeyStoreProviderArgText

public void setKeyStoreProviderArgText(java.lang.String keyStoreProviderArgText)
Sets the KeyStore provider argument text content (UTF-8).

Parameters:
keyStoreProviderArgText - the KeyStore provider argument text content (UTF-8)

setKeyStorePassword

public void setKeyStorePassword(java.lang.String keyStorePassword)
Set the KeyStore password.

Parameters:
keyStorePassword - the KeyStore password

setKeyStorePassword

public void setKeyStorePassword(char[] keyStorePassword)
Set the KeyStore password. This makes a copy of the char[] into an internal char[], which will be cleared either when you use loadKeyStore() or set it to null.

Parameters:
keyStorePassword - the KeyStore password

setKeyStorePasswordCallbackHandler

public void setKeyStorePasswordCallbackHandler(javax.security.auth.callback.CallbackHandler keyStorePasswordCallbackHandler)
Sets the KeyStore password CallbackHander (used to get the password if no password is provided).

Parameters:
keyStorePasswordCallbackHandler - the KeyStore password CallbackHandler.

loadKeyStore

public java.security.KeyStore loadKeyStore(char[] password)
                                    throws java.security.KeyStoreException,
                                           java.security.NoSuchProviderException,
                                           java.io.IOException,
                                           java.security.NoSuchAlgorithmException,
                                           java.security.cert.CertificateException,
                                           javax.security.auth.callback.UnsupportedCallbackException,
                                           java.lang.SecurityException
Loads a KeyStore according to the parameters initialised using the setters.

Parameters:
password - KeyStore password (will use password set with setKeyStorePassword if this argument is null).
Returns:
KeyStore loaded from the value initialised with the setters.
Throws:
java.security.KeyStoreException
java.security.NoSuchProviderException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
javax.security.auth.callback.UnsupportedCallbackException
java.lang.SecurityException

loadKeyStore

public java.security.KeyStore loadKeyStore()
                                    throws java.security.KeyStoreException,
                                           java.security.NoSuchProviderException,
                                           java.io.IOException,
                                           java.security.NoSuchAlgorithmException,
                                           java.security.cert.CertificateException,
                                           javax.security.auth.callback.UnsupportedCallbackException
Loads a KeyStore according to the parameters initialised using the setters. The stored password will be cleared after calling this method.

Returns:
KeyStore loaded from the value initialised with the setters.
Throws:
java.security.KeyStoreException
java.security.NoSuchProviderException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
javax.security.auth.callback.UnsupportedCallbackException

getKeyStoreDefaultLoader

public static KeyStoreLoader getKeyStoreDefaultLoader()
Builds a new KeyStoreLoader initialised with the values passed in the javax.net.ssl.keyStore, javax.net.ssl.keyStoreType, javax.net.ssl.keyStoreProvider and javax.net.ssl.keyStorePassword system properties, for using the KeyStore as a key store (as opposed to a trust store).

Returns:
KeyStore initialised with the default keystore system properties.

getTrustStoreDefaultLoader

public static KeyStoreLoader getTrustStoreDefaultLoader()
Builds a new KeyStoreLoader initialised with the values passed in the javax.net.ssl.trustStore, javax.net.ssl.trustStoreType, javax.net.ssl.trustStoreProvider and javax.net.ssl.trustStorePassword system properties, for using the KeyStore as a trust store.

Returns:
KeyStore initialised with the default keystore system properties.

clone

protected final KeyStoreLoader clone()
                              throws java.lang.CloneNotSupportedException
KeyStoreLoaders are likely to contain sensitive information; cloning is therefore not allowed.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException


Copyright © 2011. All Rights Reserved.