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
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)
-
Field Summary
Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
logger
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
ConstructorDescriptionDefault constructor.KeyStoreFactoryBean
(Resource resource, char[] password) Constructor that accepts a resource reference a keystore and the password to unlock this file.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", ...). -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected KeyStore
void
destroy()
Class<?>
char[]
Gets the password for unlocking the keystore.Gets the complete path to the PKCS#11 configuration file to use to configure the provider in the cases the type is "PKCS11".Gets the resource holding the KeyStore.getType()
Gets the type of KeyStore.void
setPassword
(char[] password) Assigns the password for unlocking the keystore.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".void
setProvider
(String provider) void
setResource
(Resource resource) Assigns the resource holding the KeyStore.void
Assigns the type of KeyStore.Methods inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingleton
-
Constructor Details
-
KeyStoreFactoryBean
public KeyStoreFactoryBean()Default constructor. -
KeyStoreFactoryBean
Constructor that accepts a resource reference a keystore and the password to unlock this file.The type of
KeyStore
created will beKeyStore.getDefaultType()
.- Parameters:
resource
- the keystore resourcepassword
- the password for unlocking the keystore
-
KeyStoreFactoryBean
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 resourcepassword
- the password for unlocking the keystoretype
- the type of keystore
-
-
Method Details
-
createInstance
- Specified by:
createInstance
in classAbstractFactoryBean<KeyStore>
- Throws:
Exception
-
getResource
Gets the resource holding the KeyStore.- Returns:
- the KeyStore resource
-
setResource
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
Gets the type of KeyStore. If not explicitly assigned,KeyStore.getDefaultType()
will be returned.- Returns:
- the type of the KeyStore
-
setType
Assigns the type of KeyStore.- Parameters:
type
- the type of the KeyStore
-
getProvider
Gets the name of the securityProvider
to use when instantiating theKeyStore
. If not explicitly assignednull
is returned. This means that the first provider that can create aKeyStore
of the given type will be used.- Returns:
- the name of the security provider to use, or null
-
setProvider
- Parameters:
provider
- the name of the security provider to use
-
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
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
- Specified by:
getObjectType
in interfaceFactoryBean<KeyStore>
- Specified by:
getObjectType
in classAbstractFactoryBean<KeyStore>
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Overrides:
afterPropertiesSet
in classAbstractFactoryBean<KeyStore>
- Throws:
Exception
-
destroy
- Specified by:
destroy
in interfaceDisposableBean
- Overrides:
destroy
in classAbstractFactoryBean<KeyStore>
- Throws:
Exception
-