use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class AbstractIdentityPasswordValidateProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
Assert.notNull(passwordChangeDto);
//
if (requiresOriginalPassword()) {
PasswordChangeType passwordChangeType = identityConfiguration.getPasswordChangeType();
if (passwordChangeType == PasswordChangeType.DISABLED) {
// check if isn't disable password change
throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_DISABLED);
} else if (passwordChangeType == PasswordChangeType.ALL_ONLY && !passwordChangeDto.isAll()) {
// for all only must change also password for czechidm
throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_ALL_ONLY);
}
// checkAccess(identity, IdentityBasePermission.PASSWORDCHANGE) is called before event publishing
if (identity.getId().equals(securityService.getCurrentId()) && identityConfiguration.isRequireOldPassword()) {
if (passwordChangeDto.getOldPassword() == null) {
throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
}
// authentication trough chain
boolean successChainAuthentication = authenticationManager.validate(identity.getUsername(), passwordChangeDto.getOldPassword());
if (!successChainAuthentication) {
throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
}
}
}
if (passwordChangeDto.isAll() || passwordChangeDto.isIdm()) {
// change identity's password
// validate password
IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
// set old password for validation - valid till, from and history check
IdmPasswordDto oldPassword = this.passwordService.findOneByIdentity(identity.getId());
passwordValidationDto.setOldPassword(oldPassword == null ? null : oldPassword.getId());
passwordValidationDto.setPassword(passwordChangeDto.getNewPassword());
passwordValidationDto.setIdentity(identity);
this.passwordPolicyService.validate(passwordValidationDto);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testTwoPoliciesSecondValidTillNull.
@Test
public void testTwoPoliciesSecondValidTillNull() {
IdmPasswordPolicyDto policy1 = getTestPolicy(false, IdmPasswordPolicyType.VALIDATE, null);
IdmPasswordPolicyDto policy2 = getTestPolicy(true, IdmPasswordPolicyType.VALIDATE, 5);
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
assertEquals(LocalDate.now(), password.getValidFrom());
assertEquals(identity.getId(), password.getIdentity());
assertEquals(LocalDate.now().plusDays(policy2.getMaxPasswordAge()), password.getValidTill());
//
policy1.setDefaultPolicy(true);
policy1 = policyService.save(policy1);
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(true);
passwordChangeDto.setNewPassword(new GuardedString("testPassword"));
identityService.passwordChange(identity, passwordChangeDto);
password = passwordService.findOneByIdentity(identity.getId());
assertNull(password.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordNonDefaultPolicy.
@Test
public void testCreatePasswordNonDefaultPolicy() {
IdmPasswordPolicyDto policy = getTestPolicy(false);
assertNotNull(policy);
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
assertEquals(LocalDate.now(), password.getValidFrom());
assertEquals(identity.getId(), password.getIdentity());
// when not exists default validation policy valid till be null
assertNull(password.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordValidationPolicy.
@Test
public void testCreatePasswordValidationPolicy() {
getTestPolicy(false, IdmPasswordPolicyType.VALIDATE, 365);
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
assertEquals(LocalDate.now(), password.getValidFrom());
assertEquals(identity.getId(), password.getIdentity());
assertNull(password.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordNoPolicy.
@Test
public void testCreatePasswordNoPolicy() {
IdmIdentityDto identity = testHelper.createIdentity();
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
assertEquals(LocalDate.now(), password.getValidFrom());
assertEquals(identity.getId(), password.getIdentity());
assertNull(password.getValidTill());
}
Aggregations