Search in sources :

Example 1 with Authenticator

use of org.apache.tinkerpop.gremlin.server.auth.Authenticator in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadBasicAuthIncorrectScheme.

@Test
public void testChannelReadBasicAuthIncorrectScheme() {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final ChannelFuture cf = createMock(ChannelFuture.class);
    expect(msg.getMethod()).andReturn(HttpMethod.POST);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(headers.get("Authorization")).andReturn("bogus");
    expect(ctx.writeAndFlush(eqHttpStatus(UNAUTHORIZED))).andReturn(cf);
    expect(cf.addListener(ChannelFutureListener.CLOSE)).andReturn(null);
    expect(msg.release()).andReturn(false);
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 2 with Authenticator

use of org.apache.tinkerpop.gremlin.server.auth.Authenticator in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadBasicAuth.

@Test
public void testChannelReadBasicAuth() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final String encodedUserNameAndPass = Base64.getEncoder().encodeToString("user:pass".getBytes());
    expect(msg.getMethod()).andReturn(HttpMethod.POST);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/");
    expect(headers.get(eq("Authorization"))).andReturn("Basic " + encodedUserNameAndPass);
    expect(ctx.fireChannelRead(isA(FullHttpRequest.class))).andReturn(ctx);
    expect(authenticator.authenticate(isA(Map.class))).andReturn(new AuthenticatedUser("foo"));
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 3 with Authenticator

use of org.apache.tinkerpop.gremlin.server.auth.Authenticator in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadTokenAuth.

@Test
public void testChannelReadTokenAuth() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final String encodedToken = Base64.getEncoder().encodeToString("askdjhf823asdlkfsasd".getBytes());
    expect(msg.getMethod()).andReturn(HttpMethod.GET);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/");
    expect(headers.get(eq("Authorization"))).andReturn("Token " + encodedToken);
    expect(ctx.fireChannelRead(isA(FullHttpRequest.class))).andReturn(ctx);
    expect(authenticator.authenticate(isA(Map.class))).andReturn(new AuthenticatedUser("foo"));
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 4 with Authenticator

use of org.apache.tinkerpop.gremlin.server.auth.Authenticator in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadGetAuthToken.

@Test
public void testChannelReadGetAuthToken() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final ChannelFuture cf = createMock(ChannelFuture.class);
    final String encodedUserNameAndPass = Base64.getEncoder().encodeToString("user:pass".getBytes());
    final Capture<Map<String, String>> credMap = EasyMock.newCapture(CaptureType.ALL);
    expect(msg.getMethod()).andReturn(HttpMethod.GET);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/session");
    expect(headers.get(eq("Authorization"))).andReturn("Basic " + encodedUserNameAndPass);
    expect(authenticator.authenticate(and(isA(Map.class), capture(credMap)))).andReturn(new AuthenticatedUser("foo"));
    expect(ctx.writeAndFlush(eqHttpStatus(OK))).andReturn(cf);
    expect(cf.addListener(ChannelFutureListener.CLOSE)).andReturn(null);
    expect(msg.release()).andReturn(false);
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
    assertNotNull(credMap.getValue().get(HttpHMACAuthenticationHandler.PROPERTY_GENERATE_TOKEN));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 5 with Authenticator

use of org.apache.tinkerpop.gremlin.server.auth.Authenticator in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadBasicAuthNoAuthHeader.

@Test
public void testChannelReadBasicAuthNoAuthHeader() {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final ChannelFuture cf = createMock(ChannelFuture.class);
    expect(msg.getMethod()).andReturn(HttpMethod.POST);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(headers.get(eq("Authorization"))).andReturn(null);
    expect(ctx.writeAndFlush(eqHttpStatus(UNAUTHORIZED))).andReturn(cf);
    expect(cf.addListener(ChannelFutureListener.CLOSE)).andReturn(null);
    expect(msg.release()).andReturn(false);
    HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)5 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)5 Authenticator (org.apache.tinkerpop.gremlin.server.auth.Authenticator)5 Test (org.junit.Test)5 ChannelFuture (io.netty.channel.ChannelFuture)3 Map (java.util.Map)3 AuthenticatedUser (org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser)3