Skip to content

Commit

Permalink
Made AuthManager available to Bolt
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Feb 21, 2016
1 parent 85a29bf commit 4cea1e9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.neo4j.kernel.lifecycle.Lifecycle;
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.logging.Log;
import org.neo4j.server.security.auth.AuthManager;
import org.neo4j.udc.UsageData;

import static org.neo4j.bolt.BoltKernelExtension.EncryptionLevel.OPTIONAL;
Expand Down Expand Up @@ -169,6 +170,8 @@ public interface Dependencies
UsageData usageData();

Monitors monitors();

AuthManager authManager();
}

public BoltKernelExtension()
Expand Down Expand Up @@ -225,7 +228,7 @@ public Lifecycle newInstance( KernelContext context, Dependencies dependencies )

connectors.add( new SocketTransport( socketAddress, sslCtx, logging.getInternalLogProvider(),
newVersions( logging,
requireEncryption ? new EncryptionRequiredSessions( sessions ) : sessions ) ) );
requireEncryption ? new EncryptionRequiredSessions( sessions ) : sessions, dependencies.authManager() ) ) );
}
}

Expand All @@ -239,12 +242,12 @@ public Lifecycle newInstance( KernelContext context, Dependencies dependencies )
}

private PrimitiveLongObjectMap<BiFunction<Channel,Boolean,BoltProtocol>> newVersions( LogService logging,
Sessions sessions )
Sessions sessions, AuthManager authManager )
{
PrimitiveLongObjectMap<BiFunction<Channel,Boolean,BoltProtocol>> availableVersions = longObjectMap();
availableVersions.put(
BoltProtocolV1.VERSION,
( channel, isEncrypted ) -> new BoltProtocolV1( logging, sessions.newSession( isEncrypted ), channel )
( channel, isEncrypted ) -> new BoltProtocolV1( logging, sessions.newSession( isEncrypted ), channel, authManager )
);
return availableVersions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.bolt.v1.runtime.StatementMetadata;
import org.neo4j.bolt.v1.runtime.spi.RecordStream;
import org.neo4j.logging.Log;
import org.neo4j.server.security.auth.AuthManager;

/** Bridges the gap between incoming deserialized messages, the user environment and back. */
public class TransportBridge extends MessageHandler.Adapter<RuntimeException>
Expand All @@ -36,11 +37,12 @@ public class TransportBridge extends MessageHandler.Adapter<RuntimeException>
private final MessageProcessingCallback<StatementMetadata> runCallback;
private final MessageProcessingCallback<RecordStream> resultStreamCallback;
private final MessageProcessingCallback<Void> simpleCallback;
private final AuthManager authManager;

private Session session;

public TransportBridge( Log log, Session session, MessageHandler<IOException> output,
Runnable onEachCompletedRequest )
Runnable onEachCompletedRequest, AuthManager authManager )
{
this.resultStreamCallback = new RecordStreamCallback( log );
this.simpleCallback = new MessageProcessingCallback<>( log );
Expand All @@ -49,11 +51,13 @@ public TransportBridge( Log log, Session session, MessageHandler<IOException> ou
this.simpleCallback.reset( output, onEachCompletedRequest );
this.resultStreamCallback.reset( output, onEachCompletedRequest );
this.runCallback.reset( output, onEachCompletedRequest );
this.authManager = authManager;
}

@Override
public void handleInitMessage( String clientName ) throws RuntimeException
{
//TODO do auth here
session.init( clientName, null, simpleCallback );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.bolt.v1.runtime.internal.Neo4jError;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.logging.Log;
import org.neo4j.server.security.auth.AuthManager;

import static org.neo4j.bolt.v1.messaging.msgprocess.MessageProcessingCallback.publishError;

Expand All @@ -58,15 +59,15 @@ public class BoltProtocolV1 implements BoltProtocol
private final Log log;
private final AtomicInteger inFlight = new AtomicInteger( 0 );

public BoltProtocolV1( final LogService logging, Session session, Channel channel )
public BoltProtocolV1( final LogService logging, Session session, Channel channel, AuthManager authManager )
{
this.log = logging.getInternalLog( getClass() );
this.session = session;
this.output = new ChunkedOutput( channel, DEFAULT_BUFFER_SIZE );
this.packer = new PackStreamMessageFormatV1.Writer( new Neo4jPack.Packer( output ), output );

this.dechunker = new BoltV1Dechunker(
new TransportBridge( log, session, packer, this::onMessageDone ),
new TransportBridge( log, session, packer, this::onMessageDone, authManager ),
this::onMessageStarted );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.neo4j.bolt.v1.transport.BoltProtocolV1;
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.kernel.impl.util.HexPrinter;
import org.neo4j.server.security.auth.AuthManager;

import static io.netty.buffer.Unpooled.wrappedBuffer;
import static org.mockito.Matchers.any;
Expand Down Expand Up @@ -115,7 +116,7 @@ private void testPermutation( byte[] unfragmented, ByteBuf[] fragments ) throws
ChannelHandlerContext ctx = mock( ChannelHandlerContext.class );
when(ctx.channel()).thenReturn( ch );

BoltProtocolV1 protocol = new BoltProtocolV1( NullLogService.getInstance(), sess, ch );
BoltProtocolV1 protocol = new BoltProtocolV1( NullLogService.getInstance(), sess, ch, mock( AuthManager.class) );

// When data arrives split up according to the current permutation
for ( ByteBuf fragment : fragments )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.server.security.auth.AuthManager;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -103,7 +104,8 @@ private SocketTransportHandler.ProtocolChooser protocolChooser( final Session se
{
PrimitiveLongObjectMap<BiFunction<Channel,Boolean,BoltProtocol>> availableVersions = longObjectMap();
availableVersions.put( BoltProtocolV1.VERSION,
( channel, isSecure ) -> new BoltProtocolV1( NullLogService.getInstance(), session, channel )
( channel, isSecure ) -> new BoltProtocolV1( NullLogService.getInstance(), session, channel, mock(
AuthManager.class ) )
);

return new SocketTransportHandler.ProtocolChooser( availableVersions, true );
Expand Down

0 comments on commit 4cea1e9

Please sign in to comment.