Class SslEngineConfigurator

java.lang.Object
org.glassfish.tyrus.client.SslEngineConfigurator

public class SslEngineConfigurator extends 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 Details

    • sslContextConfiguration

      protected volatile SslContextConfigurator sslContextConfiguration
    • sslContext

      protected volatile SSLContext sslContext
    • enabledCipherSuites

      protected String[] enabledCipherSuites
      The list of cipher suites.
    • enabledProtocols

      protected 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 Details

    • SslEngineConfigurator

      public SslEngineConfigurator(SSLContext sslContext)
      Create SSL Engine configuration basing on passed SSLContext.
      Parameters:
      sslContext - SSLContext.
    • SslEngineConfigurator

      public SslEngineConfigurator(SSLContext sslContext, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)
      Create SSL Engine configuration based on passed SSLContext, 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 passed SslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on first createSSLEngine(String) call.
      Parameters:
      sslContextConfiguration - SslContextConfigurator.
    • SslEngineConfigurator

      public SslEngineConfigurator(SslContextConfigurator sslContextConfiguration, boolean clientMode, boolean needClientAuth, boolean wantClientAuth)
      Create SSL Engine configuration basing on passed SslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on first createSSLEngine(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 - original SslEngineConfigurator instance to be copied.
    • SslEngineConfigurator

      protected SslEngineConfigurator()
      Default constructor.
  • Method Details

    • createSSLEngine

      public SSLEngine createSSLEngine(String serverHost)
      Create and configure SSLEngine, 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 SSLEngine configure(SSLEngine sslEngine)
      Configure passed SSLEngine, using current configurator settings, excluding Hostname Verification.
      Parameters:
      sslEngine - SSLEngine to configure.
      Returns:
      configured SSLEngine.
    • isClientMode

      public boolean isClientMode()
      Will SSLEngine be configured to work in client mode.
      Returns:
      true, if SSLEngine will be configured to work in client mode, or false for server mode.
    • setClientMode

      public SslEngineConfigurator setClientMode(boolean clientMode)
      Set SSLEngine to be configured to work in client mode.
      Parameters:
      clientMode - true, if SSLEngine will be configured to work in client mode, or false for server 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 String[] getEnabledCipherSuites()
      Get enabled cipher suites.
      Returns:
      String array with enabled cipher suites.
    • setEnabledCipherSuites

      public SslEngineConfigurator setEnabledCipherSuites(String[] enabledCipherSuites)
      Set enabled cipher suites.
      Parameters:
      enabledCipherSuites - String array with cipher suites.
      Returns:
      updated SslEngineConfigurator.
    • getEnabledProtocols

      public String[] getEnabledProtocols()
      Get enabled protocols.
      Returns:
      String array with enabled protocols.
    • setEnabledProtocols

      public SslEngineConfigurator setEnabledProtocols(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 - when true, servers hostname will be verified using JDK default HostnameVerifier. When false, hostname verification won't be performed unless custom HostnameVerifier is set.
      Returns:
      updated SslEngineConfigurator.
      See Also:
    • getHostnameVerifier

      public HostnameVerifier getHostnameVerifier()
      Get custom hostname verifier.
      Returns:
      user provided hostname verifier instance.
    • setHostnameVerifier

      public SslEngineConfigurator setHostnameVerifier(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 (see isHostVerificationEnabled()) and JDK default hostname verifier won't be used.

      Parameters:
      hostnameVerifier - custom hostname verifier.
      Returns:
      updated SslEngineConfigurator.
    • getSslContext

      public SSLContext getSslContext()
      Create SSLContext and store it for further invocation of this method.
      Returns:
      created ssl context.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      public SslEngineConfigurator copy()