use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto 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.SysRoleSystemDto 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.SysRoleSystemDto 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());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemServiceFilterTest method testSystemIdFilter.
@Test
public void testSystemIdFilter() {
IdmRoleDto role1 = helper.createRole();
IdmRoleDto role2 = helper.createRole();
SysSystemDto system1 = helper.createTestResourceSystem(true);
SysSystemDto system2 = helper.createTestResourceSystem(true);
//
SysSystemMappingDto sysSystemMapping1Dto = mappingService.findBySystemId(system1.getId(), SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
SysSystemMappingDto sysSystemMapping2Dto = mappingService.findBySystemId(system2.getId(), SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
createRoleSystem(role1.getId(), system1.getId(), sysSystemMapping1Dto.getId());
SysRoleSystemDto roleSystem2 = createRoleSystem(role2.getId(), system2.getId(), sysSystemMapping2Dto.getId());
//
SysRoleSystemFilter roleFilter = new SysRoleSystemFilter();
roleFilter.setSystemId(system2.getId());
Page<SysRoleSystemDto> pages = roleSystemService.find(roleFilter, null);
//
assertEquals(1, pages.getTotalElements());
assertEquals(roleSystem2.getId(), pages.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemServiceFilterTest method createRoleSystem.
/**
* Create {@link SysRoleSystemDto}
*
* @param roleId
* @param systemId
* @param systemMappingId
* @return
*/
private SysRoleSystemDto createRoleSystem(UUID roleId, UUID systemId, UUID systemMappingId) {
helper.createRole();
SysRoleSystemDto role = new SysRoleSystemDto();
role.setRole(roleId);
role.setSystem(systemId);
role.setSystemMapping(systemMappingId);
return roleSystemService.save(role);
}
Aggregations