You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/04/10 19:41:11 UTC

[2/9] tinkerpop git commit: Change abstraction to include WebSocketChannelizer

Change abstraction to include WebSocketChannelizer

Changed the abstraction so it applies to both the WebSocketChannelizer
and the HttpChannelizer. Also, renamed the configuration and tried to
make it more clear from the method signatures that the handlerClassName
config goes in Settings.AuthenticationSettings rather than the Settings
root.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/eae4101c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/eae4101c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/eae4101c

Branch: refs/heads/master
Commit: eae4101c5fb7b8b976c5898a12e180ee23e50269
Parents: 69dd924
Author: Keith Lohnes <kr...@us.ibm.com>
Authored: Mon Mar 27 10:46:04 2017 -0400
Committer: Keith Lohnes <kr...@us.ibm.com>
Committed: Tue Apr 4 09:37:28 2017 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/server/Settings.java |  4 ++--
 .../gremlin/server/channel/HttpChannelizer.java   | 12 ++----------
 .../server/channel/WebSocketChannelizer.java      | 18 +++++++++++++++---
 .../server/handler/SaslAuthenticationHandler.java |  6 ++----
 4 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eae4101c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
index 030c2e6..66c7b56 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
@@ -384,7 +384,7 @@ public class Settings {
          * used to load the implementation from the classpath. Defaults to {@link AllowAllAuthenticator} when
          * not specified.
          */
-        public String authenticator = AllowAllAuthenticator.class.getName();
+        public String authenticator = null;
 
         /**
          * The fully qualified class name of the {@link Authenticator} implementation. This class name will be
@@ -396,7 +396,7 @@ public class Settings {
         public String className = AllowAllAuthenticator.class.getName();
 
         /**
-         * The fully qualified class name of the {@link HttpAuthenticationHandler} implementation.
+         * The fully qualified class name of the {@link AbstractAuthenticationHandler} implementation.
          * This class name will be used to load the implementation from the classpath.
          * Defaults to null when not specified.
          */

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eae4101c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/HttpChannelizer.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/HttpChannelizer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/HttpChannelizer.java
index eca52a0..8884b62 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/HttpChannelizer.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/HttpChannelizer.java
@@ -71,7 +71,7 @@ public class HttpChannelizer extends AbstractChannelizer {
             // not occur. It may not be a safe assumption that the handler
             // is sharable so create a new handler each time.
             authenticationHandler = authenticator.getClass() == AllowAllAuthenticator.class ?
-                    null : createAuthenticationHandler(settings);
+                    null : instantiateAuthenticationHandler(settings.authentication);
             if (authenticationHandler != null)
                 pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
         }
@@ -85,15 +85,7 @@ public class HttpChannelizer extends AbstractChannelizer {
             //Keep things backwards compatible
             return new HttpBasicAuthenticationHandler(authenticator);
         } else {
-            try {
-                final Class<?> clazz = Class.forName(handlerClassName);
-                final Class[] constructorArgs = new Class[1];
-                constructorArgs[0] = Authenticator.class;
-                return (HttpAuthenticationHandler) clazz.getDeclaredConstructor(constructorArgs).newInstance(authenticator);
-            } catch (Exception ex) {
-                logger.warn(ex.getMessage());
-                throw new IllegalStateException(String.format("Could not create/configure HttpAuthenticationHandler %s", handlerClassName), ex);
-            }
+            return createAuthenticationHandler(authSettings);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eae4101c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
index 2373819..1b613a1 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.server.channel;
 import io.netty.channel.EventLoopGroup;
 import org.apache.tinkerpop.gremlin.server.AbstractChannelizer;
 import org.apache.tinkerpop.gremlin.server.auth.AllowAllAuthenticator;
+import org.apache.tinkerpop.gremlin.server.handler.AbstractAuthenticationHandler;
+import org.apache.tinkerpop.gremlin.server.Settings;
 import org.apache.tinkerpop.gremlin.server.handler.SaslAuthenticationHandler;
 import org.apache.tinkerpop.gremlin.server.handler.WsGremlinBinaryRequestDecoder;
 import org.apache.tinkerpop.gremlin.server.handler.WsGremlinCloseRequestDecoder;
@@ -52,7 +54,7 @@ public class WebSocketChannelizer extends AbstractChannelizer {
     private WsGremlinBinaryRequestDecoder wsGremlinBinaryRequestDecoder;
     private WsGremlinResponseFrameEncoder wsGremlinResponseFrameEncoder;
     private WsGremlinCloseRequestDecoder wsGremlinCloseRequestDecoder;
-    private SaslAuthenticationHandler authenticationHandler;
+    private AbstractAuthenticationHandler authenticationHandler;
 
     @Override
     public void init(final ServerGremlinExecutor<EventLoopGroup> serverGremlinExecutor) {
@@ -67,7 +69,7 @@ public class WebSocketChannelizer extends AbstractChannelizer {
         // configure authentication - null means don't bother to add authentication to the pipeline
         if (authenticator != null)
             authenticationHandler = authenticator.getClass() == AllowAllAuthenticator.class ?
-                    null : new SaslAuthenticationHandler(authenticator);
+                    null : instantiateAuthenticationHandler(settings.authentication);
     }
 
     @Override
@@ -109,4 +111,14 @@ public class WebSocketChannelizer extends AbstractChannelizer {
         if (authenticationHandler != null)
             pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
     }
-}
\ No newline at end of file
+
+    private AbstractAuthenticationHandler instantiateAuthenticationHandler(final Settings.AuthenticationSettings authSettings) {
+        final String authenticationHandler = authSettings.authenticationHandler;
+        if (authenticationHandler == null) {
+            //Keep things backwards compatible
+            return new SaslAuthenticationHandler(authenticator);
+        } else {
+            return createAuthenticationHandler(authSettings);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eae4101c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
index 6cb0ddb..66bffad 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/SaslAuthenticationHandler.java
@@ -51,15 +51,13 @@ import org.slf4j.LoggerFactory;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 @ChannelHandler.Sharable
-public class SaslAuthenticationHandler extends ChannelInboundHandlerAdapter {
+public class SaslAuthenticationHandler extends AbstractAuthenticationHandler {
     private static final Logger logger = LoggerFactory.getLogger(SaslAuthenticationHandler.class);
     private static final Base64.Decoder BASE64_DECODER = Base64.getDecoder();
     private static final Base64.Encoder BASE64_ENCODER = Base64.getEncoder();
 
-    private final Authenticator authenticator;
-
     public SaslAuthenticationHandler(final Authenticator authenticator) {
-        this.authenticator = authenticator;
+        super(authenticator);
     }
 
     @Override