Class SslContextFactory
SSLContext.
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 the KeyManager to be used.
Use the properties prefixed with trustManagerFactory to control
the creation of the TrustManagerFactory to be used.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate intprivate KeyManagerFactoryprivate Stringprivate booleanprivate KeyStoreprivate char[]private Stringprivate Stringprivate Stringprivate SecureRandomprivate intprivate intprivate TrustManagerFactoryprivate Stringprivate booleanprivate KeyStoreprivate ManagerFactoryParametersprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new SSLContext instance,using theKeyManagerFactoryand theTrustManagerFactory.voidsetClientSessionCacheSize(int size) Sets the SSLSession cache size for theSSLSessionContextfor use in client mode.voidsetClientSessionTimeout(int seconds) Set the SSLSession timeout limit for theSSLSessionContextfor use in client mode.voidsetKeyManagerFactory(KeyManagerFactory factory) Sets theKeyManagerFactoryto use.voidsetKeyManagerFactoryAlgorithm(String algorithm) Sets the algorithm to use when creating theKeyManagerFactoryusingKeyManagerFactory.getInstance(java.lang.String)orKeyManagerFactory.getInstance(java.lang.String, java.lang.String).voidsetKeyManagerFactoryAlgorithmUseDefault(boolean useDefault) If this is set totruewhile noKeyManagerFactoryhas been set usingsetKeyManagerFactory(KeyManagerFactory)and no algorithm has been set usingsetKeyManagerFactoryAlgorithm(String)the default algorithm return byKeyManagerFactory.getDefaultAlgorithm()will be used.voidsetKeyManagerFactoryKeyStore(KeyStore keyStore) Sets theKeyStorewhich will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])when theSSLContextis created.voidsetKeyManagerFactoryKeyStorePassword(String password) Sets the password which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])when theSSLContextis created.voidsetKeyManagerFactoryProvider(String provider) Sets the provider to use when creating theKeyManagerFactoryusingKeyManagerFactory.getInstance(java.lang.String, java.lang.String).voidsetProtocol(String protocol) Sets the protocol to use when creating theSSLContext.voidsetProvider(String provider) Sets the provider of the newSSLContext.voidsetSecureRandom(SecureRandom secureRandom) Sets theSecureRandomto use when initializing theSSLContext.voidsetServerSessionCacheSize(int serverSessionCacheSize) Sets the SSLSession cache size for theSSLSessionContextfor use in server mode.voidsetServerSessionTimeout(int serverSessionTimeout) Set the SSLSession timeout limit for theSSLSessionContextfor use in server mode.voidSets theTrustManagerFactoryto use.voidsetTrustManagerFactoryAlgorithm(String algorithm) Sets the algorithm to use when creating theTrustManagerFactoryusingTrustManagerFactory.getInstance(java.lang.String)orTrustManagerFactory.getInstance(java.lang.String, java.lang.String).voidsetTrustManagerFactoryAlgorithmUseDefault(boolean useDefault) If this is set totruewhile noTrustManagerFactoryhas been set usingsetTrustManagerFactory(TrustManagerFactory)and no algorithm has been set usingsetTrustManagerFactoryAlgorithm(String)the default algorithm return byTrustManagerFactory.getDefaultAlgorithm()will be used.voidsetTrustManagerFactoryKeyStore(KeyStore keyStore) Sets theKeyStorewhich will be used in the call toTrustManagerFactory.init(java.security.KeyStore)when theSSLContextis created.voidSets theManagerFactoryParameterswhich will be used in the call toTrustManagerFactory.init(javax.net.ssl.ManagerFactoryParameters)when theSSLContextis created.voidsetTrustManagerFactoryProvider(String provider) Sets the provider to use when creating theTrustManagerFactoryusingTrustManagerFactory.getInstance(java.lang.String, java.lang.String).
-
Field Details
-
provider
-
protocol
-
secureRandom
-
keyManagerFactoryKeyStore
-
keyManagerFactoryKeyStorePassword
private char[] keyManagerFactoryKeyStorePassword -
keyManagerFactory
-
keyManagerFactoryAlgorithm
-
keyManagerFactoryProvider
-
keyManagerFactoryAlgorithmUseDefault
private boolean keyManagerFactoryAlgorithmUseDefault -
trustManagerFactoryKeyStore
-
trustManagerFactory
-
trustManagerFactoryAlgorithm
-
trustManagerFactoryProvider
-
trustManagerFactoryAlgorithmUseDefault
private boolean trustManagerFactoryAlgorithmUseDefault -
trustManagerFactoryParameters
-
clientSessionCacheSize
private int clientSessionCacheSize -
clientSessionTimeout
private int clientSessionTimeout -
serverSessionCacheSize
private int serverSessionCacheSize -
serverSessionTimeout
private int serverSessionTimeout
-
-
Constructor Details
-
SslContextFactory
public SslContextFactory()
-
-
Method Details
-
newInstance
Create a new SSLContext instance,using theKeyManagerFactoryand theTrustManagerFactory.- Returns:
- The created instance
- Throws:
Exception- If we weren't able to create the SSLContext insyance
-
setProvider
Sets the provider of the newSSLContext. The default value isnull, which means the default provider will be used.- Parameters:
provider- the name of theSSLContextprovider
-
setProtocol
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 totruewhile noKeyManagerFactoryhas 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-trueorfalse.
-
setTrustManagerFactoryAlgorithmUseDefault
public void setTrustManagerFactoryAlgorithmUseDefault(boolean useDefault) If this is set totruewhile noTrustManagerFactoryhas 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-trueorfalse.
-
setKeyManagerFactory
Sets theKeyManagerFactoryto use. If this is set the properties which are used by this factory bean to create aKeyManagerFactorywill all be ignored.- Parameters:
factory- the factory.
-
setKeyManagerFactoryAlgorithm
Sets the algorithm to use when creating theKeyManagerFactoryusingKeyManagerFactory.getInstance(java.lang.String)orKeyManagerFactory.getInstance(java.lang.String, java.lang.String).This property will be ignored if a
KeyManagerFactoryhas been set directly usingsetKeyManagerFactory(KeyManagerFactory).If this property isn't set while no
KeyManagerFactoryhas been set usingsetKeyManagerFactory(KeyManagerFactory)andsetKeyManagerFactoryAlgorithmUseDefault(boolean)has been set totruethe value returned byKeyManagerFactory.getDefaultAlgorithm()will be used instead.- Parameters:
algorithm- the algorithm to use.
-
setKeyManagerFactoryProvider
Sets the provider to use when creating theKeyManagerFactoryusingKeyManagerFactory.getInstance(java.lang.String, java.lang.String).This property will be ignored if a
KeyManagerFactoryhas been set directly usingsetKeyManagerFactory(KeyManagerFactory).If this property isn't set and no
KeyManagerFactoryhas been set usingsetKeyManagerFactory(KeyManagerFactory)KeyManagerFactory.getInstance(java.lang.String)will be used to create theKeyManagerFactory.- Parameters:
provider- the name of the provider.
-
setKeyManagerFactoryKeyStore
Sets theKeyStorewhich will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])when theSSLContextis created.- Parameters:
keyStore- the key store.
-
setKeyManagerFactoryKeyStorePassword
Sets the password which will be used in the call toKeyManagerFactory.init(java.security.KeyStore, char[])when theSSLContextis created.- Parameters:
password- the password. Usenullto disable password.
-
setTrustManagerFactory
Sets theTrustManagerFactoryto use. If this is set the properties which are used by this factory bean to create aTrustManagerFactorywill all be ignored.- Parameters:
factory- the factory.
-
setTrustManagerFactoryAlgorithm
Sets the algorithm to use when creating theTrustManagerFactoryusingTrustManagerFactory.getInstance(java.lang.String)orTrustManagerFactory.getInstance(java.lang.String, java.lang.String).This property will be ignored if a
TrustManagerFactoryhas been set directly usingsetTrustManagerFactory(TrustManagerFactory).If this property isn't set while no
TrustManagerFactoryhas been set usingsetTrustManagerFactory(TrustManagerFactory)andsetTrustManagerFactoryAlgorithmUseDefault(boolean)has been set totruethe value returned byTrustManagerFactory.getDefaultAlgorithm()will be used instead.- Parameters:
algorithm- the algorithm to use.
-
setTrustManagerFactoryKeyStore
Sets theKeyStorewhich will be used in the call toTrustManagerFactory.init(java.security.KeyStore)when theSSLContextis created.This property will be ignored if
ManagerFactoryParametershas been set directly usingsetTrustManagerFactoryParameters(ManagerFactoryParameters).- Parameters:
keyStore- the key store.
-
setTrustManagerFactoryParameters
Sets theManagerFactoryParameterswhich will be used in the call toTrustManagerFactory.init(javax.net.ssl.ManagerFactoryParameters)when theSSLContextis created.- Parameters:
parameters- describing provider-specific trust material.
-
setTrustManagerFactoryProvider
Sets the provider to use when creating theTrustManagerFactoryusingTrustManagerFactory.getInstance(java.lang.String, java.lang.String).This property will be ignored if a
TrustManagerFactoryhas been set directly usingsetTrustManagerFactory(TrustManagerFactory).If this property isn't set and no
TrustManagerFactoryhas been set usingsetTrustManagerFactory(TrustManagerFactory)TrustManagerFactory.getInstance(java.lang.String)will be used to create theTrustManagerFactory.- Parameters:
provider- the name of the provider.
-
setSecureRandom
Sets theSecureRandomto use when initializing theSSLContext. The JVM's default will be used if this isn't set.- Parameters:
secureRandom- theSecureRandomornullif the JVM's default should be used.- See Also:
-
setClientSessionCacheSize
public void setClientSessionCacheSize(int size) Sets the SSLSession cache size for theSSLSessionContextfor use in client mode.- Parameters:
size- the new session cache size limit; zero means there is no limit.- See Also:
-
setClientSessionTimeout
public void setClientSessionTimeout(int seconds) Set the SSLSession timeout limit for theSSLSessionContextfor use in client mode.- Parameters:
seconds- the new session timeout limit in seconds; zero means there is no limit.- See Also:
-
setServerSessionCacheSize
public void setServerSessionCacheSize(int serverSessionCacheSize) Sets the SSLSession cache size for theSSLSessionContextfor use in server mode.- Parameters:
serverSessionCacheSize- the new session cache size limit; zero means there is no limit.- See Also:
-
setServerSessionTimeout
public void setServerSessionTimeout(int serverSessionTimeout) Set the SSLSession timeout limit for theSSLSessionContextfor use in server mode.- Parameters:
serverSessionTimeout- the new session timeout limit in seconds; zero means there is no limit.- See Also:
-