Class SslConfigurator
- java.lang.Object
-
- org.glassfish.jersey.SslConfigurator
-
public final class SslConfigurator extends java.lang.Object
Utility class, which helps to configureSSLContext
instances. For example:SslConfigurator sslConfig = SslConfigurator.newInstance() .trustStoreFile("truststore.jks") .trustStorePassword("asdfgh") .trustStoreType("JKS") .trustManagerFactoryAlgorithm("PKIX") .keyStoreFile("keystore.jks") .keyPassword("asdfgh") .keyStoreType("JKS") .keyManagerFactoryAlgorithm("SunX509") .keyStoreProvider("SunJSSE") .securityProtocol("SSL"); SSLContext sslContext = sslConfig.createSSLContext();
-
-
Field Summary
Fields Modifier and Type Field Description private static SslConfigurator
DEFAULT_CONFIG_NO_PROPS
Default SSL configuration that is used to create default SSL context instances that do not take into account system properties.static java.lang.String
KEY_MANAGER_FACTORY_ALGORITHM
Key manager factory algorithm name.static java.lang.String
KEY_MANAGER_FACTORY_PROVIDER
Key manager factory provider name.static java.lang.String
KEY_STORE_FILE
Key store file name.static java.lang.String
KEY_STORE_PASSWORD
Key store file password - the password used to unlock the trust store file.static java.lang.String
KEY_STORE_PROVIDER
Key store provider name.static java.lang.String
KEY_STORE_TYPE
Key store type (seeKeyStore.getType()
for more info).private java.lang.String
keyManagerFactoryAlgorithm
private java.lang.String
keyManagerFactoryProvider
private char[]
keyPass
private java.security.KeyStore
keyStore
private byte[]
keyStoreBytes
private java.lang.String
keyStoreFile
private char[]
keyStorePass
private java.lang.String
keyStoreProvider
private java.lang.String
keyStoreType
private static java.util.logging.Logger
LOGGER
Logger.private java.lang.String
securityProtocol
static java.lang.String
TRUST_MANAGER_FACTORY_ALGORITHM
Trust manager factory algorithm name.static java.lang.String
TRUST_MANAGER_FACTORY_PROVIDER
Trust manager factory provider name.static java.lang.String
TRUST_STORE_FILE
Trust store file name.static java.lang.String
TRUST_STORE_PASSWORD
Trust store file password - the password used to unlock the trust store file.static java.lang.String
TRUST_STORE_PROVIDER
Trust store provider name.static java.lang.String
TRUST_STORE_TYPE
Trust store type (seeKeyStore.getType()
for more info).private java.lang.String
trustManagerFactoryAlgorithm
private java.lang.String
trustManagerFactoryProvider
private java.security.KeyStore
trustStore
private byte[]
trustStoreBytes
private java.lang.String
trustStoreFile
private char[]
trustStorePass
private java.lang.String
trustStoreProvider
private java.lang.String
trustStoreType
-
Constructor Summary
Constructors Modifier Constructor Description private
SslConfigurator(boolean readSystemProperties)
private
SslConfigurator(SslConfigurator that)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SslConfigurator
copy()
Create a copy of the current SSL configurator instance.javax.net.ssl.SSLContext
createSSLContext()
Create new SSL context instance using the current SSL context configuration.boolean
equals(java.lang.Object o)
static javax.net.ssl.SSLContext
getDefaultContext()
Get a new instance of aSSLContext
configured using default configuration settings.static javax.net.ssl.SSLContext
getDefaultContext(boolean readSystemProperties)
Get a new instance of aSSLContext
configured using default configuration settings.(package private) java.security.KeyStore
getKeyStore()
Get the key store instance.(package private) java.security.KeyStore
getTrustStore()
Get the trust store instance.int
hashCode()
SslConfigurator
keyManagerFactoryAlgorithm(java.lang.String algorithm)
Set the key manager factory algorithm.SslConfigurator
keyManagerFactoryProvider(java.lang.String provider)
Set the key manager factory provider.SslConfigurator
keyPassword(char[] password)
Set the password of the key in the key store.SslConfigurator
keyPassword(java.lang.String password)
Set the password of the key in the key store.SslConfigurator
keyStore(java.security.KeyStore keyStore)
Set the key store instance.SslConfigurator
keyStoreBytes(byte[] payload)
Set the key store payload as byte array.SslConfigurator
keyStoreFile(java.lang.String fileName)
Set the key store file name.SslConfigurator
keyStorePassword(char[] password)
Set the password of key store.SslConfigurator
keyStorePassword(java.lang.String password)
Set the password of key store.SslConfigurator
keyStoreProvider(java.lang.String keyStoreProvider)
Set the key store provider name.SslConfigurator
keyStoreType(java.lang.String keyStoreType)
Set the type of key store.static SslConfigurator
newInstance()
Get a new & initialized SSL configurator instance.static SslConfigurator
newInstance(boolean readSystemProperties)
Get a new SSL configurator instance.SslConfigurator
retrieve(java.util.Properties props)
Retrieve the SSL context configuration from the supplied properties.SslConfigurator
securityProtocol(java.lang.String protocol)
Set the SSLContext protocol.SslConfigurator
trustManagerFactoryAlgorithm(java.lang.String algorithm)
Set the trust manager factory algorithm.SslConfigurator
trustManagerFactoryProvider(java.lang.String provider)
Set the trust manager factory provider.SslConfigurator
trustStore(java.security.KeyStore trustStore)
Set the trust store instance.SslConfigurator
trustStoreBytes(byte[] payload)
Set the trust store payload as byte array.SslConfigurator
trustStoreFile(java.lang.String fileName)
Set the trust store file name.SslConfigurator
trustStorePassword(java.lang.String password)
Set the password of trust store.SslConfigurator
trustStoreProvider(java.lang.String trustStoreProvider)
Set the trust store provider name.SslConfigurator
trustStoreType(java.lang.String trustStoreType)
Set the type of trust store.
-
-
-
Field Detail
-
TRUST_STORE_PROVIDER
public static final java.lang.String TRUST_STORE_PROVIDER
Trust store provider name. The value MUST be aString
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:
- Constant Field Values
-
KEY_STORE_PROVIDER
public static final java.lang.String KEY_STORE_PROVIDER
Key store provider name. The value MUST be aString
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:
- Constant Field Values
-
TRUST_STORE_FILE
public static final java.lang.String TRUST_STORE_FILE
Trust store file name. The value MUST be aString
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:
- Constant Field Values
-
KEY_STORE_FILE
public static final java.lang.String KEY_STORE_FILE
Key store file name. The value MUST be aString
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:
- Constant Field Values
-
TRUST_STORE_PASSWORD
public static final java.lang.String TRUST_STORE_PASSWORD
Trust store file password - the password used to unlock the trust store file. The value MUST be aString
representing the trust store file password.No default value is set.
The name of the configuration property is "javax.net.ssl.trustStorePassword".
- See Also:
- Constant Field Values
-
KEY_STORE_PASSWORD
public static final java.lang.String KEY_STORE_PASSWORD
Key store file password - the password used to unlock the trust store file. The value MUST be aString
representing the key store file password.No default value is set.
The name of the configuration property is "javax.net.ssl.keyStorePassword".
- See Also:
- Constant Field Values
-
TRUST_STORE_TYPE
public static final java.lang.String TRUST_STORE_TYPE
Trust store type (seeKeyStore.getType()
for more info). The value MUST be aString
representing the trust store type name.No default value is set.
The name of the configuration property is "javax.net.ssl.trustStoreType".
- See Also:
- Constant Field Values
-
KEY_STORE_TYPE
public static final java.lang.String KEY_STORE_TYPE
Key store type (seeKeyStore.getType()
for more info). The value MUST be aString
representing the key store type name.No default value is set.
The name of the configuration property is "javax.net.ssl.keyStoreType".
- See Also:
- Constant Field Values
-
KEY_MANAGER_FACTORY_ALGORITHM
public static final java.lang.String KEY_MANAGER_FACTORY_ALGORITHM
Key manager factory algorithm name. The value MUST be aString
representing the key manager factory algorithm name.No default value is set.
The name of the configuration property is "ssl.keyManagerFactory.algorithm".
- See Also:
- Constant Field Values
-
KEY_MANAGER_FACTORY_PROVIDER
public static final java.lang.String KEY_MANAGER_FACTORY_PROVIDER
Key manager factory provider name. The value MUST be aString
representing the key manager factory provider name.No default value is set.
The name of the configuration property is "ssl.keyManagerFactory.provider".
- See Also:
- Constant Field Values
-
TRUST_MANAGER_FACTORY_ALGORITHM
public static final java.lang.String TRUST_MANAGER_FACTORY_ALGORITHM
Trust manager factory algorithm name. The value MUST be aString
representing the trust manager factory algorithm name.No default value is set.
The name of the configuration property is "ssl.trustManagerFactory.algorithm".
- See Also:
- Constant Field Values
-
TRUST_MANAGER_FACTORY_PROVIDER
public static final java.lang.String TRUST_MANAGER_FACTORY_PROVIDER
Trust manager factory provider name. The value MUST be aString
representing the trust manager factory provider name.No default value is set.
The name of the configuration property is "ssl.trustManagerFactory.provider".
- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_NO_PROPS
private static final SslConfigurator DEFAULT_CONFIG_NO_PROPS
Default SSL configuration that is used to create default SSL context instances that do not take into account system properties.
-
LOGGER
private static final java.util.logging.Logger LOGGER
Logger.
-
keyStore
private java.security.KeyStore keyStore
-
trustStore
private java.security.KeyStore trustStore
-
trustStoreProvider
private java.lang.String trustStoreProvider
-
keyStoreProvider
private java.lang.String keyStoreProvider
-
trustStoreType
private java.lang.String trustStoreType
-
keyStoreType
private java.lang.String keyStoreType
-
trustStorePass
private char[] trustStorePass
-
keyStorePass
private char[] keyStorePass
-
keyPass
private char[] keyPass
-
trustStoreFile
private java.lang.String trustStoreFile
-
keyStoreFile
private java.lang.String keyStoreFile
-
trustStoreBytes
private byte[] trustStoreBytes
-
keyStoreBytes
private byte[] keyStoreBytes
-
trustManagerFactoryAlgorithm
private java.lang.String trustManagerFactoryAlgorithm
-
keyManagerFactoryAlgorithm
private java.lang.String keyManagerFactoryAlgorithm
-
trustManagerFactoryProvider
private java.lang.String trustManagerFactoryProvider
-
keyManagerFactoryProvider
private java.lang.String keyManagerFactoryProvider
-
securityProtocol
private java.lang.String securityProtocol
-
-
Constructor Detail
-
SslConfigurator
private SslConfigurator(boolean readSystemProperties)
-
SslConfigurator
private SslConfigurator(SslConfigurator that)
-
-
Method Detail
-
getDefaultContext
public static javax.net.ssl.SSLContext getDefaultContext()
Get a new instance of aSSLContext
configured using default configuration settings. The default SSL configuration is initialized from system properties. This method is a shortcut forgetDefaultContext(true)
.- Returns:
- new instance of a default SSL context initialized from system properties.
-
getDefaultContext
public static javax.net.ssl.SSLContext getDefaultContext(boolean readSystemProperties)
Get a new instance of aSSLContext
configured using default configuration settings. IfreadSystemProperties
parameter is set totrue
, the default SSL configuration is initialized from system properties.- Parameters:
readSystemProperties
- iftrue
, the default SSL context will be initialized using system properties.- Returns:
- new instance of a default SSL context initialized from system properties.
-
newInstance
public static SslConfigurator newInstance()
Get a new & initialized SSL configurator instance. The instanceretrieves
the initial configuration fromsystem properties
.- Returns:
- new & initialized SSL configurator instance.
-
newInstance
public static SslConfigurator newInstance(boolean readSystemProperties)
Get a new SSL configurator instance.- Parameters:
readSystemProperties
- iftrue
,Retrieves
the initial configuration fromSystem.getProperties()
, otherwise the instantiated configurator will be empty.- Returns:
- new SSL configurator instance.
-
copy
public SslConfigurator copy()
Create a copy of the current SSL configurator instance.- Returns:
- copy of the current SSL configurator instance
-
trustStoreProvider
public SslConfigurator trustStoreProvider(java.lang.String trustStoreProvider)
Set the trust store provider name.- Parameters:
trustStoreProvider
- trust store provider to set.- Returns:
- updated SSL configurator instance.
-
keyStoreProvider
public SslConfigurator keyStoreProvider(java.lang.String keyStoreProvider)
Set the key store provider name.- Parameters:
keyStoreProvider
- key store provider to set.- Returns:
- updated SSL configurator instance.
-
trustStoreType
public SslConfigurator trustStoreType(java.lang.String trustStoreType)
Set the type of trust store.- Parameters:
trustStoreType
- type of trust store to set.- Returns:
- updated SSL configurator instance.
-
keyStoreType
public SslConfigurator keyStoreType(java.lang.String keyStoreType)
Set the type of key store.- Parameters:
keyStoreType
- type of key store to set.- Returns:
- updated SSL configurator instance.
-
trustStorePassword
public SslConfigurator trustStorePassword(java.lang.String password)
Set the password of trust store.- Parameters:
password
- password of trust store to set.- Returns:
- updated SSL configurator instance.
-
keyStorePassword
public SslConfigurator keyStorePassword(java.lang.String password)
Set the password of key store.- Parameters:
password
- password of key store to set.- Returns:
- updated SSL configurator instance.
-
keyStorePassword
public SslConfigurator keyStorePassword(char[] password)
Set the password of key store.- Parameters:
password
- password of key store to set.- Returns:
- updated SSL configurator instance.
-
keyPassword
public SslConfigurator keyPassword(java.lang.String password)
Set the password of the key in the key store.- Parameters:
password
- password of key to set.- Returns:
- updated SSL configurator instance.
-
keyPassword
public SslConfigurator keyPassword(char[] password)
Set the password of the key in the key store.- Parameters:
password
- password of key to set.- Returns:
- updated SSL configurator instance.
-
trustStoreFile
public SslConfigurator trustStoreFile(java.lang.String fileName)
Set the trust store file name.Setting a trust store instance resets any
trust store instance
ortrust store payload
value previously set.- Parameters:
fileName
-file
name of the trust store.- Returns:
- updated SSL configurator instance.
-
trustStoreBytes
public SslConfigurator trustStoreBytes(byte[] payload)
Set the trust store payload as byte array.Setting a trust store instance resets any
trust store file
ortrust store instance
value previously set.- Parameters:
payload
- trust store payload.- Returns:
- updated SSL configurator instance.
-
keyStoreFile
public SslConfigurator keyStoreFile(java.lang.String fileName)
Set the key store file name.Setting a key store instance resets any
key store instance
orkey store payload
value previously set.- Parameters:
fileName
-file
name of the key store.- Returns:
- updated SSL configurator instance.
-
keyStoreBytes
public SslConfigurator keyStoreBytes(byte[] payload)
Set the key store payload as byte array.Setting a key store instance resets any
key store file
orkey store instance
value previously set.- Parameters:
payload
- key store payload.- Returns:
- updated SSL configurator instance.
-
trustManagerFactoryAlgorithm
public SslConfigurator trustManagerFactoryAlgorithm(java.lang.String algorithm)
Set the trust manager factory algorithm.- Parameters:
algorithm
- the trust manager factory algorithm.- Returns:
- updated SSL configurator instance.
-
keyManagerFactoryAlgorithm
public SslConfigurator keyManagerFactoryAlgorithm(java.lang.String algorithm)
Set the key manager factory algorithm.- Parameters:
algorithm
- the key manager factory algorithm.- Returns:
- updated SSL configurator instance.
-
trustManagerFactoryProvider
public SslConfigurator trustManagerFactoryProvider(java.lang.String provider)
Set the trust manager factory provider.- Parameters:
provider
- the trust manager factory provider.- Returns:
- updated SSL configurator instance.
-
keyManagerFactoryProvider
public SslConfigurator keyManagerFactoryProvider(java.lang.String provider)
Set the key manager factory provider.- Parameters:
provider
- the key manager factory provider.- Returns:
- updated SSL configurator instance.
-
securityProtocol
public SslConfigurator securityProtocol(java.lang.String protocol)
Set the SSLContext protocol. The default value isTLS
if this isnull
.- Parameters:
protocol
- protocol forSSLContext.getProtocol()
.- Returns:
- updated SSL configurator instance.
-
getKeyStore
java.security.KeyStore getKeyStore()
Get the key store instance.- Returns:
- key store instance or
null
if not explicitly set.
-
keyStore
public SslConfigurator keyStore(java.security.KeyStore keyStore)
Set the key store instance.Setting a key store instance resets any
key store file
orkey store payload
value previously set.- Parameters:
keyStore
- key store instance.- Returns:
- updated SSL configurator instance.
-
getTrustStore
java.security.KeyStore getTrustStore()
Get the trust store instance.Setting a trust store instance resets any
trust store file
ortrust store payload
value previously set.- Returns:
- trust store instance or
null
if not explicitly set.
-
trustStore
public SslConfigurator trustStore(java.security.KeyStore trustStore)
Set the trust store instance.- Parameters:
trustStore
- trust store instance.- Returns:
- updated SSL configurator instance.
-
createSSLContext
public javax.net.ssl.SSLContext createSSLContext()
Create new SSL context instance using the current SSL context configuration.- Returns:
- newly configured SSL context instance.
-
retrieve
public SslConfigurator retrieve(java.util.Properties props)
Retrieve the SSL context configuration from the supplied properties.- Parameters:
props
- properties containing the SSL context configuration.- Returns:
- updated SSL configurator instance.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-