You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by pl...@apache.org on 2015/10/06 16:44:21 UTC
incubator-tinkerpop git commit: TINKERPOP3-865 Fix errors in HTTP
REST Basic Auth
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/TINKERPOP3-865 [created] 7571d907c
TINKERPOP3-865 Fix errors in HTTP REST Basic Auth
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7571d907
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7571d907
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7571d907
Branch: refs/heads/TINKERPOP3-865
Commit: 7571d907c1e7aacdb1687063bc4e7745d785c1da
Parents: cbf45ca
Author: Jason Plurad <pl...@apache.org>
Authored: Tue Oct 6 10:43:31 2015 -0400
Committer: Jason Plurad <pl...@apache.org>
Committed: Tue Oct 6 10:43:31 2015 -0400
----------------------------------------------------------------------
.../gremlin/server/channel/HttpChannelizer.java | 10 ++++++++--
.../handler/HttpBasicAuthenticationHandler.java | 21 ++++++++++++--------
2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7571d907/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 d0a88e5..6b788c2 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
@@ -67,8 +67,14 @@ public class HttpChannelizer extends AbstractChannelizer {
pipeline.addLast(new HttpObjectAggregator(settings.maxContentLength));
- if (authenticationHandler != null)
- pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
+ if (authenticator != null) {
+ // cannot add same handler multiple times unless it is marked as @Sharable
+ // but we can't assume that a customer's Authenticator is sharable
+ authenticationHandler = authenticator.getClass() == AllowAllAuthenticator.class ?
+ null : new HttpBasicAuthenticationHandler(authenticator);
+ if (authenticationHandler != null)
+ pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
+ }
pipeline.addLast("http-gremlin-handler", httpGremlinEndpointHandler);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7571d907/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java
index d9d3c1e..c2f7b5a 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.server.handler;
+import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
@@ -51,21 +52,20 @@ public class HttpBasicAuthenticationHandler extends ChannelInboundHandlerAdapter
}
@Override
- public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
+ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
if (msg instanceof FullHttpMessage) {
final FullHttpMessage request = (FullHttpMessage) msg;
if (!request.headers().contains("Authorization")) {
- ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED));
- ReferenceCountUtil.release(msg);
+ sendError(ctx, msg);
return;
}
- final String authorizationHeader = request.headers().get("Authorization");
+ // strip off "Basic " from the Authorization header
+ final String authorizationHeader = request.headers().get("Authorization").substring(6);
final String authorization = new String(decoder.decode(authorizationHeader), Charset.forName("UTF-8"));
final String[] split = authorization.split(":");
if (split.length != 2) {
- ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED));
- ReferenceCountUtil.release(msg);
+ sendError(ctx, msg);
return;
}
@@ -77,9 +77,14 @@ public class HttpBasicAuthenticationHandler extends ChannelInboundHandlerAdapter
authenticator.authenticate(credentials);
ctx.fireChannelRead(request);
} catch (AuthenticationException ae) {
- ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED));
- ReferenceCountUtil.release(msg);
+ sendError(ctx, msg);
}
}
}
+
+ private void sendError(final ChannelHandlerContext ctx, final Object msg) {
+ // Close the connection as soon as the error message is sent.
+ ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED));//.addListener(ChannelFutureListener.CLOSE);
+ ReferenceCountUtil.release(msg);
+ }
}