use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultAccMultipleSystemAuthenticatorIntegrationTest method testMustChangePasswordException.
@Test(expected = MustChangePasswordException.class)
public void testMustChangePasswordException() {
String passwordSystem = getHelper().createName();
String passwordIdm = getHelper().createName();
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(passwordIdm));
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setMustChange(true);
passwordService.save(password);
SysSystemDto systemOne = createSystem(null);
addSystemToIdentity(identity, systemOne);
changePassword(identity, passwordSystem, getAccountIdForSystem(identity, systemOne));
setupAuthentication(systemOne);
// System One
LoginDto loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(new GuardedString(passwordSystem));
// valid credentials
Assert.assertTrue(authenticationManager.validate(loginDto));
// but must change password before authentication
authenticationManager.authenticate(loginDto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultLoginService method getValidIdentity.
private IdmIdentityDto getValidIdentity(LoginDto loginDto, boolean propagateException) {
String username = loginDto.getUsername();
LOG.info("Identity with username [{}] authenticating", username);
IdmIdentityDto identity = identityService.getByUsername(username);
// identity exists
if (identity == null) {
String validationMessage = MessageFormat.format("Check identity can login: The identity " + "[{0}] either doesn't exist or is deleted.", username);
if (!propagateException) {
LOG.debug(validationMessage);
return null;
}
throw new IdentityNotFoundException(validationMessage);
}
// identity is valid
if (identity.isDisabled()) {
String validationMessage = MessageFormat.format("Check identity can login: The identity [{0}] is disabled.", username);
if (!propagateException) {
LOG.debug(validationMessage);
return null;
}
throw new IdentityDisabledException(validationMessage);
}
// GuardedString isn't necessary password is in hash.
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
if (password == null) {
String validationMessage = MessageFormat.format("Identity [{0}] does not have pasword stored in IdM.", username);
if (!propagateException) {
LOG.debug(validationMessage);
return null;
}
throw new IdmAuthenticationException(validationMessage);
}
// check if password expired
if (password.getValidTill() != null && password.getValidTill().isBefore(LocalDate.now())) {
String validationMessage = MessageFormat.format("Password for identity [{0}] is expired.", username);
if (!propagateException) {
LOG.debug(validationMessage);
return null;
}
throw new ResultCodeException(CoreResultCode.PASSWORD_EXPIRED);
}
// given password is correct
if (!passwordService.checkPassword(loginDto.getPassword(), password)) {
String validationMessage = MessageFormat.format("Identity [{0}] password check failed.", username);
if (!propagateException) {
LOG.debug(validationMessage);
return null;
}
throw new IdmAuthenticationException(validationMessage);
}
//
return identity;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method confirm.
@Override
@Transactional
public boolean confirm(UUID identityId, TwoFactorRegistrationConfirmDto registrationConfirm) {
Assert.notNull(identityId, "Identity identifier is required.");
Assert.notNull(registrationConfirm, "Two factor confirm request is required.");
//
// support two factor authentication, even when identity is not authenticated by IdM (secret is required to persist only)
IdmPasswordDto password = passwordService.findOrCreateByIdentity(identityId);
if (password == null) {
throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
}
//
GuardedString verificationSecret = registrationConfirm.getVerificationSecret();
GuardedString verificationCode = registrationConfirm.getVerificationCode();
//
if (!verifyCode(verificationSecret, verificationCode)) {
throw new ResultCodeException(CoreResultCode.TWO_FACTOR_VERIFICATION_CODE_FAILED);
}
//
password.setVerificationSecret(verificationSecret.asString());
passwordService.save(password);
//
IdmProfileDto profile = profileService.findOrCreateByIdentity(identityId);
profile.setTwoFactorAuthenticationType(registrationConfirm.getTwoFactorAuthenticationType());
profileService.save(profile);
//
return true;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method requireTwoFactorAuthentication.
@Override
@Transactional
public boolean requireTwoFactorAuthentication(UUID identityId, UUID tokenId) {
// check two factor authentication is enabled
TwoFactorAuthenticationType twoFactorAuthenticationType = getTwoFactorAuthenticationType(identityId);
if (twoFactorAuthenticationType == null) {
return false;
}
//
IdmTokenDto token = tokenManager.getToken(tokenId);
if (token.isSecretVerified()) {
// token was already verified
return false;
}
//
if (TwoFactorAuthenticationType.NOTIFICATION == twoFactorAuthenticationType) {
IdmPasswordDto password = passwordService.findOneByIdentity(identityId);
if (password == null) {
throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
}
sendVerificationCode(identityService.get(identityId), generateCode(new GuardedString(password.getVerificationSecret())));
}
//
return true;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class PasswordExpiredTaskExecutorIntegrationTest method testSimpleMessageDry.
@Test
public void testSimpleMessageDry() {
// prepare date
IdmIdentityDto identity = getHelper().createIdentity();
//
try {
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
password.setValidTill(LocalDate.now().minusDays(1));
password = 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> queueItems = itemService.findQueueItems(scheduledTask, null);
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
// first check
Assert.assertTrue(result);
Assert.assertTrue(executor.getCount() > 0);
Assert.assertTrue(queueItems.getTotalElements() > 0);
Assert.assertTrue(logItems.getTotalElements() > 0);
Assert.assertTrue(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
// second process
longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
executor.setLongRunningTaskId(longRunningTask.getId());
executor.init(new HashMap<>());
result = executor.process();
itemService.findQueueItems(scheduledTask, null);
logItems = itemService.findLogItems(longRunningTask, null);
// second check
Assert.assertTrue(result);
Assert.assertEquals(Long.valueOf(0), executor.getCount());
Assert.assertTrue(queueItems.getTotalElements() > 0);
Assert.assertEquals(0, logItems.getTotalElements());
} finally {
identityService.delete(identity);
}
}
Aggregations