Class KeyStoreBuilder
java.lang.Object
se.swedenconnect.security.credential.factory.KeyStoreBuilder
A class implementing a builder pattern for setting up a
KeyStore
.- Author:
- Martin Lindström
-
Constructor Summary
ConstructorDescriptionDefault constructor.KeyStoreBuilder
(ConfigurationResourceLoader resourceLoader) Constructor assigning the resource loader to use when loading resources. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Given the properties assigned, the method loads and unlocks aKeyStore
.static KeyStoreBuilder
builder()
Creates aKeyStoreBuilder
that uses theDefaultConfigurationResourceLoader
to load resources.static KeyStoreBuilder
builder
(ConfigurationResourceLoader resourceLoader) Creates aKeyStoreBuilder
that uses the suppliedConfigurationResourceLoader
to load resources.Assigns the location for theKeyStore
.Assigns the key store password.Assigns the PIN, which is the same as the key store password.pkcs11ConfigurationFile
(String pkcs11ConfigurationFile) Assigns the full path to the PKCS#11 configuration file (for PKCS#11 key stores).pkcs11Library
(String pkcs11Library) As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately.pkcs11Slot
(String pkcs11Slot) As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately.pkcs11SlotListIndex
(Integer pkcs11SlotListIndex) As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately.pkcs11SlotName
(String pkcs11SlotName) As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately.Assigns the name of the securityProvider
to use.Assigns theKeyStore
type.
-
Constructor Details
-
KeyStoreBuilder
public KeyStoreBuilder()Default constructor.Will use the
DefaultConfigurationResourceLoader
to load resources. -
KeyStoreBuilder
Constructor assigning the resource loader to use when loading resources.- Parameters:
resourceLoader
- the resource loader, ifnull
, aDefaultConfigurationResourceLoader
will be used
-
-
Method Details
-
builder
Creates aKeyStoreBuilder
that uses theDefaultConfigurationResourceLoader
to load resources.- Returns:
- a
KeyStoreBuilder
-
builder
@Nonnull public static KeyStoreBuilder builder(@Nullable ConfigurationResourceLoader resourceLoader) Creates aKeyStoreBuilder
that uses the suppliedConfigurationResourceLoader
to load resources.- Parameters:
resourceLoader
- the resource loader- Returns:
- a
KeyStoreBuilder
-
build
@Nonnull public KeyStore build() throws IllegalArgumentException, IOException, KeyStoreException, NoSuchProviderExceptionGiven the properties assigned, the method loads and unlocks aKeyStore
.- Returns:
- the
KeyStore
- Throws:
IllegalArgumentException
- for missing or incorrect indataIOException
- if the supplied location can not be readKeyStoreException
- for errors during loading and unlocking of the key store (for example, bad password)NoSuchProviderException
- if the given provider is not available
-
type
Assigns theKeyStore
type. If not assigned,KeyStore.getDefaultType()
will be assumed.- Parameters:
type
- the key store type- Returns:
- the builder
-
location
Assigns the location for theKeyStore
. Will be read by the installedConfigurationResourceLoader
.Note: No location should be assigned for PKCS#11 key stores.
- Parameters:
location
- the location- Returns:
- the builder
-
password
Assigns the key store password.- Parameters:
password
- the password- Returns:
- the builder
-
pin
Assigns the PIN, which is the same as the key store password. When using PKCS#11 devices, the concept PIN is commoncly used instead of password.- Parameters:
pin
- the PIN- Returns:
- the builder
-
provider
Assigns the name of the securityProvider
to use. If not assigned, the default provider will be used.- Parameters:
provider
- the name of the security provider to use- Returns:
- the builder
-
pkcs11ConfigurationFile
Assigns the full path to the PKCS#11 configuration file (for PKCS#11 key stores).- Parameters:
pkcs11ConfigurationFile
- the full path to the PKCS#11 configuration file- Returns:
- the builder
-
pkcs11Library
As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately. This method assigns the PKCS#11 library path.- Parameters:
pkcs11Library
- the PKCS#11 library path- Returns:
- the builder
-
pkcs11SlotName
As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately. This method assigns the HSM slot name to use.- Parameters:
pkcs11SlotName
- the HSM slot name- Returns:
- the builder
-
pkcs11Slot
As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately. This method assigns the HSM slot number/id to use.- Parameters:
pkcs11Slot
- the HSM slot number/id- Returns:
- the builder
-
pkcs11SlotListIndex
As an alternative to assigning the PKCS#11 configuration file, each PKCS#11 setting may be supplied separately. This method assigned the HSM slot index to use.- Parameters:
pkcs11SlotListIndex
- the HSM slot index- Returns:
- the builder
-