use of org.neo4j.kernel.api.security.AuthenticationResult in project neo4j by neo4j.
the class BasicAuthManager method login.
@Override
public BasicSecurityContext login(Map<String, Object> authToken) throws InvalidAuthTokenException {
assertValidScheme(authToken);
String username = AuthToken.safeCast(AuthToken.PRINCIPAL, authToken);
String password = AuthToken.safeCast(AuthToken.CREDENTIALS, authToken);
User user = userRepository.getUserByName(username);
AuthenticationResult result = AuthenticationResult.FAILURE;
if (user != null) {
result = authStrategy.authenticate(user, password);
if (result == AuthenticationResult.SUCCESS && user.passwordChangeRequired()) {
result = AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
}
}
return new BasicSecurityContext(this, user, result);
}
use of org.neo4j.kernel.api.security.AuthenticationResult in project neo4j by neo4j.
the class InternalFlatFileRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (!authenticationEnabled) {
return null;
}
ShiroAuthToken shiroAuthToken = (ShiroAuthToken) token;
String username;
String password;
try {
username = AuthToken.safeCast(AuthToken.PRINCIPAL, shiroAuthToken.getAuthTokenMap());
password = AuthToken.safeCast(AuthToken.CREDENTIALS, shiroAuthToken.getAuthTokenMap());
} catch (InvalidAuthTokenException e) {
throw new UnsupportedTokenException(e);
}
User user = userRepository.getUserByName(username);
if (user == null) {
throw new UnknownAccountException();
}
AuthenticationResult result = authenticationStrategy.authenticate(user, password);
switch(result) {
case FAILURE:
throw new IncorrectCredentialsException();
case TOO_MANY_ATTEMPTS:
throw new ExcessiveAttemptsException();
default:
break;
}
if (user.hasFlag(InternalFlatFileRealm.IS_SUSPENDED)) {
throw new DisabledAccountException("User '" + user.name() + "' is suspended.");
}
if (user.passwordChangeRequired()) {
result = AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
}
// and we do not need to store hashed credentials in the AuthenticationInfo.
return new ShiroAuthenticationInfo(user.name(), getName(), result);
}
use of org.neo4j.kernel.api.security.AuthenticationResult in project neo4j by neo4j.
the class MultiRealmAuthManagerTest method shouldNotLogAuthenticationIfFlagSaysNo.
@Test
public void shouldNotLogAuthenticationIfFlagSaysNo() throws Throwable {
// Given
manager.shutdown();
manager = createAuthManager(false);
users.create(newUser("jake", "abc123", false));
manager.start();
setMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);
// When
AuthenticationResult result = manager.login(authToken("jake", "abc123")).subject().getAuthenticationResult();
// Then
assertThat(result, equalTo(AuthenticationResult.SUCCESS));
logProvider.assertNone(info("[jake]: logged in"));
}
use of org.neo4j.kernel.api.security.AuthenticationResult in project neo4j by neo4j.
the class MultiRealmAuthManagerTest method shouldFailAuthenticationAndEscapeIfUserIsNotFound.
@Test
public void shouldFailAuthenticationAndEscapeIfUserIsNotFound() throws Throwable {
// Given
manager.start();
// When
AuthSubject authSubject = manager.login(authToken("unknown\n\t\r\"haxx0r\"", "abc123")).subject();
AuthenticationResult result = authSubject.getAuthenticationResult();
// Then
assertThat(result, equalTo(AuthenticationResult.FAILURE));
logProvider.assertExactly(error("[%s]: failed to log in: invalid principal or credentials", escape("unknown\n\t\r\"haxx0r\"")));
}
use of org.neo4j.kernel.api.security.AuthenticationResult in project neo4j by neo4j.
the class MultiRealmAuthManagerTest method shouldFindAndAuthenticateUserSuccessfully.
@Test
public void shouldFindAndAuthenticateUserSuccessfully() throws Throwable {
// Given
users.create(newUser("jake", "abc123", false));
manager.start();
setMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);
// When
AuthenticationResult result = manager.login(authToken("jake", "abc123")).subject().getAuthenticationResult();
// Then
assertThat(result, equalTo(AuthenticationResult.SUCCESS));
logProvider.assertExactly(info("[jake]: logged in"));
}
Aggregations