Search in sources :

Example 1 with AuthenticationResult

use of org.neo4j.internal.kernel.api.security.AuthenticationResult in project neo4j by neo4j.

the class BasicSystemGraphRealm method login.

@Override
public LoginContext login(Map<String, Object> authToken, ClientConnectionInfo connectionInfo) throws InvalidAuthTokenException {
    try {
        assertValidScheme(authToken);
        String username = AuthToken.safeCast(AuthToken.PRINCIPAL, authToken);
        byte[] password = AuthToken.safeCastCredentials(AuthToken.CREDENTIALS, authToken);
        try {
            User user = systemGraphRealmHelper.getUser(username);
            AuthenticationResult result = authenticationStrategy.authenticate(user, password);
            if (result == AuthenticationResult.SUCCESS && user.passwordChangeRequired()) {
                result = AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
            }
            return new BasicLoginContext(user, result, connectionInfo);
        } catch (InvalidArgumentsException | FormatException e) {
            return new BasicLoginContext(null, AuthenticationResult.FAILURE, connectionInfo);
        }
    } finally {
        AuthToken.clearCredentials(authToken);
    }
}
Also used : User(org.neo4j.kernel.impl.security.User) BasicLoginContext(org.neo4j.server.security.auth.BasicLoginContext) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException) FormatException(org.neo4j.cypher.internal.security.FormatException) AuthenticationResult(org.neo4j.internal.kernel.api.security.AuthenticationResult)

Aggregations

FormatException (org.neo4j.cypher.internal.security.FormatException)1 AuthenticationResult (org.neo4j.internal.kernel.api.security.AuthenticationResult)1 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)1 User (org.neo4j.kernel.impl.security.User)1 BasicLoginContext (org.neo4j.server.security.auth.BasicLoginContext)1