Package org.glassfish.tyrus.client
Class SslEngineConfigurator
- java.lang.Object
-
- org.glassfish.tyrus.client.SslEngineConfigurator
-
public class SslEngineConfigurator extends java.lang.Object
SSLEngineConfigurator 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 boolean
clientMode
Client mode when handshaking.protected java.lang.String[]
enabledCipherSuites
The list of cipher suites.protected java.lang.String[]
enabledProtocols
The list of protocols.protected boolean
needClientAuth
Require client Authentication.protected javax.net.ssl.SSLContext
sslContext
protected SslContextConfigurator
sslContextConfiguration
protected boolean
wantClientAuth
True when requesting authentication.
-
Constructor Summary
Constructors Modifier Constructor Description protected
SslEngineConfigurator()
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.SSLEngine
configure(javax.net.ssl.SSLEngine sslEngine)
Configure passedSSLEngine
, using current configurator settings, excluding Hostname Verification.SslEngineConfigurator
copy()
javax.net.ssl.SSLEngine
createSSLEngine(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.HostnameVerifier
getHostnameVerifier()
Get custom hostname verifier.javax.net.ssl.SSLContext
getSslContext()
CreateSSLContext
and store it for further invocation of this method.boolean
isCipherConfigured()
boolean
isClientMode()
WillSSLEngine
be configured to work in client mode.boolean
isHostVerificationEnabled()
Get the hostname verification state.boolean
isNeedClientAuth()
Get "need client auth" property.boolean
isProtocolConfigured()
boolean
isWantClientAuth()
Get "want client auth" property.SslEngineConfigurator
setCipherConfigured(boolean isCipherConfigured)
SslEngineConfigurator
setClientMode(boolean clientMode)
SetSSLEngine
to be configured to work in client mode.SslEngineConfigurator
setEnabledCipherSuites(java.lang.String[] enabledCipherSuites)
Set enabled cipher suites.SslEngineConfigurator
setEnabledProtocols(java.lang.String[] enabledProtocols)
Set enabled protocols.SslEngineConfigurator
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Set custom hostname verifier.SslEngineConfigurator
setHostVerificationEnabled(boolean hostVerificationEnabled)
Set hostname verification.SslEngineConfigurator
setNeedClientAuth(boolean needClientAuth)
Set "need client auth" property.SslEngineConfigurator
setProtocolConfigured(boolean isProtocolConfigured)
SslEngineConfigurator
setWantClientAuth(boolean wantClientAuth)
Set "want client auth" property.java.lang.String
toString()
-
-
-
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
- originalSslEngineConfigurator
instance 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
-SSLEngine
to configure.- Returns:
- configured
SSLEngine
.
-
isClientMode
public boolean isClientMode()
WillSSLEngine
be configured to work in client mode.- Returns:
true
, ifSSLEngine
will be configured to work inclient
mode, orfalse
forserver
mode.
-
setClientMode
public SslEngineConfigurator setClientMode(boolean clientMode)
SetSSLEngine
to be configured to work in client mode.- Parameters:
clientMode
-true
, ifSSLEngine
will be configured to work inclient
mode, orfalse
forserver
mode.- 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:
String
array with enabled cipher suites.
-
setEnabledCipherSuites
public SslEngineConfigurator setEnabledCipherSuites(java.lang.String[] enabledCipherSuites)
Set enabled cipher suites.- Parameters:
enabledCipherSuites
-String
array with cipher suites.- Returns:
- updated
SslEngineConfigurator
.
-
getEnabledProtocols
public java.lang.String[] getEnabledProtocols()
Get enabled protocols.- Returns:
String
array with enabled protocols.
-
setEnabledProtocols
public SslEngineConfigurator setEnabledProtocols(java.lang.String[] enabledProtocols)
Set enabled protocols.- Parameters:
enabledProtocols
-String
array 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:
true
if the hostname verification is enabled,false
otherwise.
-
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 customHostnameVerifier
is 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
HostnameVerifier
instance 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()
CreateSSLContext
and store it for further invocation of this method.- Returns:
- created ssl context.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
copy
public SslEngineConfigurator copy()
-
-