Package no.digipost.security.keystore
Class KeyStoreBuilder
- java.lang.Object
-
- no.digipost.security.keystore.KeyStoreBuilder
-
public final class KeyStoreBuilder extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Function<? super X509Certificate,String>DEFAULT_ALIAS_CREATORThe default way to create aliases for certificates, which uses certificates' Subject DNs,serial numbers, and Issuer DNs to create aliases.
-
Constructor Summary
Constructors Constructor Description KeyStoreBuilder(KeyStoreType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyStoreBuildercontaining(X509Certificate certificate)Add a certificate which should be contained in the resultingKeyStore.KeyStoreBuildercontaining(X509Certificate certificate, String alias)Add a certificate which should be contained in the resultingKeyStorewith the given alias.KeyStoreBuildercontaining(Collection<X509Certificate> certificates)Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR.KeyStoreBuildercontaining(Stream<X509Certificate> certificates)Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR.KeyStoreBuildercontaining(Stream<X509Certificate> certificates, Function<? super X509Certificate,String> aliasCreator)Add certificates which should be contained in the resulting key store.KeyStoreBuilderloadFrom(InputStream keyStoreStream)Load key store fromInputStreaminto a newKeyStore.KeyStoreBuilderloadFromClasspath(String classpathResourceName)Load key store from classpath resource into a newKeyStore.KeyStorewithNoPassword()Build a new key store with no password to access its content.KeyStorewithPassword(char[] password)Build a new key store with the given password to access its content.KeyStorewithPassword(String password)Build a new key store with the given password to access its content.
-
-
-
Field Detail
-
DEFAULT_ALIAS_CREATOR
public static final Function<? super X509Certificate,String> DEFAULT_ALIAS_CREATOR
The default way to create aliases for certificates, which uses certificates' Subject DNs,serial numbers, and Issuer DNs to create aliases. This alias creator is to ensure unique aliases for added certificates, and should not be used for adding certificates which one wishes to retrieve by alias from the resulting key store.
-
-
Constructor Detail
-
KeyStoreBuilder
public KeyStoreBuilder(KeyStoreType type)
-
-
Method Detail
-
containing
public KeyStoreBuilder containing(X509Certificate certificate)
Add a certificate which should be contained in the resultingKeyStore. Its alias will be created byDEFAULT_ALIAS_CREATOR.- Parameters:
certificate- the certificate to add to the resulting key store.- Returns:
- the builder
-
containing
public KeyStoreBuilder containing(X509Certificate certificate, String alias)
Add a certificate which should be contained in the resultingKeyStorewith the given alias.- Parameters:
certificate- the certificate to add to the resulting key store.alias- the alias which the certificate may be retrieved from the resulting key store.- Returns:
- the builder
-
containing
public KeyStoreBuilder containing(Collection<X509Certificate> certificates)
Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR.- Parameters:
certificates- the certificates to add to the newKeyStore.- Returns:
- the builder.
-
containing
public KeyStoreBuilder containing(Stream<X509Certificate> certificates)
Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR.- Parameters:
certificates- the certificates to add to the newKeyStore.- Returns:
- the builder.
-
containing
public KeyStoreBuilder containing(Stream<X509Certificate> certificates, Function<? super X509Certificate,String> aliasCreator)
Add certificates which should be contained in the resulting key store.- Parameters:
certificates- the certificates to add to the newKeyStore.aliasCreator- creates an alias for each certificate in the new key store.- Returns:
- the builder.
- Throws:
DuplicateAlias- if the same alias is created for several certificates.
-
loadFromClasspath
public KeyStoreBuilder loadFromClasspath(String classpathResourceName)
Load key store from classpath resource into a newKeyStore.- Parameters:
classpathResourceName- the name of the classpath resource containing the key store. The resource is resolved from the root of the classpath.
-
loadFrom
public KeyStoreBuilder loadFrom(InputStream keyStoreStream)
Load key store fromInputStreaminto a newKeyStore.- Parameters:
keyStoreStream- theInputStreamcontaining the key store.
-
withNoPassword
public KeyStore withNoPassword()
Build a new key store with no password to access its content.- Returns:
- the new
KeyStore.
-
withPassword
public KeyStore withPassword(String password)
Build a new key store with the given password to access its content.- Parameters:
password- the password for the key store.- Returns:
- the new
KeyStore.
-
-