use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testChangPasswordWithNeverExpiresAndValidTill.
@Test
public void testChangPasswordWithNeverExpiresAndValidTill() {
IdmPasswordPolicyDto validatePolicy = new IdmPasswordPolicyDto();
validatePolicy.setName(getHelper().createName());
validatePolicy.setMaxPasswordAge(10);
validatePolicy.setDefaultPolicy(true);
validatePolicy.setType(IdmPasswordPolicyType.VALIDATE);
validatePolicy = passwordPolicyService.save(validatePolicy);
String password = "pass-" + System.currentTimeMillis();
IdmIdentityDto identityDto = this.getHelper().createIdentity(new GuardedString(password));
IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identityDto.getId());
assertEquals(LocalDate.now().plusDays(10), passwordDto.getValidTill());
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setOldPassword(new GuardedString(password));
passwordChange.setNewPassword(new GuardedString(password + "2"));
passwordService.save(identityDto, passwordChange);
assertFalse(passwordDto.isPasswordNeverExpires());
passwordDto.setPasswordNeverExpires(true);
IdmPasswordDto newlySaved = passwordService.save(passwordDto);
assertTrue(newlySaved.isPasswordNeverExpires());
assertNull(passwordDto.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testSavePasswordNeverExpires.
@Test
public void testSavePasswordNeverExpires() {
String password = "pass-" + System.currentTimeMillis();
IdmIdentityDto identityDto = this.getHelper().createIdentity(new GuardedString(password));
IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identityDto.getId());
assertFalse(passwordDto.isPasswordNeverExpires());
passwordDto.setPasswordNeverExpires(true);
IdmPasswordDto newlySaved = passwordService.save(passwordDto);
assertTrue(newlySaved.isPasswordNeverExpires());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testBlockLogin.
@Test
public void testBlockLogin() throws InterruptedException {
loginAsAdmin();
String testPassword = "testPassword" + System.currentTimeMillis();
IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
passwordPolicy.setName(getHelper().createName());
passwordPolicy.setDefaultPolicy(true);
passwordPolicy.setType(IdmPasswordPolicyType.VALIDATE);
passwordPolicy.setBlockLoginTime(2);
passwordPolicy.setMaxUnsuccessfulAttempts(4);
passwordPolicy = passwordPolicyService.save(passwordPolicy);
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
logout();
LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
assertNotNull(loginDto.getToken());
assertEquals(CoreModuleDescriptor.MODULE_ID, loginDto.getAuthenticationModule());
// try fail - 1#
tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
identity = identityService.get(identity.getId());
assertNull(identity.getBlockLoginDate());
// try fail - 2#
tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
identity = identityService.get(identity.getId());
assertNull(identity.getBlockLoginDate());
// try fail - 3#
tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
identity = identityService.get(identity.getId());
assertNull(identity.getBlockLoginDate());
// try fail - 4# (block)
tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
identity = identityService.get(identity.getId());
ZonedDateTime blockLoginDate = identity.getBlockLoginDate();
// blockLoginDate isn't filled by service more
assertNull(blockLoginDate);
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
assertNotNull(password);
blockLoginDate = password.getBlockLoginDate();
assertNotNull(blockLoginDate);
// try success but login is blocked
tryLoginExceptFail(identity.getUsername(), testPassword);
identity = identityService.get(identity.getId());
password = passwordService.findOneByIdentity(identity.getId());
assertNotNull(password);
assertNotNull(password.getBlockLoginDate());
// date is same
assertEquals(blockLoginDate, password.getBlockLoginDate());
// wait for 2 sec
Thread.sleep(2000);
loginDto = tryLogin(identity.getUsername(), testPassword);
assertNotNull(loginDto.getToken());
assertEquals(CoreModuleDescriptor.MODULE_ID, loginDto.getAuthenticationModule());
passwordPolicyService.delete(passwordPolicy);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testLoginWithoutPasswordPolicy.
@Test
public void testLoginWithoutPasswordPolicy() {
// remove all policies
for (IdmPasswordPolicyDto passwordPolicy : passwordPolicyService.find(null)) {
passwordPolicyService.delete(passwordPolicy);
}
String testPassword = "testPassword" + System.currentTimeMillis();
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
logout();
LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
checkLoginDto(loginDto);
String wrongPassword = "badPassword" + System.currentTimeMillis();
tryLoginExceptFail(identity.getUsername(), wrongPassword);
tryLoginExceptFail(identity.getUsername(), wrongPassword);
tryLoginExceptFail(identity.getUsername(), wrongPassword);
tryLoginExceptFail(identity.getUsername(), wrongPassword);
IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identity.getId());
assertNotNull(passwordDto);
assertNull(passwordDto.getBlockLoginDate());
identity = identityService.get(identity.getId());
assertNull(identity.getBlockLoginDate());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testAuthenticateMustChangePasswordIsSkipped.
@Test
public void testAuthenticateMustChangePasswordIsSkipped() {
// password is needed
IdmIdentityDto identity = getHelper().createIdentity();
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setMustChange(true);
passwordService.save(password);
//
TwoFactorRegistrationResponseDto initResponse = manager.init(identity.getId(), TwoFactorAuthenticationType.NOTIFICATION);
Assert.assertNotNull(initResponse);
Assert.assertNotNull(initResponse.getVerificationSecret());
Assert.assertEquals(identity.getUsername(), initResponse.getUsername());
Assert.assertNull(initResponse.getQrcode());
//
// confirm
TwoFactorRegistrationConfirmDto confirm = new TwoFactorRegistrationConfirmDto();
confirm.setVerificationSecret(new GuardedString(initResponse.getVerificationSecret()));
confirm.setVerificationCode(manager.generateCode(new GuardedString(initResponse.getVerificationSecret())));
confirm.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.NOTIFICATION);
Assert.assertTrue(manager.confirm(identity.getId(), confirm));
Assert.assertEquals(initResponse.getVerificationSecret(), getHelper().getPassword(identity).getVerificationSecret());
//
LoginDto loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(identity.getPassword());
// creadentials are valid
Assert.assertTrue(authenticationManager.validate(loginDto));
// but two factor authentication is required
String token = null;
try {
authenticationManager.authenticate(loginDto);
} catch (TwoFactorAuthenticationRequiredException ex) {
token = ex.getToken();
}
Assert.assertNotNull(token);
//
loginDto.setToken(token);
loginDto.setPassword(manager.generateCode(identity.getId()));
loginDto.setSkipMustChange(true);
LoginDto authenticated = manager.authenticate(loginDto);
//
Assert.assertNotNull(authenticated);
Assert.assertNotNull(authenticated.getAuthentication());
Assert.assertTrue(tokenManager.getToken(authenticated.getAuthentication().getId()).isSecretVerified());
}
Aggregations