Search in sources :

Example 6 with HelloMessage

use of org.neo4j.bolt.v41.messaging.request.HelloMessage in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeAuthToken.

@Override
protected void testShouldDecodeAuthToken(Map<String, Object> authToken) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    authToken.put("user_agent", "My Driver");
    HelloMessage originalMessage = new HelloMessage(authToken);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
}
Also used : HelloMessage(org.neo4j.bolt.v3.messaging.request.HelloMessage) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)

Example 7 with HelloMessage

use of org.neo4j.bolt.v41.messaging.request.HelloMessage in project neo4j by neo4j.

the class HelloMessageDecoder method decode.

@Override
public RequestMessage decode(Neo4jPack.Unpacker unpacker) throws IOException {
    Map<String, Object> meta = readMetaDataMap(unpacker);
    RoutingContext routingContext = parseRoutingContext(meta);
    return new HelloMessage(meta, routingContext, extractAuthToken(meta));
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage)

Example 8 with HelloMessage

use of org.neo4j.bolt.v41.messaging.request.HelloMessage in project neo4j by neo4j.

the class ConnectedState method process.

@Override
public BoltStateMachineState process(RequestMessage message, StateMachineContext context) throws BoltConnectionFatality {
    assertInitialized();
    if (message instanceof HelloMessage) {
        HelloMessage helloMessage = (HelloMessage) message;
        String userAgent = helloMessage.userAgent();
        Map<String, Object> authToken = helloMessage.authToken();
        RoutingContext routingContext = helloMessage.routingContext();
        if (processAuthentication(userAgent, authToken, context, routingContext)) {
            context.resolveDefaultDatabase();
            context.connectionState().onMetadata(CONNECTION_ID_KEY, Values.utf8Value(context.connectionId()));
            context.connectionState().onMetadata("hints", hints);
            return readyState;
        } else {
            return null;
        }
    }
    return null;
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage)

Example 9 with HelloMessage

use of org.neo4j.bolt.v41.messaging.request.HelloMessage in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenEmptyRoutingContextProvided.

@Test
void testShouldDecodeWhenEmptyRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, meta);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Example 10 with HelloMessage

use of org.neo4j.bolt.v41.messaging.request.HelloMessage in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeRoutingContext.

@Test
void testShouldDecodeRoutingContext() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, Object> authToken;
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    parameterMap.put("policy", "fast");
    parameterMap.put("region", "eu-west");
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    authToken = new HashMap<>(Map.copyOf(meta));
    authToken.remove("routing");
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, authToken);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)9 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)9 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)7 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)7 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)7 HashMap (java.util.HashMap)5 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)5 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)5 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)2 BeginMessage (org.neo4j.bolt.v3.messaging.request.BeginMessage)1 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)1