Class AbstractPkcs11Configuration

java.lang.Object
se.swedenconnect.security.credential.pkcs11conf.AbstractPkcs11Configuration
All Implemented Interfaces:
InitializingBean, Pkcs11Configuration
Direct Known Subclasses:
DefaultPkcs11Configuration

public abstract class AbstractPkcs11Configuration extends Object implements Pkcs11Configuration, InitializingBean
Base class for PKCS#11 configuration.

The configuration can be set up in two ways;

  1. By assigning the path to an external PKCS#11 configuration file (setConfigurationFile(String) or AbstractPkcs11Configuration(String). This is the receommended choice.
  2. By assigning each individual setting (setLibrary(String), setName(String), setSlot(String), setSlotListIndex(Integer)). This is mainly for testing purposes.

Note: If the external configuration file is set, individual settings of library, name, slot or slotListIndex will be ignored.

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

    • AbstractPkcs11Configuration

      public AbstractPkcs11Configuration()
      Default constructor.
    • AbstractPkcs11Configuration

      public AbstractPkcs11Configuration(String configurationFile) throws Pkcs11ConfigurationException
      Constructor assigning the external PKCS#11 configuration file.
      Parameters:
      configurationFile - complete path to the PKCS#11 configuration file
      Throws:
      Pkcs11ConfigurationException - if the supplied configuration file does not exist
    • AbstractPkcs11Configuration

      public AbstractPkcs11Configuration(String library, String name, String slot, Integer slotListIndex)
      A constructor setting the library, name, slot and slotListIndex individually. See also AbstractPkcs11Configuration(String).
      Parameters:
      library - the PKCS#11 library path
      name - the name of the HSM slot
      slot - the slot number/id (may be null)
      slotListIndex - the slot index (may be null)
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws Pkcs11ConfigurationException
      Specified by:
      afterPropertiesSet in interface InitializingBean
      Throws:
      Pkcs11ConfigurationException
    • getConfigurationFile

      public String getConfigurationFile()
      Gets the complete path to the configuration file.
      Returns:
      the PKCS#11 configuration file, or null
    • setConfigurationFile

      public void setConfigurationFile(String configurationFile)
      Assigns the complete path to the external PKCS#11 configuration file.
      Parameters:
      configurationFile - the path to the external PKCS#11 configuration file
    • getLibrary

      public String getLibrary()
      Returns the path to the PKCS#11 library on the host to use for the provider.

      If the configuration has been configured by assigning a configuration file (setConfigurationFile(String) or AbstractPkcs11Configuration(String)) this method will return null.

      Returns:
      path to PKCS#11 library
    • setLibrary

      public void setLibrary(String library)
      Assigns the path to the PKCS#11 library on the host to use for the provider.

      Note: If the object has been configured with an external configuration file this call will have no effect.

      Parameters:
      library - path to PKCS#11 library
    • getName

      public String getName()
      Returns the name of the HSM slot.

      If the configuration has been configured by assigning a configuration file (setConfigurationFile(String) or AbstractPkcs11Configuration(String)) this method will return null.

      Returns:
      the name of the HSM slot
    • setName

      public void setName(String name)
      Assigns the name of the HSM slot.

      Note: If the object has been configured with an external configuration file this call will have no effect.

      Parameters:
      name - the name of the HSM slot
    • getSlot

      public String getSlot()
      Returns the slot number/id to use.

      If the configuration has been configured by assigning a configuration file (setConfigurationFile(String) or AbstractPkcs11Configuration(String)) this method will return null.

      Returns:
      slot number/id, or null
    • setSlot

      public void setSlot(String slot)
      Assigns the slot number/id to use.

      Note: If the object has been configured with an external configuration file this call will have no effect.

      Parameters:
      slot - slot number/id
    • getSlotListIndex

      public Integer getSlotListIndex()
      Returns the slot list index to use.

      If the configuration has been configured by assigning a configuration file (setConfigurationFile(String) or AbstractPkcs11Configuration(String)) this method will return null.

      Returns:
      the slot list index, or null
    • setSlotListIndex

      public void setSlotListIndex(Integer slotListIndex)
      Assigns the slot list index to use.

      Note: If the object has been configured with an external configuration file this call will have no effect.

      Parameters:
      slotListIndex - slot list index
    • toString

      public String toString()
      Overrides:
      toString in class Object