java.security
Class KeyStore.Builder

java.lang.Object
  extended by java.security.KeyStore.Builder
Enclosing class:
KeyStore

public static class KeyStore.Builder
extends Object

A description of a to-be-instantiated KeyStore object.

An instance of this class encapsulates the information needed to instantiate and initialize a KeyStore object. That process is triggered when the getKeyStore() method is called.

This makes it possible to decouple configuration from KeyStore object creation and e.g. delay a password prompt until it is actually needed.

Since:
1.5

Constructor Summary
KeyStore.Builder(String type)
          Construct a Builder for a KeyStore with the specified type.
 
Method Summary
 KeyStore getKeyStore()
          Instantiate, load, and return the KeyStore described by this builder.
 KeyStore.ProtectionParameter getProtectionParameter(String alias)
          Return the ProtectionParameter that should be used to obtain the Entry with the given alias.
 void setCallbackHandler(CallbackHandler callbackHandler)
          Set the CallbackHandler that should be used to obtain the password to load the KeyStore.
 void setInputStream(InputStream inputStream)
          Set the InputStream that the KeyStore is to be loaded from.
 void setLoadStoreParameter(KeyStore.LoadStoreParameter loadStoreParameter)
          Set the InputStream that the KeyStore is to be loaded from.
 void setPassword(char[] password)
          Set the password that should be used to load the KeyStore.
 void setProvider(Provider provider)
          Set the provider object that the KeyStore is to be instantiated from.
 void setProvider(String providerName)
          Set the name of the provider the KeyStore is to be instantiated from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyStore.Builder

public KeyStore.Builder(String type)
Construct a Builder for a KeyStore with the specified type. The values for provider, password, CallbackHandler, InputStream, and LoadStoreParameters are not set.

The current AccessControlContext is saved for use by the getKeyStore() method.

Throws:
NullPointerException - if type is null
Method Detail

setProvider

public void setProvider(String providerName)
Set the name of the provider the KeyStore is to be instantiated from. If set to null, the list of installed security providers will be searched. This setting overrides a previous setting made using setProvider(Provider).

Parameters:
providerName - the name of the security provider (or null)

setProvider

public void setProvider(Provider provider)
Set the provider object that the KeyStore is to be instantiated from. If set to null, the list of installed security providers will be searched.

This setting overrides a previous setting made using setProvider(String).

Parameters:
provider - the security provider (or null)

setPassword

public void setPassword(char[] password)
Set the password that should be used to load the KeyStore. If set to null, a CallbackHandler is used to obtain the password.

Note that the password is cloned to protect against subsequent modification.

Parameters:
password - the password to use to load the KeyStore (or null)

setCallbackHandler

public void setCallbackHandler(CallbackHandler callbackHandler)
Set the CallbackHandler that should be used to obtain the password to load the KeyStore. If set to null, the auth.login.defaultCallbackHandler security property is queried for the fully qualified class name of a default handler implementation.

Parameters:
callbackHandler - the CallbackHandler that should be used to obtain the password (or null)

setInputStream

public void setInputStream(InputStream inputStream)
Set the InputStream that the KeyStore is to be loaded from. If set to null, the KeyStore.load() method will be called with a value of null as the InputStream. This setting overrides a previous setting made using setLoadStoreParameter().

Parameters:
inputStream - the inputStream to use to load the KeyStore (or null)

setLoadStoreParameter

public void setLoadStoreParameter(KeyStore.LoadStoreParameter loadStoreParameter)
Set the InputStream that the KeyStore is to be loaded from. If set to null, the KeyStore.load() method will be called with a value of null as the InputStream. This setting overrides a previous setting made using setInputStream().

Parameters:
loadStoreParameter - the LoadStoreParameter to use to load the KeyStore (or null)

getKeyStore

public KeyStore getKeyStore()
                     throws KeyStoreException
Instantiate, load, and return the KeyStore described by this builder.

Throws:
KeyStoreException - if the KeyStore could not be instantiated or loaded

getProtectionParameter

public KeyStore.ProtectionParameter getProtectionParameter(String alias)
Return the ProtectionParameter that should be used to obtain the Entry with the given alias.

Parameters:
alias - the alias of the KeyStore entry
Returns:
the ProtectionParameter that should be used to obtain the Entry with the given alias.
Throws:
NullPointerException - if alias is null