Search in sources :

Example 1 with AuthenticationException

use of org.neo4j.bolt.security.auth.AuthenticationException in project neo4j by neo4j.

the class BoltInteraction method collectResults.

private static BoltResult collectResults(TransportConnection client) throws Exception {
    ResponseMessage message = TransportTestUtil.receiveOneResponseMessage(client);
    List<String> fieldNames = new ArrayList<>();
    List<Map<String, Object>> result = new ArrayList<>();
    if (message instanceof SuccessMessage) {
        Map<String, Object> metadata = ((SuccessMessage) message).meta();
        fieldNames = (List<String>) metadata.get("fields");
    } else if (message instanceof FailureMessage) {
        FailureMessage failMessage = (FailureMessage) message;
        // drain ignoredMessage, ack failure, get successMessage
        TransportTestUtil.receiveOneResponseMessage(client);
        client.send(TransportTestUtil.chunk(reset()));
        TransportTestUtil.receiveOneResponseMessage(client);
        throw new AuthenticationException(failMessage.status(), failMessage.message());
    }
    do {
        message = TransportTestUtil.receiveOneResponseMessage(client);
        if (message instanceof RecordMessage) {
            Object[] row = ((RecordMessage) message).record().fields();
            Map<String, Object> rowMap = new HashMap<>();
            for (int i = 0; i < row.length; i++) {
                rowMap.put(fieldNames.get(i), row[i]);
            }
            result.add(rowMap);
        }
    } while (!(message instanceof SuccessMessage) && !(message instanceof FailureMessage));
    if (message instanceof FailureMessage) {
        FailureMessage failMessage = (FailureMessage) message;
        // ack failure, get successMessage
        client.send(TransportTestUtil.chunk(reset()));
        TransportTestUtil.receiveOneResponseMessage(client);
        throw new AuthenticationException(failMessage.status(), failMessage.message());
    }
    return new BoltResult(result);
}
Also used : AuthenticationException(org.neo4j.bolt.security.auth.AuthenticationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) SuccessMessage(org.neo4j.bolt.v1.messaging.message.SuccessMessage) FailureMessage(org.neo4j.bolt.v1.messaging.message.FailureMessage) RecordMessage(org.neo4j.bolt.v1.messaging.message.RecordMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AuthenticationException

use of org.neo4j.bolt.security.auth.AuthenticationException in project neo4j by neo4j.

the class DefaultBoltConnectionTest method shouldLogBoltConnectionAuthFatalityError.

@Test
void shouldLogBoltConnectionAuthFatalityError() {
    BoltConnection connection = newConnection();
    connection.enqueue(machine -> {
        throw new BoltConnectionAuthFatality(new AuthenticationException(Status.Security.Unauthorized, "inner error"));
    });
    connection.processNextBatch();
    verify(stateMachine).close();
    assertThat(logProvider).forClass(DefaultBoltConnection.class).forLevel(WARN).containsMessages("inner error");
}
Also used : AuthenticationException(org.neo4j.bolt.security.auth.AuthenticationException) Test(org.junit.jupiter.api.Test)

Example 3 with AuthenticationException

use of org.neo4j.bolt.security.auth.AuthenticationException 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)

Aggregations

AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)1 BoltConnectionFatality (org.neo4j.bolt.runtime.BoltConnectionFatality)1 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)1 FailureMessage (org.neo4j.bolt.v1.messaging.message.FailureMessage)1 RecordMessage (org.neo4j.bolt.v1.messaging.message.RecordMessage)1 ResponseMessage (org.neo4j.bolt.v1.messaging.message.ResponseMessage)1 SuccessMessage (org.neo4j.bolt.v1.messaging.message.SuccessMessage)1 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)1