Class SslConfigurator
- java.lang.Object
-
- org.glassfish.jersey.SslConfigurator
-
public final class SslConfigurator extends Object
Utility class, which helps to configureSSLContextinstances. 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();- Author:
- Alexey Stashok, Hubert Iwaniuk, Bruno Harbulot, Marek Potociar
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_MANAGER_FACTORY_ALGORITHMKey manager factory algorithm name.static StringKEY_MANAGER_FACTORY_PROVIDERKey manager factory provider name.static StringKEY_STORE_FILEKey store file name.static StringKEY_STORE_PASSWORDKey store file password - the password used to unlock the trust store file.static StringKEY_STORE_PROVIDERKey store provider name.static StringKEY_STORE_TYPEKey store type (seeKeyStore.getType()for more info).static StringTRUST_MANAGER_FACTORY_ALGORITHMTrust manager factory algorithm name.static StringTRUST_MANAGER_FACTORY_PROVIDERTrust manager factory provider name.static StringTRUST_STORE_FILETrust store file name.static StringTRUST_STORE_PASSWORDTrust store file password - the password used to unlock the trust store file.static StringTRUST_STORE_PROVIDERTrust store provider name.static StringTRUST_STORE_TYPETrust store type (seeKeyStore.getType()for more info).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SslConfiguratorcopy()Create a copy of the current SSL configurator instance.SSLContextcreateSSLContext()Create new SSL context instance using the current SSL context configuration.booleanequals(Object o)static SSLContextgetDefaultContext()Get a new instance of aSSLContextconfigured using default configuration settings.static SSLContextgetDefaultContext(boolean readSystemProperties)Get a new instance of aSSLContextconfigured using default configuration settings.inthashCode()SslConfiguratorkeyManagerFactoryAlgorithm(String algorithm)Set the key manager factory algorithm.SslConfiguratorkeyManagerFactoryProvider(String provider)Set the key manager factory provider.SslConfiguratorkeyPassword(char[] password)Set the password of the key in the key store.SslConfiguratorkeyPassword(String password)Set the password of the key in the key store.SslConfiguratorkeyStore(KeyStore keyStore)Set the key store instance.SslConfiguratorkeyStoreBytes(byte[] payload)Set the key store payload as byte array.SslConfiguratorkeyStoreFile(String fileName)Set the key store file name.SslConfiguratorkeyStorePassword(char[] password)Set the password of key store.SslConfiguratorkeyStorePassword(String password)Set the password of key store.SslConfiguratorkeyStoreProvider(String keyStoreProvider)Set the key store provider name.SslConfiguratorkeyStoreType(String keyStoreType)Set the type of key store.static SslConfiguratornewInstance()Get a new & initialized SSL configurator instance.static SslConfiguratornewInstance(boolean readSystemProperties)Get a new SSL configurator instance.SslConfiguratorretrieve()Retrieve the SSL context configuration from the system properties.SslConfiguratorretrieve(Properties props)Retrieve the SSL context configuration from the supplied properties.SslConfiguratorsecurityProtocol(String protocol)Set the SSLContext protocol.SslConfiguratortrustManagerFactoryAlgorithm(String algorithm)Set the trust manager factory algorithm.SslConfiguratortrustManagerFactoryProvider(String provider)Set the trust manager factory provider.SslConfiguratortrustStore(KeyStore trustStore)Set the trust store instance.SslConfiguratortrustStoreBytes(byte[] payload)Set the trust store payload as byte array.SslConfiguratortrustStoreFile(String fileName)Set the trust store file name.SslConfiguratortrustStorePassword(String password)Set the password of trust store.SslConfiguratortrustStoreProvider(String trustStoreProvider)Set the trust store provider name.SslConfiguratortrustStoreType(String trustStoreType)Set the type of trust store.
-
-
-
Field Detail
-
TRUST_STORE_PROVIDER
public static final String TRUST_STORE_PROVIDER
Trust store provider name. The value MUST be aStringrepresenting 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 String KEY_STORE_PROVIDER
Key store provider name. The value MUST be aStringrepresenting 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 String TRUST_STORE_FILE
Trust store file name. The value MUST be aStringrepresenting 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 String KEY_STORE_FILE
Key store file name. The value MUST be aStringrepresenting 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 String TRUST_STORE_PASSWORD
Trust store file password - the password used to unlock the trust store file. The value MUST be aStringrepresenting 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 String KEY_STORE_PASSWORD
Key store file password - the password used to unlock the trust store file. The value MUST be aStringrepresenting 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 String TRUST_STORE_TYPE
Trust store type (seeKeyStore.getType()for more info). The value MUST be aStringrepresenting 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 String KEY_STORE_TYPE
Key store type (seeKeyStore.getType()for more info). The value MUST be aStringrepresenting 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 String KEY_MANAGER_FACTORY_ALGORITHM
Key manager factory algorithm name. The value MUST be aStringrepresenting 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 String KEY_MANAGER_FACTORY_PROVIDER
Key manager factory provider name. The value MUST be aStringrepresenting 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 String TRUST_MANAGER_FACTORY_ALGORITHM
Trust manager factory algorithm name. The value MUST be aStringrepresenting 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 String TRUST_MANAGER_FACTORY_PROVIDER
Trust manager factory provider name. The value MUST be aStringrepresenting 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
-
-
Method Detail
-
getDefaultContext
public static SSLContext getDefaultContext()
Get a new instance of aSSLContextconfigured 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 SSLContext getDefaultContext(boolean readSystemProperties)
Get a new instance of aSSLContextconfigured using default configuration settings. IfreadSystemPropertiesparameter 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 the instantiated configurator will be empty.- Returns:
- new & initialized SSL configurator instance.
-
newInstance
public static SslConfigurator newInstance(boolean readSystemProperties)
Get a new SSL configurator instance.- Parameters:
readSystemProperties- iftrue,Retrievesthe initial configuration fromSystem.getProperty(String)}, 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(String trustStoreProvider)
Set the trust store provider name.- Parameters:
trustStoreProvider- trust store provider to set.- Returns:
- updated SSL configurator instance.
-
keyStoreProvider
public SslConfigurator keyStoreProvider(String keyStoreProvider)
Set the key store provider name.- Parameters:
keyStoreProvider- key store provider to set.- Returns:
- updated SSL configurator instance.
-
trustStoreType
public SslConfigurator trustStoreType(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(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(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(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(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(String fileName)
Set the trust store file name.Setting a trust store instance resets any
trust store instanceortrust store payloadvalue previously set.- Parameters:
fileName-filename 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 fileortrust store instancevalue previously set.- Parameters:
payload- trust store payload.- Returns:
- updated SSL configurator instance.
-
keyStoreFile
public SslConfigurator keyStoreFile(String fileName)
Set the key store file name.Setting a key store instance resets any
key store instanceorkey store payloadvalue previously set.- Parameters:
fileName-filename 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 fileorkey store instancevalue previously set.- Parameters:
payload- key store payload.- Returns:
- updated SSL configurator instance.
-
trustManagerFactoryAlgorithm
public SslConfigurator trustManagerFactoryAlgorithm(String algorithm)
Set the trust manager factory algorithm.- Parameters:
algorithm- the trust manager factory algorithm.- Returns:
- updated SSL configurator instance.
-
keyManagerFactoryAlgorithm
public SslConfigurator keyManagerFactoryAlgorithm(String algorithm)
Set the key manager factory algorithm.- Parameters:
algorithm- the key manager factory algorithm.- Returns:
- updated SSL configurator instance.
-
trustManagerFactoryProvider
public SslConfigurator trustManagerFactoryProvider(String provider)
Set the trust manager factory provider.- Parameters:
provider- the trust manager factory provider.- Returns:
- updated SSL configurator instance.
-
keyManagerFactoryProvider
public SslConfigurator keyManagerFactoryProvider(String provider)
Set the key manager factory provider.- Parameters:
provider- the key manager factory provider.- Returns:
- updated SSL configurator instance.
-
securityProtocol
public SslConfigurator securityProtocol(String protocol)
Set the SSLContext protocol. The default value isTLSif this isnull.- Parameters:
protocol- protocol forSSLContext.getProtocol().- Returns:
- updated SSL configurator instance.
-
keyStore
public SslConfigurator keyStore(KeyStore keyStore)
Set the key store instance.Setting a key store instance resets any
key store fileorkey store payloadvalue previously set.- Parameters:
keyStore- key store instance.- Returns:
- updated SSL configurator instance.
-
trustStore
public SslConfigurator trustStore(KeyStore trustStore)
Set the trust store instance.- Parameters:
trustStore- trust store instance.- Returns:
- updated SSL configurator instance.
-
createSSLContext
public SSLContext createSSLContext()
Create new SSL context instance using the current SSL context configuration.- Returns:
- newly configured SSL context instance.
-
retrieve
public SslConfigurator retrieve(Properties props)
Retrieve the SSL context configuration from the supplied properties.- Parameters:
props- properties containing the SSL context configuration.- Returns:
- updated SSL configurator instance.
-
retrieve
public SslConfigurator retrieve()
Retrieve the SSL context configuration from the system properties.- Returns:
- updated SSL configurator instance.
-
-