Class KeyStoreFactoryBean

java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<KeyStore>
se.swedenconnect.security.credential.factory.KeyStoreFactoryBean
All Implemented Interfaces:
Aware, BeanClassLoaderAware, BeanFactoryAware, DisposableBean, FactoryBean<KeyStore>, InitializingBean

public class KeyStoreFactoryBean extends AbstractFactoryBean<KeyStore>
Factory bean for creating and unlocking a KeyStore.

For Shibboleth users:
Basically this class is the same as net.shibboleth.ext.spring.factory.KeyStoreFactoryBean from the net.shibboleth.ext:spring-extensions library. However, using this class you can also instantiate a PKCS#11 KeyStore which is not possible with the net.shibboleth.ext.spring.factory.KeyStoreFactoryBean since it requires the resource property to be non-null.

Author:
Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
  • Constructor Details

    • KeyStoreFactoryBean

      public KeyStoreFactoryBean()
      Default constructor.
    • KeyStoreFactoryBean

      public KeyStoreFactoryBean(Resource resource, char[] password)
      Constructor that accepts a resource reference a keystore and the password to unlock this file.

      The type of KeyStore created will be KeyStore.getDefaultType().

      Parameters:
      resource - the keystore resource
      password - the password for unlocking the keystore
    • KeyStoreFactoryBean

      public KeyStoreFactoryBean(Resource resource, char[] password, String type)
      Constructor that accepts a resource reference to a keystore, the password to unlock this file and the store type ("JKS", "PKCS12", ...).
      Parameters:
      resource - the keystore resource
      password - the password for unlocking the keystore
      type - the type of keystore
  • Method Details

    • createInstance

      protected KeyStore createInstance() throws Exception
      Specified by:
      createInstance in class AbstractFactoryBean<KeyStore>
      Throws:
      Exception
    • getResource

      public Resource getResource()
      Gets the resource holding the KeyStore.
      Returns:
      the KeyStore resource
    • setResource

      public void setResource(Resource resource)
      Assigns the resource holding the KeyStore.
      Parameters:
      resource - the KeyStore resource
    • getPassword

      public char[] getPassword()
      Gets the password for unlocking the keystore.
      Returns:
      the password for unlocking the keystore
    • setPassword

      public void setPassword(char[] password)
      Assigns the password for unlocking the keystore.
      Parameters:
      password - the password to set
    • getType

      public String getType()
      Gets the type of KeyStore. If not explicitly assigned, KeyStore.getDefaultType() will be returned.
      Returns:
      the type of the KeyStore
    • setType

      public void setType(String type)
      Assigns the type of KeyStore.
      Parameters:
      type - the type of the KeyStore
    • getProvider

      public String getProvider()
      Gets the name of the security Provider to use when instantiating the KeyStore. If not explicitly assigned null is returned. This means that the first provider that can create a KeyStore of the given type will be used.
      Returns:
      the name of the security provider to use, or null
    • setProvider

      public void setProvider(String provider)
      Assigns the name of the security Provider to use when instantiating the KeyStore.
      Parameters:
      provider - the name of the security provider to use
    • getPkcs11Configuration

      public String getPkcs11Configuration()
      Gets the complete path to the PKCS#11 configuration file to use to configure the provider in the cases the type is "PKCS11". If no configuration file is supplied the supplied provider (setProvider(String)) must already have been configured for use with a specific PKCS#11 configuration.
      Returns:
      a complete path to a PKCS#11 configuration file, or null
    • setPkcs11Configuration

      public void setPkcs11Configuration(String pkcs11Configuration)
      Sets the complete path to the PKCS#11 configuration file to use to configure the provider in the cases the type is "PKCS11". If no configuration file is supplied the supplied provider (setProvider(String)) must already have been configured for use with a specific PKCS#11 configuration.
      Parameters:
      pkcs11Configuration - a complete path to a PKCS#11 configuration file
    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface FactoryBean<KeyStore>
      Specified by:
      getObjectType in class AbstractFactoryBean<KeyStore>
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface InitializingBean
      Overrides:
      afterPropertiesSet in class AbstractFactoryBean<KeyStore>
      Throws:
      Exception
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface DisposableBean
      Overrides:
      destroy in class AbstractFactoryBean<KeyStore>
      Throws:
      Exception