[grizzly~git:3340dd22] [2.3.x] update SNI API

  • From: oleksiys@...
  • To: commits@...
  • Subject: [grizzly~git:3340dd22] [2.3.x] update SNI API
  • Date: Thu, 20 Mar 2014 01:36:33 +0000

Project:    grizzly
Repository: git
Revision:   3340dd22114a01c5331bf42b6a6483597b9c4950
Author:     oleksiys
Date:       2014-03-20 01:36:16 UTC
Link:       

Log Message:
------------
[2.3.x] update SNI API


Revisions:
----------
3340dd22114a01c5331bf42b6a6483597b9c4950


Modified Paths:
---------------
extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIConfig.java
extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java
extras/tls-sni/src/test/java/org/glassfish/grizzly/sni/SNITest.java


Diffs:
------
--- a/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIConfig.java
+++ b/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIConfig.java
@@ -55,17 +55,34 @@ public class SNIConfig {
     final boolean isClientConfig;
 
     /**
-     * @return server-side SNI configuration builder
+     * @param sslEngineConfigurator {@link SSLEngineConfigurator},
+     *          or <tt>null</tt> for the default configuration
+     * @return server-side SNI configuration
      */
-    public static SNIServerConfigBuilder serverConfigBuilder() {
-        return new SNIServerConfigBuilder();
+    public static SNIConfig newServerConfig(
+        final SSLEngineConfigurator sslEngineConfigurator) {
+        return new SNIConfig(sslEngineConfigurator, null, false);
     }
-
+    
     /**
-     * @return client-side SNI configuration builder
+     * @param host the SNI host name to be sent to a server, or <tt>null</tt>
+     *          to not use SNI extension
+     * @return client-side SNI configuration
      */
-    public static SNIClientConfigBuilder clientConfigBuilder() {
-        return new SNIClientConfigBuilder();
+    public static SNIConfig newClientConfig(final String host) {
+        return new SNIConfig(null, host, true);
+    }
+    
+    /**
+     * @param host the SNI host name to be sent to a server, or <tt>null</tt>
+     *          to not use SNI extension
+     * @param sslEngineConfigurator {@link SSLEngineConfigurator},
+     *          or <tt>null</tt> for the default configuration
+     * @return client-side SNI configuration
+     */
+    public static SNIConfig newClientConfig(final String host,
+        final SSLEngineConfigurator sslEngineConfigurator) {
+        return new SNIConfig(sslEngineConfigurator, host, true);
     }
 
     private SNIConfig(final SSLEngineConfigurator engineConfig,
@@ -74,51 +91,4 @@ public class SNIConfig {
         this.host = host;
         this.isClientConfig = isClientConfig;
     }
-
-
-    public static class SNIServerConfigBuilder {
-        private SSLEngineConfigurator sslEngineConfigurator;
-
-        public SNIServerConfigBuilder sslEngineConfigurator(
-                final SSLEngineConfigurator config) {
-            this.sslEngineConfigurator = config;
-            return this;
-        }
-        
-        public SNIConfig build() {
-            if (sslEngineConfigurator == null) {
-                throw new IllegalStateException("SNIConfig has to have 
non-null SSLEngineConfigurator");
-            }
-            
-            return new SNIConfig(sslEngineConfigurator, null, false);
-        }
-    }
-
-    public static class SNIClientConfigBuilder {
-        private SSLEngineConfigurator sslEngineConfigurator;
-        private String host;
-        
-        public SNIClientConfigBuilder sslEngineConfigurator(
-                final SSLEngineConfigurator config) {
-            this.sslEngineConfigurator = config;
-            return this;
-        }
-        
-        public SNIClientConfigBuilder host(final String host) {
-            this.host = host;
-            return this;
-        }
-        
-        public SNIConfig build() {
-            if (sslEngineConfigurator == null) {
-                throw new IllegalStateException("SNIConfig has to have 
non-null SSLEngineConfigurator");
-            }
-            
-            if (host == null) {
-                throw new IllegalStateException("SNIConfig has to have 
non-null host");
-            }
-
-            return new SNIConfig(sslEngineConfigurator, host, true);
-        }
-    }    
 }--- a/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java
+++ b/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java
@@ -188,14 +188,12 @@ public class SNIFilter extends SSLFilter {
             if (sniConfig != null && !sniConfig.isClientConfig) {
                 throw new IllegalStateException("SNIConfig has to represent 
client config, not a server one");
             }
+
+            host = sniConfig != null ? sniConfig.host : null;
+            configurator = sniConfig != null && 
sniConfig.sslEngineConfigurator != null ?
+                    sniConfig.sslEngineConfigurator :
+                    getClientSSLEngineConfigurator();
             
-            if (sniConfig != null) {
-                host = sniConfig.host;
-                configurator = sniConfig.sslEngineConfigurator;
-            } else {
-                host = null;
-                configurator = getClientSSLEngineConfigurator();
-            }
         } else {
             // if resolver is not set - try to set default SNI host, based
             // on Connection's peer address
@@ -274,7 +272,7 @@ public class SNIFilter extends SSLFilter {
                 }
                 
                 final SSLEngineConfigurator configurator =
-                        sniConfig != null ?
+                        sniConfig != null && sniConfig.sslEngineConfigurator 
!= null ?
                         sniConfig.sslEngineConfigurator :
                         getServerSSLEngineConfigurator();
                 --- 
a/extras/tls-sni/src/test/java/org/glassfish/grizzly/sni/SNITest.java
+++ b/extras/tls-sni/src/test/java/org/glassfish/grizzly/sni/SNITest.java
@@ -103,9 +103,7 @@ public class SNITest {
             public SNIConfig resolve(Connection connection, String hostname) 
{
                 sniHostAttr.set(connection, hostname);
                 
-                return SNIConfig.serverConfigBuilder()
-                        .sslEngineConfigurator(sslServerEngineConfig)
-                        .build();
+                return SNIConfig.newServerConfig(sslServerEngineConfig);
             }
         });
         
@@ -113,10 +111,8 @@ public class SNITest {
 
             @Override
             public SNIConfig resolve(Connection connection) {
-                return SNIConfig.clientConfigBuilder()
-                        .sslEngineConfigurator(sslClientEngineConfig)
-                        .host(sniHostValue)
-                        .build();
+                return SNIConfig.newClientConfig(sniHostValue,
+                        sslClientEngineConfig);
             }
         });
 





[grizzly~git:3340dd22] [2.3.x] update SNI API

oleksiys 03/20/2014
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150626.29986a4)
 
 
Close
loading
Please Confirm
Close