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
}
}
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, "Password change dto is required.");
//
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
LoginDto loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(passwordChangeDto.getOldPassword());
// password is changed => prevent to validate this flag again
loginDto.setSkipMustChange(true);
//
boolean successChainValidation = authenticationManager.validate(loginDto);
if (!successChainValidation) {
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 DefaultIdmPasswordPolicyServiceIntegrationTest method testContainsUsername.
@Test
public void testContainsUsername() {
IdmIdentityDto identity = this.getHelper().createIdentity("John217", (GuardedString) null);
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setEnchancedControl(true);
policy.setIdentityAttributeCheck(IdmIdentity_.username.getName().toUpperCase());
// Equals
IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
validation.setIdentity(identity);
validation.setPassword(identity.getUsername());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Prefix with lower
validation.setPassword("123" + identity.getUsername().toLowerCase());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Suffix with upper
validation.setPassword(identity.getUsername().toUpperCase() + System.currentTimeMillis());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Suffix and prefix with accent
validation.setPassword("demojÓhn217" + System.currentTimeMillis());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Prefix with accent
validation.setPassword("demojÓhň217");
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Success prefix
validation.setPassword("demojoh");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
// Success suffix with accent
validation.setPassword("jóhdemo");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
// Compound username
identity.setUsername("Dobromila-,Josefa_\tM.");
identityService.save(identity);
validation.setPassword("joseFadobrómílá");
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Success compound username
validation.setPassword("josefmJeLidumil");
try {
passwordPolicyService.validate(validation, policy);
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method testContainsEmail.
@Test
public void testContainsEmail() {
String email = "repa@example.tld";
IdmIdentityDto identity = this.getHelper().createIdentity((GuardedString) null);
identity.setEmail(email);
identity = identityService.save(identity);
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setEnchancedControl(true);
policy.setIdentityAttributeCheck(IdmIdentity_.email.getName().toUpperCase());
// Equals
IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
validation.setIdentity(identity);
validation.setPassword(email);
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Prefix with lower
validation.setPassword("123" + email.toLowerCase());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Suffix with upper
validation.setPassword(email.toUpperCase() + System.currentTimeMillis());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Suffix and prefix with accent
validation.setPassword("demořěpá@example.tld" + System.currentTimeMillis());
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Prefix with accent
validation.setPassword("demoŘĚPÁ@example");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password pass.");
} catch (Exception e) {
fail(e.getMessage());
}
// Success prefix
validation.setPassword("demorepa@example.");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
// Success suffix with accent
validation.setPassword("@example.tdldemo");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
// Success suffix with accent
validation.setPassword("@");
try {
passwordPolicyService.validate(validation, policy);
// Success
} catch (ResultCodeException e) {
fail("Password not pass.");
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations