Search in sources :

Example 1 with AuthenticationException

use of org.camunda.bpm.engine.AuthenticationException in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testSuccessfulLoginAfterFailureWithoutDelay.

@Test
public void testSuccessfulLoginAfterFailureWithoutDelay() {
    User user = identityService.newUser("johndoe");
    user.setPassword("xxx");
    identityService.saveUser(user);
    Date now = ClockUtil.getCurrentTime();
    assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));
    try {
        assertFalse(identityService.checkPassword("johndoe", "xxx"));
        fail("expected exception");
    } catch (AuthenticationException e) {
        assertEquals("The user with id 'johndoe' is locked.", e.getMessage());
    }
    ClockUtil.setCurrentTime(DateUtils.addSeconds(now, 30));
    assertTrue(identityService.checkPassword("johndoe", "xxx"));
    identityService.deleteUser("johndoe");
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthenticationException(org.camunda.bpm.engine.AuthenticationException) Date(java.util.Date) Test(org.junit.Test)

Example 2 with AuthenticationException

use of org.camunda.bpm.engine.AuthenticationException in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testUnsuccessfulLoginAfterFailureWithoutDelay.

@Test
public void testUnsuccessfulLoginAfterFailureWithoutDelay() {
    User user = identityService.newUser("johndoe");
    user.setPassword("xxx");
    identityService.saveUser(user);
    Date now = null;
    now = ClockUtil.getCurrentTime();
    assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));
    // try again before exprTime
    ClockUtil.setCurrentTime(DateUtils.addSeconds(now, 1));
    try {
        assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));
        fail("expected exception");
    } catch (AuthenticationException e) {
        assertEquals("The user with id 'johndoe' is locked.", e.getMessage());
    }
    identityService.deleteUser("johndoe");
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthenticationException(org.camunda.bpm.engine.AuthenticationException) Date(java.util.Date) Test(org.junit.Test)

Example 3 with AuthenticationException

use of org.camunda.bpm.engine.AuthenticationException in project camunda-bpm-platform by camunda.

the class LoginAttemptsTest method testUsuccessfulAttemptsResultInException.

@Test
public void testUsuccessfulAttemptsResultInException() throws ParseException {
    User user = identityService.newUser("johndoe");
    user.setPassword("xxx");
    identityService.saveUser(user);
    Date now = sdf.parse("2000-01-24T13:00:00");
    ClockUtil.setCurrentTime(now);
    try {
        for (int i = 0; i <= 6; i++) {
            assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));
            now = DateUtils.addSeconds(now, 5);
            ClockUtil.setCurrentTime(now);
        }
        fail("expected exception");
    } catch (AuthenticationException e) {
        assertTrue(e.getMessage().contains("The user with id 'johndoe' is locked."));
    }
    identityService.deleteUser(user.getId());
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthenticationException(org.camunda.bpm.engine.AuthenticationException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)3 AuthenticationException (org.camunda.bpm.engine.AuthenticationException)3 User (org.camunda.bpm.engine.identity.User)3 Test (org.junit.Test)3