use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto 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.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class IdentityCreatePasswordValidateProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
GuardedString password = event.getContent().getPassword();
IdmIdentityDto identity = event.getContent();
// when create identity password can be null
if (password != null) {
IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
passwordValidationDto.setPassword(password);
passwordValidationDto.setIdentity(identity);
// validate create new password by default password policy
this.passwordPolicyService.validate(passwordValidationDto);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testValidationProhibitedChars.
@Test
public void testValidationProhibitedChars() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_14");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(5);
policy.setMinPasswordLength(1);
policy.setProhibitedCharacters("12abcDEF!@");
IdmPasswordValidationDto password = new IdmPasswordValidationDto();
try {
password.setPassword("test");
this.passwordPolicyService.validate(password, policy);
password.setPassword("ABde");
this.passwordPolicyService.validate(password, policy);
} catch (Exception e) {
fail("Password validate prohibited characters. " + policy);
}
try {
password.setPassword("tEst");
this.passwordPolicyService.validate(password, policy);
fail("Password validate prohibited characters. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("eddD");
this.passwordPolicyService.validate(password, policy);
fail("Password validate prohibited characters. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("5416");
this.passwordPolicyService.validate(password, policy);
fail("Password validate prohibited characters. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("test!");
this.passwordPolicyService.validate(password, policy);
fail("Password validate prohibited characters. " + policy);
} catch (Exception e) {
// nothing, success
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testValidateSpecialChar.
@Test
public void testValidateSpecialChar() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_13");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(3);
policy.setMinPasswordLength(1);
policy.setMinSpecialChar(2);
IdmPasswordValidationDto password = new IdmPasswordValidationDto();
try {
password.setPassword("!@");
this.passwordPolicyService.validate(password, policy);
password.setPassword("!@#");
this.passwordPolicyService.validate(password, policy);
password.setPassword("!@a");
this.passwordPolicyService.validate(password, policy);
} catch (Exception e) {
fail("Password validation special chars. " + e.getMessage());
}
try {
password.setPassword("!");
this.passwordPolicyService.validate(password, policy);
fail("Password validation special chars. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("!@#$");
this.passwordPolicyService.validate(password, policy);
fail("Password validation special chars. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("test");
this.passwordPolicyService.validate(password, policy);
fail("Password validation special chars. " + policy);
} catch (Exception e) {
// nothing, success
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testValidateBase.
@Test
public void testValidateBase() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_15");
policy.setType(IdmPasswordPolicyType.GENERATE);
policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
policy.setMaxPasswordLength(5);
policy.setMinPasswordLength(1);
policy.setNumberBase("123");
policy.setMinNumber(3);
IdmPasswordValidationDto password = new IdmPasswordValidationDto();
try {
password.setPassword("123");
this.passwordPolicyService.validate(password, policy);
password.setPassword("1234");
this.passwordPolicyService.validate(password, policy);
password.setPassword("111");
this.passwordPolicyService.validate(password, policy);
} catch (Exception e) {
fail("Password base validation. " + policy);
}
try {
password.setPassword("124");
this.passwordPolicyService.validate(password, policy);
fail("Password base validation. " + policy);
} catch (Exception e) {
// nothing, success
}
try {
password.setPassword("456");
this.passwordPolicyService.validate(password, policy);
fail("Password base validation. " + policy);
} catch (Exception e) {
// nothing, success
}
}
Aggregations