Search in sources :

Example 51 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testMustChangePassword.

@Test
public void testMustChangePassword() {
    // create identity with must change password
    IdmIdentityDto identity = getHelper().createIdentity("password");
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    password.setMustChange(true);
    passwordService.save(password);
    // 
    // change password
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    passwordChangeDto.setOldPassword(identity.getPassword());
    passwordChangeDto.setNewPassword(identity.getPassword());
    identityService.passwordChange(identity, passwordChangeDto);
    // 
    // try to login => ok
    LoginDto login = loginService.login(new LoginDto(identity));
    Assert.assertNotNull(login.getToken());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 52 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testClearBlockLoginDate.

@Test
public void testClearBlockLoginDate() {
    IdmPasswordPolicyDto validatePolicy = new IdmPasswordPolicyDto();
    validatePolicy.setName(getHelper().createName());
    validatePolicy.setBlockLoginTime(150);
    validatePolicy.setMaxUnsuccessfulAttempts(3);
    validatePolicy.setDefaultPolicy(true);
    validatePolicy.setType(IdmPasswordPolicyType.VALIDATE);
    validatePolicy = passwordPolicyService.save(validatePolicy);
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    assertEquals(0, passwordDto.getUnsuccessfulAttempts());
    // first login
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    GuardedString oldPassword = new GuardedString(String.valueOf(System.currentTimeMillis()));
    loginDto.setPassword(oldPassword);
    try {
        authenticationManager.authenticate(loginDto);
        fail();
    } catch (IdmAuthenticationException ex) {
    // success
    }
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    assertEquals(1, passwordDto.getUnsuccessfulAttempts());
    try {
        authenticationManager.authenticate(loginDto);
        fail();
    } catch (IdmAuthenticationException ex) {
    // success
    }
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    assertEquals(2, passwordDto.getUnsuccessfulAttempts());
    try {
        authenticationManager.authenticate(loginDto);
        fail();
    } catch (ResultCodeException ex) {
    // Another exception
    // success
    }
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNotNull(passwordDto.getBlockLoginDate());
    assertEquals(3, passwordDto.getUnsuccessfulAttempts());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    passwordChangeDto.setOldPassword(oldPassword);
    passwordChangeDto.setNewPassword(new GuardedString(String.valueOf(System.currentTimeMillis())));
    identityService.passwordChange(identity, passwordChangeDto);
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    assertEquals(0, passwordDto.getUnsuccessfulAttempts());
    passwordPolicyService.delete(validatePolicy);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 53 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testMustChangePasswordException.

@Test(expected = MustChangePasswordException.class)
public void testMustChangePasswordException() {
    // create identity with must change password
    IdmIdentityDto identity = getHelper().createIdentity("password");
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    password.setMustChange(true);
    passwordService.save(password);
    // 
    // try to login => exception
    authenticationManager.authenticate(new LoginDto(identity));
}
Also used : IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 54 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testReachSecondBlockPeriod.

@Test
public void testReachSecondBlockPeriod() throws InterruptedException {
    IdmPasswordPolicyDto validatePolicy = new IdmPasswordPolicyDto();
    validatePolicy.setName(getHelper().createName());
    validatePolicy.setBlockLoginTime(2);
    validatePolicy.setMaxUnsuccessfulAttempts(1);
    validatePolicy.setDefaultPolicy(true);
    validatePolicy.setType(IdmPasswordPolicyType.VALIDATE);
    validatePolicy = passwordPolicyService.save(validatePolicy);
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    assertEquals(0, passwordDto.getUnsuccessfulAttempts());
    // first login
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    GuardedString oldPassword = new GuardedString(String.valueOf(System.currentTimeMillis()));
    loginDto.setPassword(oldPassword);
    ZonedDateTime start = ZonedDateTime.now();
    try {
        authenticationManager.authenticate(loginDto);
        fail();
    } catch (ResultCodeException ex) {
    // success
    }
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNotNull(passwordDto.getBlockLoginDate());
    assertEquals(1, passwordDto.getUnsuccessfulAttempts());
    ZonedDateTime blockLoginDate = passwordDto.getBlockLoginDate();
    long seconds = ChronoUnit.SECONDS.between(start, blockLoginDate);
    if (seconds > 3) {
        // correct is 2 second but some machine can be slower
        fail("Diff between start and block date is more than 3 second. Current: " + seconds);
    }
    Thread.sleep(1000 * seconds);
    start = ZonedDateTime.now();
    try {
        authenticationManager.authenticate(loginDto);
        fail();
    } catch (ResultCodeException ex) {
    // success
    }
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNotNull(passwordDto.getBlockLoginDate());
    // Attempts are increased
    assertEquals(2, passwordDto.getUnsuccessfulAttempts());
    blockLoginDate = passwordDto.getBlockLoginDate();
    seconds = ChronoUnit.SECONDS.between(start, blockLoginDate);
    if (seconds > 5) {
        // correct is 4 second but some machine can be slower
        fail("Diff between start and block date is more than 5 second. Current: " + seconds);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ZonedDateTime(java.time.ZonedDateTime) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 55 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testNonExistingPassword.

@Test
public void testNonExistingPassword() {
    IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
    passwordPolicy.setName(getHelper().createName());
    passwordPolicy.setDefaultPolicy(true);
    passwordPolicy.setType(IdmPasswordPolicyType.VALIDATE);
    passwordPolicy.setBlockLoginTime(2);
    passwordPolicy.setMaxUnsuccessfulAttempts(2);
    passwordPolicy = passwordPolicyService.save(passwordPolicy);
    IdmIdentityDto identity = getHelper().createIdentity(null, null);
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNull(passwordDto);
    String wrongPassword = "badPassword" + System.currentTimeMillis();
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    // password was created
    assertNotNull(passwordDto);
    assertNull(passwordDto.getPassword());
    assertNull(passwordDto.getBlockLoginDate());
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    // block
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getPassword());
    assertNotNull(passwordDto.getBlockLoginDate());
    passwordPolicyService.delete(passwordPolicy);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)88 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)71 Test (org.junit.Test)65 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)53 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)52 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)28 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)9 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)9 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)9 ZonedDateTime (java.time.ZonedDateTime)9 UUID (java.util.UUID)9 IdmPasswordFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter)8 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException)8 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7