Package org.forgerock.security.keystore
Class KeyStoreBuilder
java.lang.Object
org.forgerock.security.keystore.KeyStoreBuilder
Builder class for loading key stores.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds and loads the keystore using the provided parameters.withInputStream
(InputStream inputStream) Specifies the input stream to load the keystore from.withKeyStoreFile
(File keyStoreFile) Specifies the file to load the keystore from.withKeyStoreFile
(String keyStoreFile) Specifies the file to load the keystore from.withKeyStoreType
(String type) Specifies the type of keystore to load.withLoadStoreParameter
(KeyStore.LoadStoreParameter loadStoreParameter) Specifies theKeyStore.LoadStoreParameter
to use to load theKeyStore
.withPassword
(char[] password) Specifies the password to unlock the keystore.withPassword
(String password) Specifies the password to unlock the keystore.withProvider
(String providerName) Specifies the security provider to use for the keystore.withProvider
(Provider provider) Specifies the security provider to use for the keystore.Specifies the argument to the Java Keystore Provider.withProviderClass
(String className) Specifies the java class name of a keystore provider.withProviderClass
(String className, ClassLoader classLoader) Specifies the java class name of a keystore provider.
-
Constructor Details
-
KeyStoreBuilder
public KeyStoreBuilder()
-
-
Method Details
-
withInputStream
Specifies the input stream to load the keystore from. Defaults tonull
to create a fresh keystore.Note: the input stream will be closed automatically after the keystore is loaded.
- Parameters:
inputStream
- the input stream to load the keystore from.- Returns:
- the same builder instance.
-
withKeyStoreFile
Specifies the file to load the keystore from.- Parameters:
keyStoreFile
- the keystore file to load.- Returns:
- the same builder instance.
- Throws:
FileNotFoundException
- if the file does not exist, is not a file, or cannot be read.
-
withKeyStoreFile
Specifies the file to load the keystore from. If the file name is "NONE" (case-insensitive), empty, or null the keystore will be loaded with a nullInputStream
.- Parameters:
keyStoreFile
- the name of keystore file to load.- Returns:
- the same builder instance.
- Throws:
FileNotFoundException
- if the file does not exist, is not a file, or cannot be read.
-
withKeyStoreType
Specifies the type of keystore to load. Defaults to JKS.- Parameters:
type
- the type of keystore to load. May not be null.- Returns:
- the same builder instance.
-
withPassword
Specifies the password to unlock the keystore. Defaults to no password. The password will be cleared after the keystore has been loaded.- Parameters:
password
- the password to unlock the keystore.- Returns:
- the same builder instance.
-
withPassword
Specifies the password to unlock the keystore.- Parameters:
password
- the password to use. May not be null.- Returns:
- the same builder instance.
- See Also:
-
withProvider
Specifies the security provider to use for the keystore.- Parameters:
provider
- the security provider. May not be null.- Returns:
- the same builder instance.
-
withProvider
Specifies the security provider to use for the keystore.- Parameters:
providerName
- the name of the provider to use.- Returns:
- the same builder instance.
- Throws:
IllegalArgumentException
- if no such provider exists.
-
withLoadStoreParameter
Specifies theKeyStore.LoadStoreParameter
to use to load theKeyStore
.- Parameters:
loadStoreParameter
- theKeyStore.LoadStoreParameter
.- Returns:
- the same builder instance.
-
withProviderClass
Specifies the java class name of a keystore provider. The class will be loaded via reflection using the default class loader.- Parameters:
className
- Java class name of a KeyStoreProvider - specififed as a string- Returns:
- the same builder instance.
-
withProviderClass
Specifies the java class name of a keystore provider. The class will be loaded via reflection using the supplied Class Loader- Parameters:
className
- Java class name of a KeyStoreProvider - specififed as a stringclassLoader
- - The Java Class Loader to use.- Returns:
- the same builder instance.
-
withProviderArgument
Specifies the argument to the Java Keystore Provider. This is used when loading the provider through reflection. The interpretation of the argument is specific to the KeyStore Provider.- Parameters:
arg
- The string argument to the provider.- Returns:
- the same builder instance.
-
build
Builds and loads the keystore using the provided parameters. If a password was provided, then it is blanked after the keystore has been loaded.- Returns:
- the configured keystore.
-