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