use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningExtendedAttribute.
@Test
public void doIdentityProvisioningExtendedAttribute() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
// We will use firstName attribute (password attribute is not returned
// by default)
SysSystemAttributeMappingFilter filterSchemaAttr = new SysSystemAttributeMappingFilter();
filterSchemaAttr.setIdmPropertyName("firstName");
filterSchemaAttr.setSystemId(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemAttributeMappingDto attributeHandling = systemAttributeMappingService.find(filterSchemaAttr, null).getContent().get(0);
// Set attribute to extended attribute and modify idmPropety to
// extPassword
attributeHandling.setIdmPropertyName(IDENTITY_EXT_PASSWORD);
attributeHandling.setExtendedAttribute(true);
attributeHandling.setConfidentialAttribute(true);
attributeHandling.setEntityAttribute(false);
attributeHandling.setTransformToResourceScript("return attributeValue");
// Form attribute definition will be created during save attribute
// handling
attributeHandling = systemAttributeMappingService.save(attributeHandling);
// Create extended attribute value for password
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto phoneValue = new IdmFormValueDto();
phoneValue.setFormAttribute(formDefinition.getMappedAttributeByCode(IDENTITY_EXT_PASSWORD).getId());
phoneValue.setStringValue(IDENTITY_PASSWORD_THREE);
values.add(phoneValue);
formService.saveValues(identityRepository.findOne(identity.getId()), formDefinition, values);
// save account
provisioningService.doProvisioning(identity);
TestResource resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(IDENTITY_PASSWORD_THREE, resourceAccoutn.getFirstname());
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto 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.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningStrategyIfNull.
@Test
public void doIdentityProvisioningStrategyIfNull() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
// Default email strategy is CREATE, we check value
TestResource resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(EMAIL_ONE, resourceAccoutn.getEmail());
SysSystemAttributeMappingFilter filterSchemaAttr = new SysSystemAttributeMappingFilter();
filterSchemaAttr.setIdmPropertyName("email");
filterSchemaAttr.setSystemId(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemAttributeMappingDto attributeHandling = systemAttributeMappingService.find(filterSchemaAttr, null).getContent().get(0);
attributeHandling.setEntityAttribute(true);
attributeHandling.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL);
attributeHandling.setTransformToResourceScript("return \"" + EMAIL_TWO + "\";");
systemAttributeMappingService.save(attributeHandling);
// Do provisioning
provisioningService.doProvisioning(identity);
// Email strategy is WRITE_IF_NULL ... email in account must not have new value
resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotEquals(EMAIL_TWO, resourceAccoutn.getEmail());
attributeHandling.setEntityAttribute(true);
attributeHandling.setStrategyType(AttributeMappingStrategyType.SET);
attributeHandling.setTransformToResourceScript("return \"" + EMAIL_TWO + "\";");
systemAttributeMappingService.save(attributeHandling);
// Do provisioning
provisioningService.doProvisioning(identity);
// Email strategy is SET ... email in account must have new value
resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(EMAIL_TWO, resourceAccoutn.getEmail());
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningStrategyMergeException.
// Expected PROVISIONING_MERGE_ATTRIBUTE_IS_NOT_MULTIVALUE
@Test(expected = ProvisioningException.class)
public void doIdentityProvisioningStrategyMergeException() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
SysSystemAttributeMappingFilter filterSchemaAttr = new SysSystemAttributeMappingFilter();
filterSchemaAttr.setIdmPropertyName("email");
filterSchemaAttr.setSystemId(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemAttributeMappingDto attributeHandling = systemAttributeMappingService.find(filterSchemaAttr, null).getContent().get(0);
attributeHandling.setEntityAttribute(true);
attributeHandling.setStrategyType(AttributeMappingStrategyType.MERGE);
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(attributeHandling.getSchemaAttribute());
schemaAttributeDto.setMultivalued(false);
schemaAttributeService.save(schemaAttributeDto);
systemAttributeMappingService.save(attributeHandling);
// Do provisioning
provisioningService.doProvisioning(identity);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingServiceTest method createAttributeMappingSystem.
private SysSystemAttributeMappingDto createAttributeMappingSystem(SysSystemMappingDto systemMapping, AttributeMappingStrategyType mappingStrategyType, UUID schemaAttribute) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setName("Name" + UUID.randomUUID());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping.setSchemaAttribute(schemaAttribute);
attributeMapping.setStrategyType(mappingStrategyType);
attributeMapping.setUid(false);
return attributeMappingService.save(attributeMapping);
}
Aggregations