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));
}
}
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);
}
}
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();
}
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");
}
Aggregations