use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testAuthenticatePasswordIsDeleted.
@Test(expected = EntityNotFoundException.class)
public void testAuthenticatePasswordIsDeleted() {
// password is needed
IdmIdentityDto identity = getHelper().createIdentity();
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
//
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()));
//
// delete password
passwordService.delete(password);
//
manager.authenticate(loginDto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class PasswordExpiredTaskExecutorIntegrationTest method testNotSendMessageValidTillToday.
@Test
public void testNotSendMessageValidTillToday() {
// prepare date
IdmIdentityDto identity = getHelper().createIdentity();
//
try {
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setValidTill(LocalDate.now());
passwordService.save(password);
// prepare task
IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(new HashMap<>());
// first process
Boolean result = executor.process();
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
// check
Assert.assertTrue(result);
Assert.assertTrue(logItems.getContent().stream().anyMatch(pi -> {
return pi.getReferencedEntityId().equals(password.getId()) && pi.getOperationResult().getState() == OperationState.NOT_EXECUTED;
}));
} finally {
identityService.delete(identity);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class PasswordExpiredTaskExecutorIntegrationTest method testNotSendMessageToDisabledIdentity.
@Test
public void testNotSendMessageToDisabledIdentity() {
// prepare date
IdmIdentityDto identity = getHelper().createIdentity();
//
try {
IdmPasswordDto preparedPassword = passwordService.findOneByIdentity(identity.getId());
preparedPassword.setValidTill(LocalDate.now().minusDays(1));
IdmPasswordDto password = passwordService.save(preparedPassword);
// disable identity
identity.setState(IdentityState.DISABLED_MANUALLY);
identityService.save(identity);
// prepare task
IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(new HashMap<>());
// first process
Boolean result = executor.process();
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
// check
Assert.assertTrue(result);
Assert.assertFalse(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
} finally {
identityService.delete(identity);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testSavePasswordNeverExpiresWithSetValidTill.
@Test
public void testSavePasswordNeverExpiresWithSetValidTill() {
String password = "pass-" + System.currentTimeMillis();
IdmIdentityDto identityDto = this.getHelper().createIdentity(new GuardedString(password));
IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identityDto.getId());
assertFalse(passwordDto.isPasswordNeverExpires());
passwordDto.setValidTill(LocalDate.now().plusDays(10));
passwordDto = passwordService.save(passwordDto);
assertFalse(passwordDto.isPasswordNeverExpires());
assertEquals(LocalDate.now().plusDays(10), passwordDto.getValidTill());
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 testFailWithouMaxUnsuccessfulAttempts.
@Test
public void testFailWithouMaxUnsuccessfulAttempts() {
IdmPasswordPolicyDto validatePolicy = new IdmPasswordPolicyDto();
validatePolicy.setName(getHelper().createName());
validatePolicy.setBlockLoginTime(3);
validatePolicy.setMaxUnsuccessfulAttempts(null);
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 (IdmAuthenticationException ex) {
// success
}
passwordDto = passwordService.findOneByIdentity(identity.getId());
assertNotNull(passwordDto);
assertNull(passwordDto.getBlockLoginDate());
assertEquals(3, passwordDto.getUnsuccessfulAttempts());
try {
authenticationManager.authenticate(loginDto);
fail();
} catch (IdmAuthenticationException ex) {
// success
}
passwordDto = passwordService.findOneByIdentity(identity.getId());
assertNotNull(passwordDto);
assertNull(passwordDto.getBlockLoginDate());
assertEquals(4, passwordDto.getUnsuccessfulAttempts());
}
Aggregations