use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedStrategyMergeTest.
@Test
@Transactional
public void compileAttributesOverrloadedStrategyMergeTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
// roleOne
SysRoleSystemDto roleSystem1 = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem1.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// roleTwo
SysRoleSystemDto roleSystem2 = roleSystemService.get(overloadingAttributes.get(1).getRoleSystem());
roleDto = roleService.get(roleSystem2.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// overloadedRoleOne
SysRoleSystemAttributeDto attribute1 = overloadingAttributes.get(0);
attribute1.setStrategyType(AttributeMappingStrategyType.MERGE);
attribute1 = roleSystemAttributeService.save(attribute1);
overloadingAttributes.set(0, attribute1);
// overloadedRoleTwo
SysRoleSystemAttributeDto attribute2 = overloadingAttributes.get(1);
attribute2.setStrategyType(AttributeMappingStrategyType.MERGE);
attribute2 = roleSystemAttributeService.save(attribute2);
overloadingAttributes.set(1, attribute2);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(3, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloadedRoleTwo".equals(attribute.getName());
}).findFirst().isPresent());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedStrategyMergeAuthoTest.
@Test
@Transactional
public void compileAttributesOverrloadedStrategyMergeAuthoTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
// roleOne
SysRoleSystemDto roleSystem1 = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem1.getRole());
roleDto.setPriority(200);
roleDto = roleService.save(roleDto);
// roleTwo
SysRoleSystemDto roleSystem2 = roleSystemService.get(overloadingAttributes.get(1).getRoleSystem());
roleDto = roleService.get(roleSystem2.getRole());
roleDto.setPriority(100);
roleDto = roleService.save(roleDto);
// overloadedRoleOne
SysRoleSystemAttributeDto attribute1 = overloadingAttributes.get(0);
attribute1.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
attribute1 = roleSystemAttributeService.save(attribute1);
overloadingAttributes.set(0, attribute1);
// overloadedRoleTwo
SysRoleSystemAttributeDto attribute2 = overloadingAttributes.get(1);
attribute2.setStrategyType(AttributeMappingStrategyType.AUTHORITATIVE_MERGE);
attribute2 = roleSystemAttributeService.save(attribute2);
overloadingAttributes.set(1, attribute2);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(3, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloadedRoleTwo".equals(attribute.getName());
}).findFirst().isPresent());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedSamePriorityTest.
@Test
@Transactional
public void compileAttributesOverrloadedSamePriorityTest() {
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
List<AttributeMapping> defaultAttributes = new ArrayList<>();
initDataSystem();
initOverloadedAttributes(overloadingAttributes, defaultAttributes);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloadedRoleTwo".equals(attribute.getName());
}).findFirst().isPresent());
// set name role One to zroleOne
SysRoleSystemDto roleSystem = roleSystemService.get(overloadingAttributes.get(0).getRoleSystem());
IdmRoleDto roleDto = roleService.get(roleSystem.getRole());
roleDto.setCode("zroleOne");
roleDto = roleService.save(roleDto);
roleSystem = roleSystemService.save(roleSystem);
List<SysRoleSystemAttributeDto> freshOverloadingAttributes = new ArrayList<>();
overloadingAttributes.forEach(attributeOver -> {
freshOverloadingAttributes.add(roleSystemAttributeService.get(attributeOver.getId()));
});
compilledAttributes = provisioningService.compileAttributes(defaultAttributes, freshOverloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloaded".equals(attribute.getName());
}).findFirst().isPresent());
// We set role mapping attribute to disabled, then must have higher
// "priority", then role mapping one
// and must missing in result
SysRoleSystemAttributeDto attribute = overloadingAttributes.get(1);
attribute.setDisabledDefaultAttribute(true);
attribute = roleSystemAttributeService.save(attribute);
overloadingAttributes.set(1, attribute);
List<SysRoleSystemAttributeDto> freshOverloadingAttributesTwo = new ArrayList<>();
overloadingAttributes.forEach(attributeOver -> {
freshOverloadingAttributes.add(roleSystemAttributeService.get(attributeOver.getId()));
});
compilledAttributes = provisioningService.compileAttributes(defaultAttributes, freshOverloadingAttributesTwo, SystemEntityType.IDENTITY);
Assert.assertEquals(1, compilledAttributes.size());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemAttributeServiceTest method testArchiveControledValuesAfterRoleIsDeleted.
@Test
public void testArchiveControledValuesAfterRoleIsDeleted() {
// prepare mapped attribute with controled value
IdmRoleDto role = helper.createRole();
SysSystemDto system = helper.createTestResourceSystem(true);
systemService.generateSchema(system);
//
// create eav attribute
String attributeName = helper.getSchemaColumnName("EAV_ATTRIBUTE");
SysSchemaAttributeFilter schemaAttFilter = new SysSchemaAttributeFilter();
schemaAttFilter.setSystemId(system.getId());
schemaAttFilter.setName(attributeName);
List<SysSchemaAttributeDto> schemaAttrs = schemaAttributeService.find(schemaAttFilter, null).getContent();
Assert.assertEquals(1, schemaAttrs.size());
SysSchemaAttributeDto schemaAttributeDto = schemaAttrs.get(0);
schemaAttributeDto.setMultivalued(true);
schemaAttributeDto = schemaAttributeService.save(schemaAttributeDto);
SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
schemaAttributeFilter.setName(attributeName);
List<SysSchemaAttributeDto> atts = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
Assert.assertEquals(1, atts.size());
SysSchemaAttributeDto sysSchemaAttributeEav = atts.get(0);
//
// create eav attribute mapping with merge
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setExtendedAttribute(true);
attributeMapping.setName(attributeName);
attributeMapping.setIdmPropertyName(attributeName);
attributeMapping.setStrategyType(AttributeMappingStrategyType.MERGE);
attributeMapping.setSchemaAttribute(sysSchemaAttributeEav.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
//
// role system mapping with merge value
SysRoleSystemDto roleSystem = helper.createRoleSystem(role, system);
SysRoleSystemAttributeDto overloadedRoleOne = new SysRoleSystemAttributeDto();
overloadedRoleOne.setSystemAttributeMapping(attributeMapping.getId());
overloadedRoleOne.setEntityAttribute(false);
overloadedRoleOne.setExtendedAttribute(true);
overloadedRoleOne.setStrategyType(AttributeMappingStrategyType.MERGE);
overloadedRoleOne.setName(attributeMapping.getName());
overloadedRoleOne.setDisabledDefaultAttribute(false);
overloadedRoleOne.setIdmPropertyName(attributeName);
overloadedRoleOne.setRoleSystem(roleSystem.getId());
String valueOne = helper.createName();
overloadedRoleOne.setTransformToResourceScript("return '" + valueOne + "';");
overloadedRoleOne = roleSystemAttributeService.save(overloadedRoleOne);
//
// assign role to identity
IdmIdentityDto identity = helper.createIdentity();
attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
IdmRoleRequestDto request = helper.createRoleRequest(identity, role);
request = helper.executeRequest(request, false, true);
UUID identityRoleId = request.getConceptRoles().get(0).getIdentityRole();
IdmIdentityRoleDto identityRole = identityRoleService.get(identityRoleId);
List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
Assert.assertEquals(1, accounts.size());
// Account was created, provisioning was finished, but attribute was still not
// recalculated, because provisioning for create of account doesn't need a
// controlled values, so attribute is not recalculated now.
attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
// Execute update provisioning -> executes recalculation of the attribute
identityService.save(identity);
attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
Assert.assertFalse(attributeMapping.isEvictControlledValuesCache());
//
// find controlled values
SysAttributeControlledValueFilter valueFilter = new SysAttributeControlledValueFilter();
valueFilter.setAttributeMappingId(attributeMapping.getId());
List<SysAttributeControlledValueDto> controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
Assert.assertEquals(1, controlledValues.size());
Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
// try to delete role => role is still assigned
try {
roleService.delete(role);
} catch (ResultCodeException ex) {
Assert.assertEquals(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED.getCode(), ((ResultCodeException) ex).getError().getError().getStatusEnum());
}
//
controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
Assert.assertEquals(1, controlledValues.size());
Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
Assert.assertTrue(controlledValues.stream().allMatch(v -> !v.isHistoricValue()));
//
// remove assigned role and remove role with controller values
identityRoleService.delete(identityRole);
roleService.delete(role);
attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
// Manual recalculation of the attribute
systemAttributeMappingService.recalculateAttributeControlledValues(system.getId(), SystemEntityType.IDENTITY, attributeName, attributeMapping);
// Attribute must be recalculated now
attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
Assert.assertFalse(attributeMapping.isEvictControlledValuesCache());
//
controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
Assert.assertEquals(1, controlledValues.size());
Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
Assert.assertTrue(controlledValues.stream().allMatch(v -> v.isHistoricValue()));
//
// delete system (referential integrity just for sure)
systemService.delete(system);
controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
Assert.assertTrue(controlledValues.isEmpty());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemAttributeServiceTest method testAddRoleMappingAttribute.
@Test
public void testAddRoleMappingAttribute() {
IdmRoleDto role = helper.createRole();
SysSystemDto system = helper.createTestResourceSystem(true);
SysRoleSystemAttributeDto attribute = roleSystemAttributeService.addRoleMappingAttribute(system.getId(), role.getId(), helper.getSchemaColumnName(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME), null, IcObjectClassInfo.ACCOUNT);
Assert.assertNotNull(attribute);
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
roleSystemFilter.setSystemId(system.getId());
List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilter, null).getContent();
Assert.assertEquals(1, roleSystems.size());
SysRoleSystemDto roleSystem = roleSystems.get(0);
SysSystemMappingDto systemMapping = roleSystemAttributeService.getSystemMapping(system.getId(), IcObjectClassInfo.ACCOUNT, SystemOperationType.PROVISIONING);
Assert.assertNotNull(systemMapping);
Assert.assertEquals(systemMapping.getId(), roleSystem.getSystemMapping());
}
Aggregations