Class SSLContextFactoryBean
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanClassLoaderAware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.FactoryBean
,org.springframework.beans.factory.InitializingBean
FactoryBean
implementation
which makes it possible to configure SSLContext
instances using Spring.
If no properties are set the returned SSLContext
will
be equivalent to what the following creates:
SSLContext c = SSLContext.getInstance( "TLS" ); c.init( null, null, null );
Use the properties prefixed with keyManagerFactory
to control
the creation of the KeyManager
to be used.
Use the properties prefixed with trustManagerFactory
to control
the creation of the TrustManagerFactory
to be used.
-
Field Summary
Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
void
setKeyManagerFactory
(KeyManagerFactory factory) Sets theKeyManagerFactory
to use.void
setKeyManagerFactoryAlgorithm
(String algorithm) Sets the algorithm to use when creating theKeyManagerFactory
usingKeyManagerFactory.getInstance(java.lang.String)
orKeyManagerFactory.getInstance(java.lang.String, java.lang.String)
.void
setKeyManagerFactoryAlgorithmUseDefault
(boolean useDefault) If this is set totrue
while noKeyManagerFactory
has been set usingsetKeyManagerFactory(KeyManagerFactory)
and no algorithm has been set usingsetKeyManagerFactoryAlgorithm(String)
the default algorithm return byKeyManagerFactory.getDefaultAlgorithm()
will be used.void
setKeyManagerFactoryKeyStore
(KeyStore keyStore) Sets theKeyStore
which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])
when theSSLContext
is created.void
setKeyManagerFactoryKeyStorePassword
(String password) Sets the password which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])
when theSSLContext
is created.void
setKeyManagerFactoryProvider
(String provider) Sets the provider to use when creating theKeyManagerFactory
usingKeyManagerFactory.getInstance(java.lang.String, java.lang.String)
.void
setProtocol
(String protocol) Sets the protocol to use when creating theSSLContext
.void
setSecureRandom
(SecureRandom secureRandom) Sets theSecureRandom
to use when initializing theSSLContext
.void
Sets theTrustManagerFactory
to use.void
setTrustManagerFactoryAlgorithm
(String algorithm) Sets the algorithm to use when creating theTrustManagerFactory
usingTrustManagerFactory.getInstance(java.lang.String)
orTrustManagerFactory.getInstance(java.lang.String, java.lang.String)
.void
setTrustManagerFactoryAlgorithmUseDefault
(boolean useDefault) If this is set totrue
while noTrustManagerFactory
has been set usingsetTrustManagerFactory(TrustManagerFactory)
and no algorithm has been set usingsetTrustManagerFactoryAlgorithm(String)
the default algorithm return byTrustManagerFactory.getDefaultAlgorithm()
will be used.void
setTrustManagerFactoryKeyStore
(KeyStore keyStore) Sets theKeyStore
which will be used in the call toTrustManagerFactory.init(java.security.KeyStore)
when theSSLContext
is created.void
Sets theManagerFactoryParameters
which will be used in the call toTrustManagerFactory.init(javax.net.ssl.ManagerFactoryParameters)
when theSSLContext
is created.void
setTrustManagerFactoryProvider
(String provider) Sets the provider to use when creating theTrustManagerFactory
usingTrustManagerFactory.getInstance(java.lang.String, java.lang.String)
.Methods inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
afterPropertiesSet, destroy, destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingleton
-
Constructor Details
-
SSLContextFactoryBean
public SSLContextFactoryBean()
-
-
Method Details
-
createInstance
- Specified by:
createInstance
in classorg.springframework.beans.factory.config.AbstractFactoryBean
- Throws:
Exception
-
getObjectType
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean
- Specified by:
getObjectType
in classorg.springframework.beans.factory.config.AbstractFactoryBean
-
setProtocol
Sets the protocol to use when creating theSSLContext
. The default isTLS
.- Parameters:
protocol
- the name of the protocol.- Throws:
IllegalArgumentException
- if the specified value isnull
.
-
setKeyManagerFactoryAlgorithmUseDefault
public void setKeyManagerFactoryAlgorithmUseDefault(boolean useDefault) If this is set totrue
while noKeyManagerFactory
has been set usingsetKeyManagerFactory(KeyManagerFactory)
and no algorithm has been set usingsetKeyManagerFactoryAlgorithm(String)
the default algorithm return byKeyManagerFactory.getDefaultAlgorithm()
will be used.- Parameters:
useDefault
-true
orfalse
.
-
setTrustManagerFactoryAlgorithmUseDefault
public void setTrustManagerFactoryAlgorithmUseDefault(boolean useDefault) If this is set totrue
while noTrustManagerFactory
has been set usingsetTrustManagerFactory(TrustManagerFactory)
and no algorithm has been set usingsetTrustManagerFactoryAlgorithm(String)
the default algorithm return byTrustManagerFactory.getDefaultAlgorithm()
will be used.- Parameters:
useDefault
-true
orfalse
.
-
setKeyManagerFactory
Sets theKeyManagerFactory
to use. If this is set the properties which are used by this factory bean to create aKeyManagerFactory
will all be ignored.- Parameters:
factory
- the factory.
-
setKeyManagerFactoryAlgorithm
Sets the algorithm to use when creating theKeyManagerFactory
usingKeyManagerFactory.getInstance(java.lang.String)
orKeyManagerFactory.getInstance(java.lang.String, java.lang.String)
.This property will be ignored if a
KeyManagerFactory
has been set directly usingsetKeyManagerFactory(KeyManagerFactory)
.If this property isn't set while no
KeyManagerFactory
has been set usingsetKeyManagerFactory(KeyManagerFactory)
andsetKeyManagerFactoryAlgorithmUseDefault(boolean)
has been set totrue
the value returned byKeyManagerFactory.getDefaultAlgorithm()
will be used instead.- Parameters:
algorithm
- the algorithm to use.
-
setKeyManagerFactoryProvider
Sets the provider to use when creating theKeyManagerFactory
usingKeyManagerFactory.getInstance(java.lang.String, java.lang.String)
.This property will be ignored if a
KeyManagerFactory
has been set directly usingsetKeyManagerFactory(KeyManagerFactory)
.If this property isn't set and no
KeyManagerFactory
has been set usingsetKeyManagerFactory(KeyManagerFactory)
KeyManagerFactory.getInstance(java.lang.String)
will be used to create theKeyManagerFactory
.- Parameters:
provider
- the name of the provider.
-
setKeyManagerFactoryKeyStore
Sets theKeyStore
which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])
when theSSLContext
is created.- Parameters:
keyStore
- the key store.
-
setKeyManagerFactoryKeyStorePassword
Sets the password which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])
when theSSLContext
is created.- Parameters:
password
- the password. Usenull
to disable password.
-
setTrustManagerFactory
Sets theTrustManagerFactory
to use. If this is set the properties which are used by this factory bean to create aTrustManagerFactory
will all be ignored.- Parameters:
factory
- the factory.
-
setTrustManagerFactoryAlgorithm
Sets the algorithm to use when creating theTrustManagerFactory
usingTrustManagerFactory.getInstance(java.lang.String)
orTrustManagerFactory.getInstance(java.lang.String, java.lang.String)
.This property will be ignored if a
TrustManagerFactory
has been set directly usingsetTrustManagerFactory(TrustManagerFactory)
.If this property isn't set while no
TrustManagerFactory
has been set usingsetTrustManagerFactory(TrustManagerFactory)
andsetTrustManagerFactoryAlgorithmUseDefault(boolean)
has been set totrue
the value returned byTrustManagerFactory.getDefaultAlgorithm()
will be used instead.- Parameters:
algorithm
- the algorithm to use.
-
setTrustManagerFactoryKeyStore
Sets theKeyStore
which will be used in the call toTrustManagerFactory.init(java.security.KeyStore)
when theSSLContext
is created.This property will be ignored if
ManagerFactoryParameters
has been set directly usingsetTrustManagerFactoryParameters(ManagerFactoryParameters)
.- Parameters:
keyStore
- the key store.
-
setTrustManagerFactoryParameters
Sets theManagerFactoryParameters
which will be used in the call toTrustManagerFactory.init(javax.net.ssl.ManagerFactoryParameters)
when theSSLContext
is created.- Parameters:
parameters
- describing provider-specific trust material.
-
setTrustManagerFactoryProvider
Sets the provider to use when creating theTrustManagerFactory
usingTrustManagerFactory.getInstance(java.lang.String, java.lang.String)
.This property will be ignored if a
TrustManagerFactory
has been set directly usingsetTrustManagerFactory(TrustManagerFactory)
.If this property isn't set and no
TrustManagerFactory
has been set usingsetTrustManagerFactory(TrustManagerFactory)
TrustManagerFactory.getInstance(java.lang.String)
will be used to create theTrustManagerFactory
.- Parameters:
provider
- the name of the provider.
-
setSecureRandom
Sets theSecureRandom
to use when initializing theSSLContext
. The JVM's default will be used if this isn't set.- Parameters:
secureRandom
- theSecureRandom
ornull
if the JVM's default should be used.- See Also:
-