Class SslContextConfigurator
Used to configure SslEngineConfigurator
, which will be passed to client via configuration properties.
Example:
SslContextConfigurator sslContextConfigurator = new SslContextConfigurator(); sslContextConfigurator.setTrustStoreFile("..."); sslContextConfigurator.setTrustStorePassword("..."); sslContextConfigurator.setTrustStoreType("..."); sslContextConfigurator.setKeyStoreFile("..."); sslContextConfigurator.setKeyStorePassword("..."); sslContextConfigurator.setKeyStoreType("..."); SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(sslContextConfigurator, true, false, false); client.getProperties().put(ClientManager.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
- Author:
- Alexey Stashok, Hubert Iwaniuk, Bruno Harbulot, Marek Potociar
-
Field Summary
Modifier and TypeFieldDescriptionstatic final SslContextConfigurator
Default SSL configuration.static final String
Key manager factory algorithm name.static final String
Key store file name.static final String
Key store file password - the password used to unlock the trust store file.static final String
Key store provider name.static final String
Key store type (seeKeyStore.getType()
for more info).static final String
Trust manager factory algorithm name.static final String
Trust store file name.static final String
Trust store file password - the password used to unlock the trust store file.static final String
Trust store provider name.static final String
Trust store type (seeKeyStore.getType()
for more info). -
Constructor Summary
ConstructorDescriptionDefault constructor.SslContextConfigurator
(boolean readSystemProperties) Constructor that allows you creating empty configuration. -
Method Summary
Modifier and TypeMethodDescriptionCreateSSLContext
from current configuration.retrieve
(Properties props) Retrieve settings from (system) properties.setKeyManagerFactoryAlgorithm
(String keyManagerFactoryAlgorithm) Sets the key manager factory algorithm.setKeyPassword
(char[] keyPassword) Password of the key in the key store.setKeyPassword
(String keyPassword) Password of the key in the key store.setKeyStoreBytes
(byte[] keyStoreBytes) Sets key store payload as byte array.setKeyStoreFile
(String keyStoreFile) Sets key store file name, also makes sure that if other key store configuration parameters are not set to set them to default values.setKeyStorePassword
(char[] keyStorePassword) Password of key store.setKeyStorePassword
(String keyStorePassword) Password of key store.setKeyStoreProvider
(String keyStoreProvider) Sets the key store provider name.setKeyStoreType
(String keyStoreType) Type of key store.setSecurityProtocol
(String securityProtocol) Sets the SSLContext protocol.setTrustManagerFactoryAlgorithm
(String trustManagerFactoryAlgorithm) Sets the trust manager factory algorithm.setTrustStoreBytes
(byte[] trustStoreBytes) Sets trust store payload as byte array.setTrustStoreFile
(String trustStoreFile) Sets trust store file name, also makes sure that if other trust store configuration parameters are not set to set them to default values.setTrustStorePassword
(String trustStorePassword) Password of trust store.setTrustStoreProvider
(String trustStoreProvider) Sets the trust store provider name.setTrustStoreType
(String trustStoreType) Type of trust store.boolean
ValidatesSslContextConfigurator
configuration.boolean
validateConfiguration
(boolean needsKeyStore) ValidatesSslContextConfigurator
configuration.
-
Field Details
-
TRUST_STORE_PROVIDER
Trust store provider name.The value MUST be a
String
representing the name of a trust store provider.No default value is set.
The name of the configuration property is
"javax.net.ssl.trustStoreProvider"
.- See Also:
-
KEY_STORE_PROVIDER
Key store provider name.The value MUST be a
String
representing the name of a trust store provider.No default value is set.
The name of the configuration property is
"javax.net.ssl.keyStoreProvider"
.- See Also:
-
TRUST_STORE_FILE
Trust store file name.The value MUST be a
String
representing the name of a trust store file.No default value is set.
The name of the configuration property is
"javax.net.ssl.trustStore"
.- See Also:
-
KEY_STORE_FILE
Key store file name.The value MUST be a
String
representing the name of a key store file.No default value is set.
The name of the configuration property is
"javax.net.ssl.keyStore"
.- See Also:
-
TRUST_STORE_PASSWORD
Trust store file password - the password used to unlock the trust store file.The value MUST be a
String
representing the trust store file password.No default value is set.
The name of the configuration property is
"javax.net.ssl.trustStorePassword"
.- See Also:
-
KEY_STORE_PASSWORD
Key store file password - the password used to unlock the trust store file.The value MUST be a
String
representing the key store file password.No default value is set.
The name of the configuration property is
"javax.net.ssl.keyStorePassword"
.- See Also:
-
TRUST_STORE_TYPE
Trust store type (seeKeyStore.getType()
for more info).The value MUST be a
String
representing the trust store type name.No default value is set.
The name of the configuration property is
"javax.net.ssl.trustStoreType"
.- See Also:
-
KEY_STORE_TYPE
Key store type (seeKeyStore.getType()
for more info).The value MUST be a
String
representing the key store type name.No default value is set.
The name of the configuration property is
"javax.net.ssl.keyStoreType"
.- See Also:
-
KEY_FACTORY_MANAGER_ALGORITHM
Key manager factory algorithm name.The value MUST be a
String
representing the key manager factory algorithm name.No default value is set.
The name of the configuration property is
"ssl.KeyManagerFactory.algorithm"
.- See Also:
-
TRUST_FACTORY_MANAGER_ALGORITHM
Trust manager factory algorithm name.The value MUST be a
String
representing the trust manager factory algorithm name.No default value is set.
The name of the configuration property is
"ssl.TrustManagerFactory.algorithm"
.- See Also:
-
DEFAULT_CONFIG
Default SSL configuration. If you have changed any ofSystem.getProperties()
of javax.net.ssl family you should refresh this configuration by callingretrieve(java.util.Properties)
.
-
-
Constructor Details
-
SslContextConfigurator
public SslContextConfigurator()Default constructor. Reads configuration properties fromSystem.getProperties()
. CallsSslContextConfigurator(boolean)
withtrue
. -
SslContextConfigurator
public SslContextConfigurator(boolean readSystemProperties) Constructor that allows you creating empty configuration.- Parameters:
readSystemProperties
- Iftrue
populates configuration fromSystem.getProperties()
, else you have empty configuration.
-
-
Method Details
-
setTrustStoreProvider
Sets the trust store provider name.- Parameters:
trustStoreProvider
- Trust store provider to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStoreProvider
Sets the key store provider name.- Parameters:
keyStoreProvider
- Key store provider to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setTrustStoreType
Type of trust store.- Parameters:
trustStoreType
- Type of trust store to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStoreType
Type of key store.- Parameters:
keyStoreType
- Type of key store to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setTrustStorePassword
Password of trust store.- Parameters:
trustStorePassword
- Password of trust store to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStorePassword
Password of key store.- Parameters:
keyStorePassword
- Password of key store to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStorePassword
Password of key store.- Parameters:
keyStorePassword
- Password of key store to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyPassword
Password of the key in the key store.- Parameters:
keyPassword
- Password of key to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyPassword
Password of the key in the key store.- Parameters:
keyPassword
- Password of key to set.- Returns:
- updated
SslContextConfigurator
instance.
-
setTrustStoreFile
Sets trust store file name, also makes sure that if other trust store configuration parameters are not set to set them to default values. Method resets trust store bytes if any have been set before viasetTrustStoreBytes(byte[])
.- Parameters:
trustStoreFile
- File name of trust store.- Returns:
- updated
SslContextConfigurator
instance.
-
setTrustStoreBytes
Sets trust store payload as byte array. Method resets trust store file if any has been set before viasetTrustStoreFile(java.lang.String)
.- Parameters:
trustStoreBytes
- trust store payload.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStoreFile
Sets key store file name, also makes sure that if other key store configuration parameters are not set to set them to default values. Method resets key store bytes if any have been set before viasetKeyStoreBytes(byte[])
.- Parameters:
keyStoreFile
- File name of key store.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyStoreBytes
Sets key store payload as byte array. Method resets key store file if any has been set before viasetKeyStoreFile(java.lang.String)
.- Parameters:
keyStoreBytes
- key store payload.- Returns:
- updated
SslContextConfigurator
instance.
-
setTrustManagerFactoryAlgorithm
Sets the trust manager factory algorithm.- Parameters:
trustManagerFactoryAlgorithm
- the trust manager factory algorithm.- Returns:
- updated
SslContextConfigurator
instance.
-
setKeyManagerFactoryAlgorithm
Sets the key manager factory algorithm.- Parameters:
keyManagerFactoryAlgorithm
- the key manager factory algorithm.- Returns:
- updated
SslContextConfigurator
instance.
-
setSecurityProtocol
Sets the SSLContext protocol. The default value isTLS
if this is null.- Parameters:
securityProtocol
- Protocol forSSLContext.getProtocol()
.- Returns:
- updated
SslContextConfigurator
instance.
-
validateConfiguration
public boolean validateConfiguration()ValidatesSslContextConfigurator
configuration.- Returns:
true
if configuration is valid, elsefalse
.
-
validateConfiguration
public boolean validateConfiguration(boolean needsKeyStore) ValidatesSslContextConfigurator
configuration.- Parameters:
needsKeyStore
- forces failure if no keystore is specified.- Returns:
true
if configuration is valid, elsefalse
.
-
createSSLContext
CreateSSLContext
from current configuration.- Returns:
- created
SSLContext
.
-
retrieve
Retrieve settings from (system) properties.- Parameters:
props
- property map (usually taken fromSystem.getProperties()
).- Returns:
- updated
SslContextConfigurator
instance.
-