Search in sources :

Example 1 with AuthenticationResult

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

the class MultiRealmAuthManagerTest method shouldActivateActiveUser.

@Test
public void shouldActivateActiveUser() throws Throwable {
    // Given
    final User user = newUser("jake", "abc123", false);
    users.create(user);
    manager.start();
    when(authStrategy.authenticate(user, "abc123")).thenReturn(AuthenticationResult.SUCCESS);
    // When
    userManager.activateUser("jake", false);
    setMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);
    // Then
    AuthenticationResult result = manager.login(authToken("jake", "abc123")).subject().getAuthenticationResult();
    assertThat(result, equalTo(AuthenticationResult.SUCCESS));
}
Also used : User(org.neo4j.kernel.impl.security.User) AuthenticationResult(org.neo4j.kernel.api.security.AuthenticationResult) Test(org.junit.Test)

Example 2 with AuthenticationResult

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

the class MultiRealmAuthManagerTest method shouldReturnTooManyAttemptsWhenThatIsAppropriate.

@Test
public void shouldReturnTooManyAttemptsWhenThatIsAppropriate() throws Throwable {
    // Given
    users.create(newUser("jake", "abc123", true));
    manager.start();
    setMockAuthenticationStrategyResult("jake", "wrong password", AuthenticationResult.TOO_MANY_ATTEMPTS);
    // When
    AuthSubject authSubject = manager.login(authToken("jake", "wrong password")).subject();
    AuthenticationResult result = authSubject.getAuthenticationResult();
    // Then
    assertThat(result, equalTo(AuthenticationResult.TOO_MANY_ATTEMPTS));
    logProvider.assertExactly(error("[%s]: failed to log in: too many failed attempts", "jake"));
}
Also used : AuthSubject(org.neo4j.kernel.api.security.AuthSubject) AuthenticationResult(org.neo4j.kernel.api.security.AuthenticationResult) Test(org.junit.Test)

Example 3 with AuthenticationResult

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

the class MultiRealmAuthManagerTest method shouldSuspendExistingUser.

@Test
public void shouldSuspendExistingUser() throws Throwable {
    // Given
    final User user = newUser("jake", "abc123", true);
    users.create(user);
    manager.start();
    // When
    userManager.suspendUser("jake");
    // Then
    setMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);
    AuthenticationResult result = manager.login(authToken("jake", "abc123")).subject().getAuthenticationResult();
    assertThat(result, equalTo(AuthenticationResult.FAILURE));
}
Also used : User(org.neo4j.kernel.impl.security.User) AuthenticationResult(org.neo4j.kernel.api.security.AuthenticationResult) Test(org.junit.Test)

Example 4 with AuthenticationResult

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

the class MultiRealmAuthManagerTest method shouldNotRequestPasswordChangeWithInvalidCredentials.

@Test
public void shouldNotRequestPasswordChangeWithInvalidCredentials() throws Throwable {
    // Given
    users.create(newUser("neo", "abc123", true));
    manager.start();
    setMockAuthenticationStrategyResult("neo", "abc123", AuthenticationResult.SUCCESS);
    setMockAuthenticationStrategyResult("neo", "wrong", AuthenticationResult.FAILURE);
    // When
    AuthenticationResult result = manager.login(authToken("neo", "wrong")).subject().getAuthenticationResult();
    // Then
    assertThat(result, equalTo(AuthenticationResult.FAILURE));
}
Also used : AuthenticationResult(org.neo4j.kernel.api.security.AuthenticationResult) Test(org.junit.Test)

Example 5 with AuthenticationResult

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

the class MultiRealmAuthManagerTest method shouldSuspendSuspendedUser.

@Test
public void shouldSuspendSuspendedUser() throws Throwable {
    // Given
    final User user = newUser("jake", "abc123", false);
    users.create(user);
    manager.start();
    userManager.suspendUser("jake");
    // When
    userManager.suspendUser("jake");
    setMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);
    // Then
    AuthenticationResult result = manager.login(authToken("jake", "abc123")).subject().getAuthenticationResult();
    assertThat(result, equalTo(AuthenticationResult.FAILURE));
}
Also used : User(org.neo4j.kernel.impl.security.User) AuthenticationResult(org.neo4j.kernel.api.security.AuthenticationResult) Test(org.junit.Test)

Aggregations

AuthenticationResult (org.neo4j.kernel.api.security.AuthenticationResult)13 Test (org.junit.Test)11 User (org.neo4j.kernel.impl.security.User)5 AuthSubject (org.neo4j.kernel.api.security.AuthSubject)3 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1 UnsupportedTokenException (org.apache.shiro.authc.pam.UnsupportedTokenException)1 InvalidAuthTokenException (org.neo4j.kernel.api.security.exception.InvalidAuthTokenException)1