use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class ProvisioningMergeTest method testSkipMergeValueIfContractExcluded.
@Test
public void testSkipMergeValueIfContractExcluded() {
SysSystemDto system = helper.createSystem("test_resource");
SysSystemMappingDto mapping = helper.createMapping(system);
IdmRoleDto roleOne = helper.createRole();
IdmRoleDto roleTwo = helper.createRole();
SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
rightsSchemaAttribute.setMultivalued(true);
rightsSchemaAttribute.setClassType(String.class.getName());
rightsSchemaAttribute.setReadable(true);
rightsSchemaAttribute.setUpdateable(true);
rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
rightsAttribute.setSystemMapping(mapping.getId());
rightsAttribute.setName(RIGHTS_ATTRIBUTE);
rightsAttribute.setStrategyType(AttributeMappingStrategyType.MERGE);
rightsAttribute = attributeMappingService.save(rightsAttribute);
SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
roleAttributeOne.setEntityAttribute(false);
roleAttributeOne.setExtendedAttribute(false);
roleAttributeOne.setRoleSystem(roleSystemOne.getId());
roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
List<Serializable> controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
roleAttributeTwo.setEntityAttribute(false);
roleAttributeTwo.setExtendedAttribute(false);
roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
assertNotNull(controlledAttributeValues);
assertEquals(2, controlledAttributeValues.size());
assertTrue(controlledAttributeValues.contains(ONE_VALUE));
assertTrue(controlledAttributeValues.contains(TWO_VALUE));
SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
attributeControlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
List<Serializable> historicControlledValues = //
attributeControlledValueService.find(attributeControlledValueFilter, //
null).getContent().stream().map(//
SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
assertNotNull(historicControlledValues);
assertEquals(0, historicControlledValues.size());
IdmIdentityDto identity = this.getHelper().createIdentity();
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
// Set contract as excluded
contract.setState(ContractState.EXCLUDED);
contract = identityContractService.save(contract);
assertTrue(contract.isExcluded());
this.getHelper().createIdentityRole(identity, roleOne);
this.getHelper().createIdentityRole(identity, roleTwo);
SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
operationFilter.setEntityIdentifier(identity.getId());
List<SysProvisioningArchiveDto> archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
assertEquals(1, archives.size());
SysProvisioningArchiveDto archive = archives.get(0);
assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
ProvisioningContext provisioningContext = archive.getProvisioningContext();
Map<ProvisioningAttributeDto, Object> accountObject = provisioningContext.getAccountObject();
Entry<ProvisioningAttributeDto, Object> attributeEntry = accountObject.entrySet().stream().filter(entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
List<?> values = (List<?>) attributeEntry.getValue();
assertEquals(2, values.size());
// Set attribute TWO to skip value if contract is excluded
roleAttributeTwo.setSkipValueIfExcluded(true);
roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
// Save identity -> execute provisioning
identityService.save(identity);
archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
assertEquals(1, archives.size());
archive = archives.get(0);
assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
provisioningContext = archive.getProvisioningContext();
accountObject = provisioningContext.getAccountObject();
attributeEntry = //
accountObject.entrySet().stream().filter(//
entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
values = (List<?>) attributeEntry.getValue();
assertEquals(1, values.size());
assertEquals(ONE_VALUE, values.get(0));
// Set contract as not excluded
contract.setState(null);
contract = identityContractService.save(contract);
assertFalse(contract.isExcluded());
// Save identity -> execute provisioning
identityService.save(identity);
archives = provisioningArchiveService.find(operationFilter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName()))).getContent();
assertEquals(1, archives.size());
archive = archives.get(0);
assertEquals(ProvisioningEventType.UPDATE, archive.getOperationType());
provisioningContext = archive.getProvisioningContext();
accountObject = provisioningContext.getAccountObject();
attributeEntry = //
accountObject.entrySet().stream().filter(//
entry -> RIGHTS_ATTRIBUTE.equals(entry.getKey().getSchemaAttributeName())).findFirst().get();
values = (List<?>) attributeEntry.getValue();
assertEquals(2, values.size());
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedDisabledTest.
@Test
@Transactional
public void compileAttributesOverrloadedDisabledTest() {
List<AttributeMapping> defaultAttributes = new ArrayList<>();
List<SysRoleSystemAttributeDto> overloadingAttributes = new ArrayList<>();
initDataSystem();
SysSchemaAttributeDto attOne = new SysSchemaAttributeDto();
attOne.setName("attOne");
attOne.setObjectClass(objectClasses.get(0).getId());
attOne.setClassType(String.class.getName());
attOne = schemaAttributeService.save(attOne);
SysSchemaAttributeDto attTwo = new SysSchemaAttributeDto();
attTwo.setName("attTwo");
attTwo.setObjectClass(objectClasses.get(0).getId());
attTwo.setClassType(String.class.getName());
attTwo = schemaAttributeService.save(attTwo);
SysSystemAttributeMappingDto defOne = new SysSystemAttributeMappingDto();
defOne.setEntityAttribute(true);
defOne.setIdmPropertyName("one");
defOne.setName("defOne");
defOne.setDisabledAttribute(true);
defOne.setSchemaAttribute(attOne.getId());
defOne.setSystemMapping(systemMapping.getId());
defOne = systemAttributeMappingService.save(defOne);
defaultAttributes.add(defOne);
SysSystemAttributeMappingDto defTwo = new SysSystemAttributeMappingDto();
defTwo.setEntityAttribute(true);
defTwo.setIdmPropertyName("two");
defTwo.setName("defTwo");
defTwo.setSchemaAttribute(attTwo.getId());
defTwo.setSystemMapping(systemMapping.getId());
defTwo = systemAttributeMappingService.save(defTwo);
defaultAttributes.add(defTwo);
IdmRoleDto roleOne = new IdmRoleDto();
roleOne.setCode("roleOne");
roleOne.setPriority(100);
roleOne = roleService.save(roleOne);
SysRoleSystemDto roleSystem = new SysRoleSystemDto();
roleSystem.setRole(roleOne.getId());
roleSystem.setSystem(system.getId());
roleSystem.setSystemMapping(systemMapping.getId());
roleSystem = roleSystemService.save(roleSystem);
SysRoleSystemAttributeDto overloadedOne = new SysRoleSystemAttributeDto();
overloadedOne.setSystemAttributeMapping(defOne.getId());
overloadedOne.setEntityAttribute(true);
overloadedOne.setIdmPropertyName("one");
overloadedOne.setName("defOneOverloaded");
overloadedOne.setDisabledDefaultAttribute(false);
overloadedOne.setRoleSystem(roleSystem.getId());
overloadedOne = roleSystemAttributeService.save(overloadedOne);
overloadingAttributes.add(overloadedOne);
List<AttributeMapping> compilledAttributes = provisioningService.compileAttributes(defaultAttributes, overloadingAttributes, SystemEntityType.IDENTITY);
Assert.assertEquals(2, compilledAttributes.size());
Assert.assertTrue(compilledAttributes.stream().filter(attribute -> {
return "defOneOverloaded".equals(attribute.getName());
}).findFirst().isPresent());
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingServiceTest method transformationFromScriptFailure.
@Test
public void transformationFromScriptFailure() {
SysSystemDto system = createSystem();
SysSchemaObjectClassDto objClass = createObjectClass(system);
SysSchemaAttributeDto schemaAttr = createSchemaAttribute(objClass);
SysSystemMappingDto systemMapping = testHelper.createMappingSystem(SystemEntityType.IDENTITY, objClass);
SysSystemAttributeMappingDto attrMapping = createAttributeMappingSystem(systemMapping, AttributeMappingStrategyType.CREATE, schemaAttr.getId());
// script consists of just one missing symbol,
// which is supposed to be part of error message
String script = "xxxxx";
attrMapping.setTransformFromResourceScript(script);
systemMapping = mappingService.save(systemMapping);
try {
attributeMappingService.transformValueFromResource("testValue", attrMapping, new ArrayList<IcAttribute>());
fail();
} catch (ResultCodeException ex) {
ErrorModel errModel = ex.getError().getError();
String message = (String) errModel.getParameters().get(SysSystemAttributeMappingService.MAPPING_SCRIPT_FAIL_MESSAGE_KEY);
String idmPath = (String) errModel.getParameters().get(SysSystemAttributeMappingService.MAPPING_SCRIPT_FAIL_IDM_PATH_KEY);
assertEquals(errModel.getStatusEnum(), AccResultCode.GROOVY_SCRIPT_ATTR_TRANSFORMATION_FAILED.getCode());
assertTrue(message.contains(script));
assertTrue(idmPath.contains(system.getCode()));
assertTrue(idmPath.contains(systemMapping.getName()));
assertTrue(idmPath.contains(attrMapping.getName()));
} catch (Exception e) {
fail();
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingServiceTest method textFilterTest.
@Test
public void textFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
AttributeMappingStrategyType strategyType = AttributeMappingStrategyType.MERGE;
SysSystemDto system = createSystem();
SysSchemaObjectClassDto objectClass = createObjectClass(system);
SysSystemMappingDto systemMapping = testHelper.createMappingSystem(entityType, objectClass);
SysSchemaAttributeDto schemaAttribute = createSchemaAttribute(objectClass);
SysSystemAttributeMappingDto attributeMapping1 = createAttributeMappingSystem(systemMapping, strategyType, schemaAttribute.getId());
attributeMapping1.setName("OriginalName01");
attributeMappingService.save(attributeMapping1);
SysSystemAttributeMappingDto attributeMapping2 = createAttributeMappingSystem(systemMapping, AttributeMappingStrategyType.CREATE, schemaAttribute.getId());
attributeMapping2.setName("OriginalName21");
attributeMappingService.save(attributeMapping2);
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setText("OriginalName0");
Page<SysSystemAttributeMappingDto> result = attributeMappingService.find(filter, null, permission);
assertEquals(1, result.getTotalElements());
assertTrue(result.getContent().contains(attributeMapping1));
assertFalse(result.getContent().contains(attributeMapping2));
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingServiceTest method isUidFitlerTest.
@Test
public void isUidFitlerTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
AttributeMappingStrategyType strategyType = AttributeMappingStrategyType.MERGE;
SysSystemDto system = createSystem();
SysSchemaObjectClassDto objectClass = createObjectClass(system);
SysSystemMappingDto systemMapping1 = testHelper.createMappingSystem(entityType, objectClass);
SysSystemMappingDto systemMapping2 = testHelper.createMappingSystem(entityType, objectClass);
SysSchemaAttributeDto schemaAttribute = createSchemaAttribute(objectClass);
SysSystemAttributeMappingDto attributeMapping1 = createAttributeMappingSystem(systemMapping1, AttributeMappingStrategyType.CREATE, schemaAttribute.getId());
SysSystemAttributeMappingDto attributeMapping2 = createAttributeMappingSystem(systemMapping2, strategyType, schemaAttribute.getId());
attributeMapping2.setUid(true);
attributeMappingService.save(attributeMapping2);
createAttributeMappingSystem(systemMapping1, AttributeMappingStrategyType.SET, schemaAttribute.getId());
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setIsUid(true);
filter.setSystemId(system.getId());
Page<SysSystemAttributeMappingDto> result = attributeMappingService.find(filter, null, permission);
assertEquals(1, result.getTotalElements());
assertTrue(result.getContent().contains(attributeMapping2));
assertFalse(result.getContent().contains(attributeMapping1));
}
Aggregations