Package org.glassfish.tyrus.client
Class SslEngineConfigurator
- java.lang.Object
-
- org.glassfish.tyrus.client.SslEngineConfigurator
-
public class SslEngineConfigurator extends java.lang.ObjectSSLEngineConfigurator class from Grizzly project.Utility class, which helps to configure
SSLEngine. Should 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
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanclientModeClient mode when handshaking.protected java.lang.String[]enabledCipherSuitesThe list of cipher suites.protected java.lang.String[]enabledProtocolsThe list of protocols.protected booleanneedClientAuthRequire client Authentication.protected javax.net.ssl.SSLContextsslContextprotected SslContextConfiguratorsslContextConfigurationprotected booleanwantClientAuthTrue when requesting authentication.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSslEngineConfigurator()Default constructor.SslEngineConfigurator(javax.net.ssl.SSLContext sslContext)Create SSL Engine configuration basing on passedSSLContext.SslEngineConfigurator(javax.net.ssl.SSLContext sslContext, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)Create SSL Engine configuration based on passedSSLContext, using passed client mode, need/want client auth parameters.SslEngineConfigurator(SslContextConfigurator sslContextConfiguration)Create SSL Engine configuration based on passedSslContextConfigurator.SslEngineConfigurator(SslContextConfigurator sslContextConfiguration, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)Create SSL Engine configuration basing on passedSslContextConfigurator.SslEngineConfigurator(SslEngineConfigurator original)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.net.ssl.SSLEngineconfigure(javax.net.ssl.SSLEngine sslEngine)Configure passedSSLEngine, using current configurator settings, excluding Hostname Verification.SslEngineConfiguratorcopy()javax.net.ssl.SSLEnginecreateSSLEngine(java.lang.String serverHost)Create and configureSSLEngine, based on current settings.java.lang.String[]getEnabledCipherSuites()Get enabled cipher suites.java.lang.String[]getEnabledProtocols()Get enabled protocols.javax.net.ssl.HostnameVerifiergetHostnameVerifier()Get custom hostname verifier.javax.net.ssl.SSLContextgetSslContext()CreateSSLContextand store it for further invocation of this method.booleanisCipherConfigured()booleanisClientMode()WillSSLEnginebe configured to work in client mode.booleanisHostVerificationEnabled()Get the hostname verification state.booleanisNeedClientAuth()Get "need client auth" property.booleanisProtocolConfigured()booleanisWantClientAuth()Get "want client auth" property.SslEngineConfiguratorsetCipherConfigured(boolean isCipherConfigured)SslEngineConfiguratorsetClientMode(boolean clientMode)SetSSLEngineto be configured to work in client mode.SslEngineConfiguratorsetEnabledCipherSuites(java.lang.String[] enabledCipherSuites)Set enabled cipher suites.SslEngineConfiguratorsetEnabledProtocols(java.lang.String[] enabledProtocols)Set enabled protocols.SslEngineConfiguratorsetHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)Set custom hostname verifier.SslEngineConfiguratorsetHostVerificationEnabled(boolean hostVerificationEnabled)Set hostname verification.SslEngineConfiguratorsetNeedClientAuth(boolean needClientAuth)Set "need client auth" property.SslEngineConfiguratorsetProtocolConfigured(boolean isProtocolConfigured)SslEngineConfiguratorsetWantClientAuth(boolean wantClientAuth)Set "want client auth" property.java.lang.StringtoString()
-
-
-
Field Detail
-
sslContextConfiguration
protected volatile SslContextConfigurator sslContextConfiguration
-
sslContext
protected volatile javax.net.ssl.SSLContext sslContext
-
enabledCipherSuites
protected java.lang.String[] enabledCipherSuites
The list of cipher suites.
-
enabledProtocols
protected java.lang.String[] enabledProtocols
The list of protocols.
-
clientMode
protected boolean clientMode
Client mode when handshaking.
-
needClientAuth
protected boolean needClientAuth
Require client Authentication.
-
wantClientAuth
protected boolean wantClientAuth
True when requesting authentication.
-
-
Constructor Detail
-
SslEngineConfigurator
public SslEngineConfigurator(javax.net.ssl.SSLContext sslContext)
Create SSL Engine configuration basing on passedSSLContext.- Parameters:
sslContext-SSLContext.
-
SslEngineConfigurator
public SslEngineConfigurator(javax.net.ssl.SSLContext sslContext, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)Create SSL Engine configuration based on passedSSLContext, using passed client mode, need/want client auth parameters.- Parameters:
sslContext-SSLContext.clientMode- will be configured to work in client mode.needClientAuth- client authentication is required.wantClientAuth- client should authenticate.
-
SslEngineConfigurator
public SslEngineConfigurator(SslContextConfigurator sslContextConfiguration)
Create SSL Engine configuration based on passedSslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on firstcreateSSLEngine(String)call.- Parameters:
sslContextConfiguration-SslContextConfigurator.
-
SslEngineConfigurator
public SslEngineConfigurator(SslContextConfigurator sslContextConfiguration, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)
Create SSL Engine configuration basing on passedSslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on firstcreateSSLEngine(String)call.- Parameters:
sslContextConfiguration-SslContextConfigurator.clientMode- will be configured to work in client mode.needClientAuth- client authentication is required.wantClientAuth- client should authenticate.
-
SslEngineConfigurator
public SslEngineConfigurator(SslEngineConfigurator original)
Copy constructor.- Parameters:
original- originalSslEngineConfiguratorinstance to be copied.
-
SslEngineConfigurator
protected SslEngineConfigurator()
Default constructor.
-
-
Method Detail
-
createSSLEngine
public javax.net.ssl.SSLEngine createSSLEngine(java.lang.String serverHost)
Create and configureSSLEngine, based on current settings.- Parameters:
serverHost- server host, which will be used to verify authenticity of the server (the provided host name will compared to the host in the certificate provided by the server).- Returns:
SSLEngine.
-
configure
public javax.net.ssl.SSLEngine configure(javax.net.ssl.SSLEngine sslEngine)
Configure passedSSLEngine, using current configurator settings, excluding Hostname Verification.- Parameters:
sslEngine-SSLEngineto configure.- Returns:
- configured
SSLEngine.
-
isClientMode
public boolean isClientMode()
WillSSLEnginebe configured to work in client mode.- Returns:
true, ifSSLEnginewill be configured to work inclientmode, orfalseforservermode.
-
setClientMode
public SslEngineConfigurator setClientMode(boolean clientMode)
SetSSLEngineto be configured to work in client mode.- Parameters:
clientMode-true, ifSSLEnginewill be configured to work inclientmode, orfalseforservermode.- Returns:
- updated
SslEngineConfigurator.
-
isNeedClientAuth
public boolean isNeedClientAuth()
Get "need client auth" property.- Returns:
- need client auth property value;
-
setNeedClientAuth
public SslEngineConfigurator setNeedClientAuth(boolean needClientAuth)
Set "need client auth" property.- Parameters:
needClientAuth- value to be set.- Returns:
- updated
SslEngineConfigurator.
-
isWantClientAuth
public boolean isWantClientAuth()
Get "want client auth" property.- Returns:
- need client auth property value;
-
setWantClientAuth
public SslEngineConfigurator setWantClientAuth(boolean wantClientAuth)
Set "want client auth" property.- Parameters:
wantClientAuth- value to be set.- Returns:
- updated
SslEngineConfigurator.
-
getEnabledCipherSuites
public java.lang.String[] getEnabledCipherSuites()
Get enabled cipher suites.- Returns:
Stringarray with enabled cipher suites.
-
setEnabledCipherSuites
public SslEngineConfigurator setEnabledCipherSuites(java.lang.String[] enabledCipherSuites)
Set enabled cipher suites.- Parameters:
enabledCipherSuites-Stringarray with cipher suites.- Returns:
- updated
SslEngineConfigurator.
-
getEnabledProtocols
public java.lang.String[] getEnabledProtocols()
Get enabled protocols.- Returns:
Stringarray with enabled protocols.
-
setEnabledProtocols
public SslEngineConfigurator setEnabledProtocols(java.lang.String[] enabledProtocols)
Set enabled protocols.- Parameters:
enabledProtocols-Stringarray with protocols.- Returns:
- updated
SslEngineConfigurator.
-
isCipherConfigured
public boolean isCipherConfigured()
-
setCipherConfigured
public SslEngineConfigurator setCipherConfigured(boolean isCipherConfigured)
-
isProtocolConfigured
public boolean isProtocolConfigured()
-
setProtocolConfigured
public SslEngineConfigurator setProtocolConfigured(boolean isProtocolConfigured)
-
isHostVerificationEnabled
public boolean isHostVerificationEnabled()
Get the hostname verification state.- Returns:
trueif the hostname verification is enabled,falseotherwise.
-
setHostVerificationEnabled
public SslEngineConfigurator setHostVerificationEnabled(boolean hostVerificationEnabled)
Set hostname verification.- Parameters:
hostVerificationEnabled- whentrue, servers hostname will be verified using JDK defaultHostnameVerifier. Whenfalse, hostname verification won't be performed unless customHostnameVerifieris set.- Returns:
- updated
SslEngineConfigurator. - See Also:
setHostnameVerifier(HostnameVerifier)
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
Get custom hostname verifier.- Returns:
- user provided hostname verifier instance.
-
setHostnameVerifier
public SslEngineConfigurator setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Set custom hostname verifier.When custom
HostnameVerifierinstance is registered, it will be used to perform hostname verification, no matter on the state of hostname verification flag (seeisHostVerificationEnabled()) and JDK default hostname verifier won't be used.- Parameters:
hostnameVerifier- custom hostname verifier.- Returns:
- updated
SslEngineConfigurator.
-
getSslContext
public javax.net.ssl.SSLContext getSslContext()
CreateSSLContextand store it for further invocation of this method.- Returns:
- created ssl context.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
copy
public SslEngineConfigurator copy()
-
-