Search in sources :

Example 1 with FormatException

use of org.neo4j.cypher.internal.security.FormatException in project neo4j by neo4j.

the class UserSerialization method deserializeCredentials.

private static Credential deserializeCredentials(String part, int lineNumber) throws FormatException {
    String[] split = part.split(CREDENTIAL_SEPARATOR, -1);
    String algorithm = split[0];
    int iterations;
    String hasherVersion;
    if (split.length == 4) {
        iterations = Integer.parseInt(split[3]);
    } else if (split.length == 3) {
        iterations = LegacyCredential.ITERATIONS;
    } else {
        throw new FormatException(format("wrong number of credential fields [line %d]", lineNumber));
    }
    try {
        hasherVersion = SecureHasherConfigurations.getVersionForConfiguration(algorithm, iterations);
    } catch (InvalidArgumentException e) {
        throw new FormatException(format("unknown digest \"%s\" [line %d]:", part, lineNumber));
    }
    if (hasherVersion.equals("0")) {
        byte[] decodedPassword = HexString.decodeHexString(split[1]);
        byte[] decodedSalt = HexString.decodeHexString(split[2]);
        return new LegacyCredential(decodedSalt, decodedPassword);
    } else {
        return SystemGraphCredential.deserialize(part, new SecureHasher(hasherVersion));
    }
}
Also used : InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) HexString(org.neo4j.string.HexString) FormatException(org.neo4j.cypher.internal.security.FormatException)

Example 2 with FormatException

use of org.neo4j.cypher.internal.security.FormatException 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)

Example 3 with FormatException

use of org.neo4j.cypher.internal.security.FormatException in project neo4j by neo4j.

the class UserSerialization method deserializeRecord.

@Override
protected User deserializeRecord(String line, int lineNumber) throws FormatException {
    String[] parts = line.split(userSeparator, -1);
    if (parts.length != 3) {
        throw new FormatException(format("wrong number of line fields, expected 3, got %d [line %d]", parts.length, lineNumber));
    }
    User.Builder b = new User.Builder(parts[0], deserializeCredentials(parts[1], lineNumber));
    for (String flag : parts[2].split(",", -1)) {
        String trimmed = flag.trim();
        if (!trimmed.isEmpty()) {
            b = b.withFlag(trimmed);
        }
    }
    return b.build();
}
Also used : User(org.neo4j.kernel.impl.security.User) HexString(org.neo4j.string.HexString) FormatException(org.neo4j.cypher.internal.security.FormatException)

Example 4 with FormatException

use of org.neo4j.cypher.internal.security.FormatException in project neo4j by neo4j.

the class BasicSystemGraphRealmIT method shouldNotAddInitialUserIfUsersExist.

@Test
void shouldNotAddInitialUserIfUsersExist() throws Throwable {
    initialPassword.create(createUser(INITIAL_USER_NAME, "123", false));
    oldUsers.create(createUser("oldUser", "321", false));
    startSystemGraphRealm();
    User initUser;
    try {
        initUser = realmHelper.getUser(INITIAL_USER_NAME);
    } catch (InvalidArgumentsException | FormatException e) {
        initUser = null;
    }
    assertNull(initUser);
    assertAuthenticationSucceeds(realmHelper, "oldUser", "321");
}
Also used : User(org.neo4j.kernel.impl.security.User) BasicSystemGraphRealmTestHelper.createUser(org.neo4j.security.BasicSystemGraphRealmTestHelper.createUser) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException) FormatException(org.neo4j.cypher.internal.security.FormatException) Test(org.junit.jupiter.api.Test)

Aggregations

FormatException (org.neo4j.cypher.internal.security.FormatException)4 User (org.neo4j.kernel.impl.security.User)3 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)2 HexString (org.neo4j.string.HexString)2 Test (org.junit.jupiter.api.Test)1 SecureHasher (org.neo4j.cypher.internal.security.SecureHasher)1 InvalidArgumentException (org.neo4j.exceptions.InvalidArgumentException)1 AuthenticationResult (org.neo4j.internal.kernel.api.security.AuthenticationResult)1 BasicSystemGraphRealmTestHelper.createUser (org.neo4j.security.BasicSystemGraphRealmTestHelper.createUser)1 BasicLoginContext (org.neo4j.server.security.auth.BasicLoginContext)1