Class SslContextFactory
- java.lang.Object
-
- org.apache.mina.filter.ssl.SslContextFactory
-
public class SslContextFactory extends Object
A factory that creates and configures a newSSLContext
.If no properties are set the returned
SSLContext
will be equivalent to what the following creates:SSLContext c = SSLContext.getInstance("TLSv1.2"); c.init(null, null, null);
Use the properties prefixed with
keyManagerFactory
to control the creation of theKeyManager
to be used.Use the properties prefixed with
trustManagerFactory
to control the creation of theTrustManagerFactory
to be used.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description SslContextFactory()
-
Method Summary
-
-
-
Method Detail
-
newInstance
public SSLContext newInstance() throws Exception
Create a new SSLContext instance,using theKeyManagerFactory
and theTrustManagerFactory
.- Returns:
- The created instance
- Throws:
Exception
- If we weren't able to create the SSLContext insyance
-
setProvider
public void setProvider(String provider)
Sets the provider of the newSSLContext
. The default value isnull
, which means the default provider will be used.- Parameters:
provider
- the name of theSSLContext
provider
-
setProtocol
public void setProtocol(String protocol)
Sets the protocol to use when creating theSSLContext
. The default isTLS
.- Parameters:
protocol
- the name of the protocol.
-
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. The default value of this property istrue
.- 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. The default value of this property istrue
.- Parameters:
useDefault
-true
orfalse
.
-
setKeyManagerFactory
public void setKeyManagerFactory(KeyManagerFactory factory)
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
public 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)
.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
public void setKeyManagerFactoryProvider(String provider)
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
public void setKeyManagerFactoryKeyStore(KeyStore keyStore)
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
public void setKeyManagerFactoryKeyStorePassword(String password)
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
public void setTrustManagerFactory(TrustManagerFactory factory)
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
public 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)
.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
public void setTrustManagerFactoryKeyStore(KeyStore keyStore)
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
public void setTrustManagerFactoryParameters(ManagerFactoryParameters parameters)
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
public void setTrustManagerFactoryProvider(String provider)
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
public void setSecureRandom(SecureRandom secureRandom)
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:
SSLContext.init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)
-
setClientSessionCacheSize
public void setClientSessionCacheSize(int size)
Sets the SSLSession cache size for theSSLSessionContext
for use in client mode.- Parameters:
size
- the new session cache size limit; zero means there is no limit.- See Also:
SSLSessionContext.setSessionCacheSize(int size)
-
setClientSessionTimeout
public void setClientSessionTimeout(int seconds)
Set the SSLSession timeout limit for theSSLSessionContext
for use in client mode.- Parameters:
seconds
- the new session timeout limit in seconds; zero means there is no limit.- See Also:
SSLSessionContext.setSessionTimeout(int seconds)
-
setServerSessionCacheSize
public void setServerSessionCacheSize(int serverSessionCacheSize)
Sets the SSLSession cache size for theSSLSessionContext
for use in server mode.- Parameters:
serverSessionCacheSize
- the new session cache size limit; zero means there is no limit.- See Also:
SSLSessionContext.setSessionCacheSize(int)
-
setServerSessionTimeout
public void setServerSessionTimeout(int serverSessionTimeout)
Set the SSLSession timeout limit for theSSLSessionContext
for use in server mode.- Parameters:
serverSessionTimeout
- the new session timeout limit in seconds; zero means there is no limit.- See Also:
SSLSessionContext.setSessionTimeout(int)
-
-