Search in sources :

Example 1 with BoltConnectionFatality

use of org.neo4j.bolt.runtime.BoltConnectionFatality in project neo4j by neo4j.

the class BoltConditions method verifyOneResponse.

public static void verifyOneResponse(ThrowingBiConsumer<BoltStateMachine, BoltResponseRecorder, BoltConnectionFatality> transition) throws Exception {
    BoltStateMachine machine = newMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    try {
        transition.accept(machine, recorder);
    } catch (BoltConnectionFatality connectionFatality) {
    // acceptable for invalid transitions
    }
    assertEquals(1, recorder.responseCount());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) AbstractBoltStateMachine(org.neo4j.bolt.runtime.statemachine.impl.AbstractBoltStateMachine) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality)

Example 2 with BoltConnectionFatality

use of org.neo4j.bolt.runtime.BoltConnectionFatality in project neo4j by neo4j.

the class AbstractBoltStateMachine method handleFailure.

@Override
public void handleFailure(Throwable cause, boolean fatal) throws BoltConnectionFatality {
    if (ExceptionUtils.indexOfType(cause, BoltConnectionFatality.class) != -1) {
        fatal = true;
    }
    Neo4jError error = fatal ? Neo4jError.fatalFrom(cause) : Neo4jError.from(cause);
    fail(error);
    if (error.isFatal()) {
        if (ExceptionUtils.indexOfType(cause, AuthorizationExpiredException.class) != -1) {
            throw new BoltConnectionAuthFatality("Failed to process a bolt message", cause);
        }
        if (cause instanceof AuthenticationException) {
            throw new BoltConnectionAuthFatality((AuthenticationException) cause);
        }
        throw new BoltConnectionFatality("Failed to process a bolt message", cause);
    }
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) AuthenticationException(org.neo4j.bolt.security.auth.AuthenticationException) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality)

Example 3 with BoltConnectionFatality

use of org.neo4j.bolt.runtime.BoltConnectionFatality in project neo4j by neo4j.

the class BytesAccumulator method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf buf = (ByteBuf) msg;
    count += buf.readableBytes();
    if (count < 0) {
        count = Long.MAX_VALUE;
    }
    if (count > limit) {
        ctx.channel().close();
        throw new BoltConnectionFatality(format("A connection '%s' is terminated because too many inbound bytes received " + "before the client is authenticated. Max bytes allowed: %s. Bytes received: %s.", ctx.channel(), limit, count), null);
    }
    super.channelRead(ctx, msg);
}
Also used : BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with BoltConnectionFatality

use of org.neo4j.bolt.runtime.BoltConnectionFatality in project neo4j by neo4j.

the class BoltStateMachineV4Test method actionsDisallowedBeforeInitialized.

@Test
void actionsDisallowedBeforeInitialized() {
    // Given
    BoltStateMachine machine = newMachine();
    // When
    try {
        machine.process(BoltV4Messages.run(), nullResponseHandler());
        fail("Failed to fail fatally");
    }// Then
     catch (BoltConnectionFatality e) {
    // fatality correctly generated
    }
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality) Test(org.junit.jupiter.api.Test)

Aggregations

BoltConnectionFatality (org.neo4j.bolt.runtime.BoltConnectionFatality)4 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.jupiter.api.Test)1 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)1 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)1 AbstractBoltStateMachine (org.neo4j.bolt.runtime.statemachine.impl.AbstractBoltStateMachine)1 AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)1 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)1