Class SslConfigurator
- java.lang.Object
-
- org.glassfish.jersey.SslConfigurator
-
public final class SslConfigurator extends java.lang.ObjectUtility 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();
-
-
Field Summary
Fields Modifier and Type Field Description private static SslConfiguratorDEFAULT_CONFIG_NO_PROPSDefault SSL configuration that is used to create default SSL context instances that do not take into account system properties.static java.lang.StringKEY_MANAGER_FACTORY_ALGORITHMKey manager factory algorithm name.static java.lang.StringKEY_MANAGER_FACTORY_PROVIDERKey manager factory provider name.static java.lang.StringKEY_STORE_FILEKey store file name.static java.lang.StringKEY_STORE_PASSWORDKey store file password - the password used to unlock the trust store file.static java.lang.StringKEY_STORE_PROVIDERKey store provider name.static java.lang.StringKEY_STORE_TYPEKey store type (seeKeyStore.getType()for more info).private java.lang.StringkeyManagerFactoryAlgorithmprivate java.lang.StringkeyManagerFactoryProviderprivate char[]keyPassprivate java.security.KeyStorekeyStoreprivate byte[]keyStoreBytesprivate java.lang.StringkeyStoreFileprivate char[]keyStorePassprivate java.lang.StringkeyStoreProviderprivate java.lang.StringkeyStoreTypeprivate static java.util.logging.LoggerLOGGERLogger.private java.lang.StringsecurityProtocolstatic java.lang.StringTRUST_MANAGER_FACTORY_ALGORITHMTrust manager factory algorithm name.static java.lang.StringTRUST_MANAGER_FACTORY_PROVIDERTrust manager factory provider name.static java.lang.StringTRUST_STORE_FILETrust store file name.static java.lang.StringTRUST_STORE_PASSWORDTrust store file password - the password used to unlock the trust store file.static java.lang.StringTRUST_STORE_PROVIDERTrust store provider name.static java.lang.StringTRUST_STORE_TYPETrust store type (seeKeyStore.getType()for more info).private java.lang.StringtrustManagerFactoryAlgorithmprivate java.lang.StringtrustManagerFactoryProviderprivate java.security.KeyStoretrustStoreprivate byte[]trustStoreBytesprivate java.lang.StringtrustStoreFileprivate char[]trustStorePassprivate java.lang.StringtrustStoreProviderprivate java.lang.StringtrustStoreType
-
Constructor Summary
Constructors Modifier Constructor Description privateSslConfigurator(boolean readSystemProperties)privateSslConfigurator(SslConfigurator that)
-
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.javax.net.ssl.SSLContextcreateSSLContext()Create new SSL context instance using the current SSL context configuration.booleanequals(java.lang.Object o)static javax.net.ssl.SSLContextgetDefaultContext()Get a new instance of aSSLContextconfigured using default configuration settings.static javax.net.ssl.SSLContextgetDefaultContext(boolean readSystemProperties)Get a new instance of aSSLContextconfigured using default configuration settings.(package private) java.security.KeyStoregetKeyStore()Get the key store instance.(package private) java.security.KeyStoregetTrustStore()Get the trust store instance.inthashCode()SslConfiguratorkeyManagerFactoryAlgorithm(java.lang.String algorithm)Set the key manager factory algorithm.SslConfiguratorkeyManagerFactoryProvider(java.lang.String provider)Set the key manager factory provider.SslConfiguratorkeyPassword(char[] password)Set the password of the key in the key store.SslConfiguratorkeyPassword(java.lang.String password)Set the password of the key in the key store.SslConfiguratorkeyStore(java.security.KeyStore keyStore)Set the key store instance.SslConfiguratorkeyStoreBytes(byte[] payload)Set the key store payload as byte array.SslConfiguratorkeyStoreFile(java.lang.String fileName)Set the key store file name.SslConfiguratorkeyStorePassword(char[] password)Set the password of key store.SslConfiguratorkeyStorePassword(java.lang.String password)Set the password of key store.SslConfiguratorkeyStoreProvider(java.lang.String keyStoreProvider)Set the key store provider name.SslConfiguratorkeyStoreType(java.lang.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(java.util.Properties props)Retrieve the SSL context configuration from the supplied properties.SslConfiguratorsecurityProtocol(java.lang.String protocol)Set the SSLContext protocol.SslConfiguratortrustManagerFactoryAlgorithm(java.lang.String algorithm)Set the trust manager factory algorithm.SslConfiguratortrustManagerFactoryProvider(java.lang.String provider)Set the trust manager factory provider.SslConfiguratortrustStore(java.security.KeyStore trustStore)Set the trust store instance.SslConfiguratortrustStoreBytes(byte[] payload)Set the trust store payload as byte array.SslConfiguratortrustStoreFile(java.lang.String fileName)Set the trust store file name.SslConfiguratortrustStorePassword(java.lang.String password)Set the password of trust store.SslConfiguratortrustStoreProvider(java.lang.String trustStoreProvider)Set the trust store provider name.SslConfiguratortrustStoreType(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 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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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
-
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 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 javax.net.ssl.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 instanceretrievesthe 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,Retrievesthe 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 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(java.lang.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(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 isTLSif 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
nullif 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 fileorkey store payloadvalue 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 fileortrust store payloadvalue previously set.- Returns:
- trust store instance or
nullif 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-