use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method testMinCharacterCountExplicitlySetZero.
@Test
public void testMinCharacterCountExplicitlySetZero() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_20");
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setMinPasswordLength(0);
policy.setMinNumber(0);
policy.setMinLowerChar(0);
policy.setMinSpecialChar(0);
policy.setMinUpperChar(0);
IdmPasswordValidationDto password = new IdmPasswordValidationDto();
try {
password.setPassword("asdfg12345###");
this.passwordPolicyService.validate(password, policy);
password.setPassword("");
this.passwordPolicyService.validate(password, policy);
password.setPassword("123456@#$%^&*ASDFGHJK");
this.passwordPolicyService.validate(password, policy);
} catch (Exception e) {
// nothing, success
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method testContainsCombination.
@Test
public void testContainsCombination() {
String firstName = "DěmÓ";
String lastName = "Těšť";
String username = "ExámplÉ";
IdmIdentityDto identity = this.getHelper().createIdentity((GuardedString) null);
identity.setFirstName(firstName);
identity.setUsername(username);
identity.setLastName(lastName);
identity = identityService.save(identity);
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setEnchancedControl(true);
policy.setIdentityAttributeCheck(IdmIdentity_.firstName.getName().toUpperCase() + ", " + IdmIdentity_.username.getName().toUpperCase());
// Equals
IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
validation.setIdentity(identity);
validation.setPassword(firstName);
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Equals
validation.setPassword(username);
try {
passwordPolicyService.validate(validation, policy);
fail("Password pass.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
// Equals with not controlled
validation.setPassword(lastName);
try {
passwordPolicyService.validate(validation, policy);
// Success
} 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 IdentityPasswordValidateProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
IdmIdentityDto identity = event.getContent();
//
Assert.notNull(passwordChangeDto, "Password change dto is required.");
Assert.notNull(identity, "Identity is required.");
//
LOG.debug("Call validate password for systems and default password policy for identity username [{}]", event.getContent().getUsername());
//
List<IdmPasswordPolicyDto> passwordPolicyList = validateDefinition(identity, passwordChangeDto);
//
// Find user accounts
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, null).getContent();
//
if (!securityService.isAdmin()) {
// check accounts and property all_only
PasswordChangeType passwordChangeType = identityConfiguration.getPasswordChangeType();
if (passwordChangeType == PasswordChangeType.ALL_ONLY) {
// get distinct account ids from identity accounts
List<String> accountIds = identityAccounts.stream().filter(identityAccount -> {
// filter by ownership
return (identityAccount.isOwnership());
}).map(AccIdentityAccountDto::getAccount).map(UUID::toString).collect(Collectors.toList());
//
if (!accountIds.isEmpty() && !passwordChangeDto.getAccounts().isEmpty()) {
// size of the found accounts must match the account size in the password change - ALL_ONLY
boolean containsAll = accountIds.size() == passwordChangeDto.getAccounts().size();
if (!containsAll) {
throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_ALL_ONLY);
}
}
}
}
//
// validate
IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
// get old password for validation - till, from and password history
IdmPasswordDto oldPassword = this.passwordService.findOneByIdentity(identity.getId());
passwordValidationDto.setOldPassword(oldPassword == null ? null : oldPassword.getId());
passwordValidationDto.setIdentity(identity);
passwordValidationDto.setPassword(passwordChangeDto.getNewPassword());
this.passwordPolicyService.validate(passwordValidationDto, passwordPolicyList);
//
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
}
}
Aggregations