use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class PasswordPreValidationIntegrationTest method testLenght.
@Test
public void testLenght() {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("test" + System.currentTimeMillis());
identity.setFirstName("testFirst");
identity.setLastName("testSecond");
identity = idmIdentityService.save(identity);
//
SysSystemDto system = testHelper.createTestResourceSystem(true);
//
AccAccountDto acc = new AccAccountDto();
acc.setId(UUID.randomUUID());
acc.setUid(System.currentTimeMillis() + "");
acc.setAccountType(AccountType.PERSONAL);
acc.setSystem(system.getId());
//
acc = accountService.save(acc);
//
AccIdentityAccountDto account = testHelper.createIdentityAccount(system, identity);
account.setAccount(acc.getId());
account.setOwnership(true);
account = accountIdentityService.save(account);
List<String> accounts = new ArrayList<String>();
accounts.add(acc.getId() + "");
// password policy default
IdmPasswordPolicyDto policyDefault = new IdmPasswordPolicyDto();
policyDefault.setName(System.currentTimeMillis() + "test1");
policyDefault.setDefaultPolicy(true);
policyDefault.setMinPasswordLength(5);
policyDefault.setMaxPasswordLength(10);
// password policy
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName(System.currentTimeMillis() + "test2");
policy.setDefaultPolicy(false);
policy.setMinPasswordLength(6);
policy.setMaxPasswordLength(11);
policyDefault = passwordPolicyService.save(policyDefault);
policy = passwordPolicyService.save(policy);
system.setPasswordPolicyValidate(policy.getId());
systemService.save(system);
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setAccounts(accounts);
passwordChange.setAll(true);
try {
idmIdentityService.validatePassword(passwordChange);
} catch (ResultCodeException ex) {
assertEquals(6, ex.getError().getError().getParameters().get("minLength"));
assertEquals(10, ex.getError().getError().getParameters().get("maxLength"));
assertEquals(policy.getName() + ", " + policyDefault.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
assertEquals(3, ex.getError().getError().getParameters().size());
policyDefault.setDefaultPolicy(false);
passwordPolicyService.save(policyDefault);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class IdentityPasswordPreValidateDefinitionProcessor method process.
@Override
public EventResult<PasswordChangeDto> process(EntityEvent<PasswordChangeDto> event) {
PasswordChangeDto passwordChangeDto = event.getContent();
IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
List<IdmPasswordPolicyDto> passwordPolicyList = validateDefinition(passwordChangeDto);
this.passwordPolicyService.preValidate(passwordValidationDto, passwordPolicyList);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method initData.
private void initData() {
IdmIdentityDto identity;
AccAccountDto accountOne;
AccIdentityAccountDto accountIdentityOne;
// create test system
SysSystemDto system = helper.createSystem(TestResource.TABLE_NAME, SYSTEM_NAME);
// set default generate password policy for system
IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
passwordPolicy.setName(PASSWORD_POLICY);
passwordPolicy.setType(IdmPasswordPolicyType.GENERATE);
passwordPolicy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
passwordPolicy.setLowerCharBase("a");
passwordPolicy.setMinPasswordLength(2);
passwordPolicy.setMaxPasswordLength(2);
passwordPolicy.setMinLowerChar(2);
passwordPolicy = passwordPolicyService.save(passwordPolicy);
system.setPasswordPolicyGenerate(passwordPolicy.getId());
system = systemService.save(system);
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create test identity for provisioning test
identity = new IdmIdentityDto();
identity.setUsername(IDENTITY_USERNAME);
identity.setFirstName(IDENTITY_USERNAME);
identity.setLastName(IDENTITY_USERNAME);
identity = idmIdentityService.save(identity);
accountOne = new AccAccountDto();
accountOne.setSystem(system.getId());
accountOne.setUid("x" + IDENTITY_USERNAME);
accountOne.setAccountType(AccountType.PERSONAL);
accountOne.setEntityType(SystemEntityType.IDENTITY);
accountOne = accountService.save(accountOne);
accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
IdmIdentityDto identityTwo = new IdmIdentityDto();
identityTwo.setUsername(IDENTITY_USERNAME_TWO);
identityTwo.setFirstName(IDENTITY_USERNAME_TWO);
identityTwo.setLastName(IDENTITY_USERNAME_TWO);
identityTwo = idmIdentityService.save(identityTwo);
AccAccountDto accountTwo = new AccAccountDto();
accountTwo.setSystem(system.getId());
accountTwo.setUid("x" + IDENTITY_USERNAME_TWO);
accountTwo.setAccountType(AccountType.PERSONAL);
accountTwo.setEntityType(SystemEntityType.IDENTITY);
accountTwo = accountService.save(accountTwo);
AccIdentityAccountDto accountIdentityTwo = new AccIdentityAccountDto();
accountIdentityTwo.setIdentity(identityTwo.getId());
accountIdentityTwo.setOwnership(true);
accountIdentityTwo.setAccount(accountTwo.getId());
accountIdentityTwo = identityAccoutnService.save(accountIdentityTwo);
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto entityHandlingResult = systemEntityHandlingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
schemaAttributesPage.forEach(schemaAttr -> {
if ("__NAME__".equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(true);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName(IdmIdentity_.username.getName());
attributeMapping.setTransformToResourceScript("if(attributeValue){return \"x\"+ attributeValue;}");
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
} else if ("firstname".equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.firstName.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setTransformFromResourceScript("if(attributeValue){return attributeValue.substring(1);}");
attributeMapping.setSystemMapping(entityHandlingResult.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
} else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.lastName.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
} else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("password");
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
} else if ("email".equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.email.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setStrategyType(AttributeMappingStrategyType.CREATE);
attributeMapping.setSystemMapping(entityHandlingResult.getId());
attributeMapping.setTransformToResourceScript("return \"" + EMAIL_ONE + "\";");
attributeMapping = systemAttributeMappingService.save(attributeMapping);
}
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyIntegrationTest method testCreateTwoDefaultPolicy.
@Test
public void testCreateTwoDefaultPolicy() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName("test_18_default");
policy.setType(IdmPasswordPolicyType.VALIDATE);
policy.setDefaultPolicy(true);
policy = saveInTransaction(policy, passwordPolicyService);
IdmPasswordPolicyDto defaultValidatePolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
assertEquals(policy.getId(), defaultValidatePolicy.getId());
assertEquals(policy.getName(), defaultValidatePolicy.getName());
assertEquals(policy.getType(), defaultValidatePolicy.getType());
IdmPasswordPolicyDto policyNew = new IdmPasswordPolicyDto();
policyNew.setName("test_19_default");
policyNew.setType(IdmPasswordPolicyType.VALIDATE);
policyNew.setDefaultPolicy(true);
policyNew = saveInTransaction(policyNew, passwordPolicyService);
defaultValidatePolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
assertEquals(policyNew.getId(), defaultValidatePolicy.getId());
assertEquals(policyNew.getName(), defaultValidatePolicy.getName());
assertEquals(policyNew.getType(), defaultValidatePolicy.getType());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto 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
}
}
Aggregations