Top Description Fields Constructors Methods
org.glassfish.tyrus.client

public Class SslContextConfigurator

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, java.security.KeyManagementException, .KeyStore, .KeyStoreException, .NoSuchAlgorithmException, .NoSuchProviderException, .UnrecoverableKeyException, java.security.cert.CertificateException, java.util.Properties, java.util.logging.Level, .Logger, javax.net.ssl.KeyManagerFactory, .SSLContext, .TrustManagerFactory

Utility class, which helps to configure ssl context.

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);
Authors
Alexey Stashok, Hubert Iwaniuk, Bruno Harbulot, Marek Potociar

Field Summary

Modifier and TypeField and Description
public static final SslContextConfigurator
DEFAULT_CONFIG

Default SSL configuration.

public static final String
KEY_FACTORY_MANAGER_ALGORITHM

Key manager factory algorithm name.

public static final String
KEY_STORE_FILE

Key store file name.

public static final String
KEY_STORE_PASSWORD

Key store file password - the password used to unlock the trust store file.

public static final String
KEY_STORE_PROVIDER

Key store provider name.

public static final String
KEY_STORE_TYPE

Key store type (see java.security.KeyStore#getType() for more info).

private String
private char[]
private byte[]
private String
private char[]
private String
private String
private static final Logger
LOGGER

Default Logger.

private String
public static final String
TRUST_FACTORY_MANAGER_ALGORITHM

Trust manager factory algorithm name.

public static final String
TRUST_STORE_FILE

Trust store file name.

public static final String
TRUST_STORE_PASSWORD

Trust store file password - the password used to unlock the trust store file.

public static final String
TRUST_STORE_PROVIDER

Trust store provider name.

public static final String
TRUST_STORE_TYPE

Trust store type (see java.security.KeyStore#getType() for more info).

private String
private byte[]
private String
private char[]
private String
private String

Constructor Summary

AccessConstructor and Description
public
SslContextConfigurator()

Default constructor.

public
SslContextConfigurator(boolean
If true populates configuration from System#getProperties(), else you have empty configuration.
readSystemProperties
)

Constructor that allows you creating empty configuration.

Method Summary

Modifier and TypeMethod and Description
public SSLContext

Returns:

created SSLContext.
createSSLContext
()

Create SSLContext from current configuration.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
retrieve
(Properties
property map (usually taken from System#getProperties()).
props
)

Retrieve settings from (system) properties.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyManagerFactoryAlgorithm
(String
the key manager factory algorithm.
keyManagerFactoryAlgorithm
)

Sets the key manager factory algorithm.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyPassword
(String
Password of key to set.
keyPassword
)

Password of the key in the key store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyPassword
(char[]
Password of key to set.
keyPassword
)

Password of the key in the key store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStoreBytes
(byte[]
key store payload.
keyStoreBytes
)

Sets key store payload as byte array.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStoreFile
(String
File name of key store.
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.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStorePassword
(String
Password of key store to set.
keyStorePassword
)

Password of key store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStorePassword
(char[]
Password of key store to set.
keyStorePassword
)

Password of key store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStoreProvider
(String
Key store provider to set.
keyStoreProvider
)

Sets the key store provider name.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setKeyStoreType
(String
Type of key store to set.
keyStoreType
)

Type of key store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setSecurityProtocol
(String securityProtocol)

Sets the SSLContext protocol.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustManagerFactoryAlgorithm
(String
the trust manager factory algorithm.
trustManagerFactoryAlgorithm
)

Sets the trust manager factory algorithm.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustStoreBytes
(byte[]
trust store payload.
trustStoreBytes
)

Sets trust store payload as byte array.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustStoreFile
(String
File name of trust store.
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.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustStorePassword
(String
Password of trust store to set.
trustStorePassword
)

Password of trust store.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustStoreProvider
(String
Trust store provider to set.
trustStoreProvider
)

Sets the trust store provider name.

public SslContextConfigurator

Returns:

updated SslContextConfigurator instance.
setTrustStoreType
(String
Type of trust store to set.
trustStoreType
)

Type of trust store.

public boolean

Returns:

true if configuration is valid, else false.
validateConfiguration
()

Validates SslContextConfigurator configuration.

public boolean

Returns:

true if configuration is valid, else false.
validateConfiguration
(boolean
forces failure if no keystore is specified.
needsKeyStore
)

Validates SslContextConfigurator configuration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_CONFIGback to summary
public static final SslContextConfigurator DEFAULT_CONFIG

Default SSL configuration. If you have changed any of System#getProperties() of javax.net.ssl family you should refresh this configuration by calling retrieve(java.util.Properties).

KEY_FACTORY_MANAGER_ALGORITHMback to summary
public static final String 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 .

KEY_STORE_FILEback to summary
public static final String 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 .

KEY_STORE_PASSWORDback to summary
public static final String 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 .

KEY_STORE_PROVIDERback to summary
public static final String 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 .

KEY_STORE_TYPEback to summary
public static final String KEY_STORE_TYPE

Key store type (see java.security.KeyStore#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 .

keyManagerFactoryAlgorithmback to summary
private String keyManagerFactoryAlgorithm
keyPasswordback to summary
private char[] keyPassword
keyStoreBytesback to summary
private byte[] keyStoreBytes
keyStoreFileback to summary
private String keyStoreFile
keyStorePasswordback to summary
private char[] keyStorePassword
keyStoreProviderback to summary
private String keyStoreProvider
keyStoreTypeback to summary
private String keyStoreType
LOGGERback to summary
private static final Logger LOGGER

Default Logger.

securityProtocolback to summary
private String securityProtocol
TRUST_FACTORY_MANAGER_ALGORITHMback to summary
public static final String 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 .

TRUST_STORE_FILEback to summary
public static final String 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 .

TRUST_STORE_PASSWORDback to summary
public static final String 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 .

TRUST_STORE_PROVIDERback to summary
public static final String 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 .

TRUST_STORE_TYPEback to summary
public static final String TRUST_STORE_TYPE

Trust store type (see java.security.KeyStore#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 .

trustManagerFactoryAlgorithmback to summary
private String trustManagerFactoryAlgorithm
trustStoreBytesback to summary
private byte[] trustStoreBytes
trustStoreFileback to summary
private String trustStoreFile
trustStorePasswordback to summary
private char[] trustStorePassword
trustStoreProviderback to summary
private String trustStoreProvider
trustStoreTypeback to summary
private String trustStoreType

Constructor Detail

SslContextConfiguratorback to summary
public SslContextConfigurator()

Default constructor. Reads configuration properties from System#getProperties(). Calls SslContextConfigurator(boolean) with true.

SslContextConfiguratorback to summary
public SslContextConfigurator(boolean readSystemProperties)

Constructor that allows you creating empty configuration.

Parameters
readSystemProperties:boolean

If true populates configuration from System#getProperties(), else you have empty configuration.

Method Detail

createSSLContextback to summary
public SSLContext createSSLContext()

Create SSLContext from current configuration.

Returns:SSLContext

created SSLContext.

retrieveback to summary
public SslContextConfigurator retrieve(Properties props)

Retrieve settings from (system) properties.

Parameters
props:Properties

property map (usually taken from System#getProperties()).

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyManagerFactoryAlgorithmback to summary
public SslContextConfigurator setKeyManagerFactoryAlgorithm(String keyManagerFactoryAlgorithm)

Sets the key manager factory algorithm.

Parameters
keyManagerFactoryAlgorithm:String

the key manager factory algorithm.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyPasswordback to summary
public SslContextConfigurator setKeyPassword(String keyPassword)

Password of the key in the key store.

Parameters
keyPassword:String

Password of key to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyPasswordback to summary
public SslContextConfigurator setKeyPassword(char[] keyPassword)

Password of the key in the key store.

Parameters
keyPassword:char[]

Password of key to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStoreBytesback to summary
public SslContextConfigurator setKeyStoreBytes(byte[] keyStoreBytes)

Sets key store payload as byte array. Method resets key store file if any has been set before via setKeyStoreFile(java.lang.String).

Parameters
keyStoreBytes:byte[]

key store payload.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStoreFileback to summary
public SslContextConfigurator 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. Method resets key store bytes if any have been set before via setKeyStoreBytes(byte[]).

Parameters
keyStoreFile:String

File name of key store.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStorePasswordback to summary
public SslContextConfigurator setKeyStorePassword(String keyStorePassword)

Password of key store.

Parameters
keyStorePassword:String

Password of key store to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStorePasswordback to summary
public SslContextConfigurator setKeyStorePassword(char[] keyStorePassword)

Password of key store.

Parameters
keyStorePassword:char[]

Password of key store to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStoreProviderback to summary
public SslContextConfigurator setKeyStoreProvider(String keyStoreProvider)

Sets the key store provider name.

Parameters
keyStoreProvider:String

Key store provider to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setKeyStoreTypeback to summary
public SslContextConfigurator setKeyStoreType(String keyStoreType)

Type of key store.

Parameters
keyStoreType:String

Type of key store to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setSecurityProtocolback to summary
public SslContextConfigurator setSecurityProtocol(String securityProtocol)

Sets the SSLContext protocol. The default value is TLS if this is null.

Parameters
securityProtocol:String

Protocol for javax.net.ssl.SSLContext#getProtocol().

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustManagerFactoryAlgorithmback to summary
public SslContextConfigurator setTrustManagerFactoryAlgorithm(String trustManagerFactoryAlgorithm)

Sets the trust manager factory algorithm.

Parameters
trustManagerFactoryAlgorithm:String

the trust manager factory algorithm.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustStoreBytesback to summary
public SslContextConfigurator setTrustStoreBytes(byte[] trustStoreBytes)

Sets trust store payload as byte array. Method resets trust store file if any has been set before via setTrustStoreFile(java.lang.String).

Parameters
trustStoreBytes:byte[]

trust store payload.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustStoreFileback to summary
public SslContextConfigurator 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. Method resets trust store bytes if any have been set before via setTrustStoreBytes(byte[]).

Parameters
trustStoreFile:String

File name of trust store.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustStorePasswordback to summary
public SslContextConfigurator setTrustStorePassword(String trustStorePassword)

Password of trust store.

Parameters
trustStorePassword:String

Password of trust store to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustStoreProviderback to summary
public SslContextConfigurator setTrustStoreProvider(String trustStoreProvider)

Sets the trust store provider name.

Parameters
trustStoreProvider:String

Trust store provider to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

setTrustStoreTypeback to summary
public SslContextConfigurator setTrustStoreType(String trustStoreType)

Type of trust store.

Parameters
trustStoreType:String

Type of trust store to set.

Returns:SslContextConfigurator

updated SslContextConfigurator instance.

validateConfigurationback to summary
public boolean validateConfiguration()

Validates SslContextConfigurator configuration.

Returns:boolean

true if configuration is valid, else false.

validateConfigurationback to summary
public boolean validateConfiguration(boolean needsKeyStore)

Validates SslContextConfigurator configuration.

Parameters
needsKeyStore:boolean

forces failure if no keystore is specified.

Returns:boolean

true if configuration is valid, else false.