Class KeyStoreBuilder


  • public final class KeyStoreBuilder
    extends Object
    Builder class for loading key stores.
    • Constructor Detail

      • KeyStoreBuilder

        public KeyStoreBuilder()
    • Method Detail

      • withInputStream

        public KeyStoreBuilder withInputStream​(InputStream inputStream)
        Specifies the input stream to load the keystore from. Defaults to null 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

        public KeyStoreBuilder withKeyStoreFile​(File keyStoreFile)
                                         throws FileNotFoundException
        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

        public KeyStoreBuilder withKeyStoreFile​(String keyStoreFile)
                                         throws FileNotFoundException
        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 null InputStream.
        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

        @Deprecated
        public KeyStoreBuilder withKeyStoreType​(KeyStoreType type)
        Deprecated.
        Use withKeyStoreType(String) instead. Use of the KeyStoreType enum is deprecated as it restricts the keystore type to those specified in the enum. Library consumers may want to specify the keystore type at runtime.
        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.
      • withKeyStoreType

        public KeyStoreBuilder withKeyStoreType​(String type)
        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

        public KeyStoreBuilder withPassword​(char[] password)
        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

        public KeyStoreBuilder withPassword​(String password)
        Specifies the password to unlock the keystore.
        Parameters:
        password - the password to use. May not be null.
        Returns:
        the same builder instance.
        See Also:
        withPassword(char[])
      • withProvider

        public KeyStoreBuilder withProvider​(Provider provider)
        Specifies the security provider to use for the keystore.
        Parameters:
        provider - the security provider. May not be null.
        Returns:
        the same builder instance.
      • withProvider

        public KeyStoreBuilder withProvider​(String providerName)
        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.
      • withProviderClass

        public KeyStoreBuilder withProviderClass​(String className)
        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

        public KeyStoreBuilder withProviderClass​(String className,
                                                 ClassLoader classLoader)
        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 string
        classLoader - - The Java Class Loader to use.
        Returns:
        the same builder instance.
      • withProviderArgument

        public KeyStoreBuilder withProviderArgument​(String arg)
        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

        public KeyStore 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.