Class KeyStoreFactoryBean
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<KeyStore>
se.swedenconnect.security.credential.spring.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
loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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 TypeMethodDescriptionvoidprotected KeyStorevoiddestroy()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.voidsetPassword(char[] password) Assigns the password for unlocking the keystore.voidsetPkcs11Configuration(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".voidsetProvider(String provider) voidsetResource(Resource resource) Assigns the resource holding the KeyStore.voidAssigns 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
KeyStorecreated will beKeyStore.getDefaultType().- Parameters:
resource- the keystore resourcepassword- the password for unlocking the keystore
-
KeyStoreFactoryBean
public KeyStoreFactoryBean(@Nullable Resource resource, @Nonnull char[] password, @Nullable 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 (may benullif type is "PKCS11")password- the password for unlocking the keystoretype- the type of keystore
-
-
Method Details
-
createInstance
- Specified by:
createInstancein 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
@Nullable public char[] getPassword()Gets the password for unlocking the keystore.- Returns:
- the password for unlocking the keystore
-
setPassword
public void setPassword(@Nonnull 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 securityProviderto use when instantiating theKeyStore. If not explicitly assignednullis returned. This means that the first provider that can create aKeyStoreof 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:
getObjectTypein interfaceFactoryBean<KeyStore>- Specified by:
getObjectTypein classAbstractFactoryBean<KeyStore>
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Overrides:
afterPropertiesSetin classAbstractFactoryBean<KeyStore>- Throws:
Exception
-
destroy
- Specified by:
destroyin interfaceDisposableBean- Overrides:
destroyin classAbstractFactoryBean<KeyStore>- Throws:
Exception
-