Class KeyStoreBuilder

java.lang.Object
se.swedenconnect.security.credential.factory.KeyStoreBuilder

public class KeyStoreBuilder extends Object
A class implementing a builder pattern for setting up a KeyStore.
Author:
Martin Lindström
  • Constructor Details

  • Method Details

    • builder

      @Nonnull public static KeyStoreBuilder builder()
      Creates a KeyStoreBuilder that uses the DefaultConfigurationResourceLoader to load resources.
      Returns:
      a KeyStoreBuilder
    • builder

      @Nonnull public static KeyStoreBuilder builder(@Nullable ConfigurationResourceLoader resourceLoader)
      Creates a KeyStoreBuilder that uses the supplied ConfigurationResourceLoader to load resources.
      Parameters:
      resourceLoader - the resource loader
      Returns:
      a KeyStoreBuilder
    • build

      Given the properties assigned, the method loads and unlocks a KeyStore.
      Returns:
      the KeyStore
      Throws:
      IllegalArgumentException - for missing or incorrect indata
      IOException - if the supplied location can not be read
      KeyStoreException - for errors during loading and unlocking of the key store (for example, bad password)
      NoSuchProviderException - if the given provider is not available
    • type

      @Nonnull public KeyStoreBuilder type(@Nonnull String type)
      Assigns the KeyStore type. If not assigned, KeyStore.getDefaultType() will be assumed.
      Parameters:
      type - the key store type
      Returns:
      the builder
    • location

      @Nonnull public KeyStoreBuilder location(@Nonnull String location)
      Assigns the location for the KeyStore. Will be read by the installed ConfigurationResourceLoader.

      Note: No location should be assigned for PKCS#11 key stores.

      Parameters:
      location - the location
      Returns:
      the builder
    • password

      @Nonnull public KeyStoreBuilder password(@Nonnull String password)
      Assigns the key store password.
      Parameters:
      password - the password
      Returns:
      the builder
    • pin

      @Nonnull public KeyStoreBuilder pin(@Nonnull String 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

      @Nonnull public KeyStoreBuilder provider(@Nonnull String provider)
      Assigns the name of the security Provider 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

      @Nonnull public KeyStoreBuilder pkcs11ConfigurationFile(@Nonnull String 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

      @Nonnull public KeyStoreBuilder pkcs11Library(@Nonnull String 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

      @Nonnull public KeyStoreBuilder pkcs11SlotName(@Nonnull String 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

      @Nonnull public KeyStoreBuilder pkcs11Slot(@Nonnull String 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

      @Nonnull public KeyStoreBuilder pkcs11SlotListIndex(@Nonnull Integer 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