Search in sources :

Example 1 with BoltConnectionAuthFatality

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringREADYRun.

@SuppressWarnings("unchecked")
@Test
void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable {
    // Given
    TransactionStateMachineSPI transactionSPI = mock(TransactionStateMachineSPI.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(transactionSPI).beginTransaction(any(), any(), any(), any(), any(), any());
    BoltStateMachine machine = newMachineWithTransactionSPI(transactionSPI);
    // When & Then
    try {
        machine.process(BoltV4Messages.run("THIS WILL BE IGNORED"), nullResponseHandler());
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 2 with BoltConnectionAuthFatality

use of org.neo4j.bolt.runtime.BoltConnectionAuthFatality 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 BoltConnectionAuthFatality

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onDiscardRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.discardAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 4 with BoltConnectionAuthFatality

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.pullAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
    verify(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Aggregations

BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)4 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)4 Test (org.junit.jupiter.api.Test)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)2 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 BoltConnectionFatality (org.neo4j.bolt.runtime.BoltConnectionFatality)1 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)1 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)1 AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)1