Class AbstractSunPkcs11Configuration

java.lang.Object
se.swedenconnect.security.credential.pkcs11.AbstractSunPkcs11Configuration
All Implemented Interfaces:
Pkcs11Configuration
Direct Known Subclasses:
CustomPkcs11Configuration, FilePkcs11Configuration, StaticPkcs11Configuration

public abstract class AbstractSunPkcs11Configuration extends Object implements Pkcs11Configuration
Abstract base class for PKCS#11 configuration.

This implementation assumes that the SunPKCS11 security provider is used, or other security providers that supports the KeyStoreSpi.

The method getBaseProviderName() must be overridden if another security provider than SunPKCS11 is being used.

See PKCS#11 Reference Guide.

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

  • Constructor Details

    • AbstractSunPkcs11Configuration

      protected AbstractSunPkcs11Configuration()
      Default constructor.
    • AbstractSunPkcs11Configuration

      protected AbstractSunPkcs11Configuration(@Nullable String baseProviderName)
      Constructor setting the "base provider name".

      Assigns the name of the security provider that we use to create new instances that have names according to <base-provider-name>-<instance-name>, where 'instance-name' is gotten from the configuration. Implementations wishing to use another provider than "SunPKCS11" should supply this provider name.

      Parameters:
      baseProviderName - the base provider name
  • Method Details

    • init

      @PostConstruct public void init() throws Pkcs11ConfigurationException
      An init method that should be called to fully initialize the configuration object.
      Throws:
      Pkcs11ConfigurationException - for configuration errors
    • getProvider

      @Nonnull public Provider getProvider() throws Pkcs11ConfigurationException
      Gets the Java security Provider to use when setting up a PKCS#11 credential.
      Specified by:
      getProvider in interface Pkcs11Configuration
      Returns:
      a Provider instance
      Throws:
      Pkcs11ConfigurationException - if the configuration is incorrect
    • getBaseProviderName

      protected final String getBaseProviderName()
      Gets the name of the security provider that we use to create new instances that have names according to <base-provider-name>-<instance-name>, where 'instance-name' is gotten from the configuration.
      Returns:
      the provider name (SunPKCS11 is used for the default implementation)
    • getConfigurationData

      @Nullable protected abstract String getConfigurationData()
      Gets the configuration data for this configuration. The data returned is supplied in the Provider.configure(String) call that is made to configure the PKCS#11 security provider.

      The returned string represents either a file name to an PKCS#11 configuration file or PKCS#11 configuration commands (in that case the string must be prefixed with --.

      Note: For configuration objects using a pre-configured security provider, the method must return null.

      Returns:
      configuration data for a PKCS#11 provider, or null if no configuration is needed
    • toString

      public String toString()
      Overrides:
      toString in class Object