use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysAttributeControlledValueService method setControlledValues.
@Transactional
@Override
public void setControlledValues(SysSystemAttributeMappingDto attributeMapping, List<Serializable> controlledAttributeValues) {
Assert.notNull(attributeMapping, "Attribute mapping is required.");
Assert.notNull(controlledAttributeValues, "Controlled values are required.");
SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
attributeControlledValueFilter.setAttributeMappingId(attributeMapping.getId());
attributeControlledValueFilter.setHistoricValue(Boolean.FALSE);
// Search controlled values for that attribute
List<SysAttributeControlledValueDto> controlledValues = //
this.find(attributeControlledValueFilter, null).getContent();
// Search values for which does not exists same controlled value (for given
// attribute)
List<Serializable> valuesToAdd = controlledAttributeValues.stream().filter(newValue -> {
//
return !//
controlledValues.stream().filter(//
controlledValue -> controlledValue.getValue().equals(newValue)).findFirst().isPresent();
}).collect(Collectors.toList());
// Search old controlled values which does not exists in new definition
List<SysAttributeControlledValueDto> controlledValuesToDelete = controlledValues.stream().filter(controlledValue -> {
//
return !//
controlledAttributeValues.stream().filter(//
newValue -> controlledValue.getValue().equals(newValue)).findFirst().isPresent();
}).collect(Collectors.toList());
// Delete old values
controlledValuesToDelete.forEach(controlledValue -> this.delete(controlledValue));
// Persists new controlled values
valuesToAdd.forEach(valueToAdd -> {
SysAttributeControlledValueDto controlledValue = new SysAttributeControlledValueDto();
controlledValue.setAttributeMapping(attributeMapping.getId());
controlledValue.setHistoricValue(false);
controlledValue.setValue(valueToAdd);
controlledValue = this.save(controlledValue);
});
// Search historic controlled values for that attribute
attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
List<SysAttributeControlledValueDto> historicControlledValues = //
this.find(attributeControlledValueFilter, //
null).getContent().stream().collect(Collectors.toList());
List<SysAttributeControlledValueDto> historicValuesToDelete = //
historicControlledValues.stream().filter(//
historicValue -> controlledAttributeValues.contains(historicValue.getValue())).collect(Collectors.toList());
// If historic value exists in current definition, then will be deleted
historicValuesToDelete.forEach(historicValue -> {
this.delete(historicValue);
});
// Controlled values are synchronized now, so we can set evict to false
attributeMapping.setEvictControlledValuesCache(false);
systemAttributeMappingService.save(attributeMapping);
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysAttributeControlledValueService method addHistoricValue.
@Transactional
@Override
public void addHistoricValue(SysSystemAttributeMappingDto attributeMapping, Serializable value) {
// If value doesn't exists do nothing
if (ObjectUtils.isEmpty(value)) {
return;
}
Assert.notNull(attributeMapping, "Attribute mapping is required.");
SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
attributeControlledValueFilter.setAttributeMappingId(attributeMapping.getId());
attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
// Search historic values for that attribute
List<SysAttributeControlledValueDto> historicValues = //
this.find(attributeControlledValueFilter, null).getContent();
boolean historicValueExists = //
historicValues.stream().filter(//
historicValue -> historicValue.getValue().equals(value)).findFirst().isPresent();
if (!historicValueExists) {
SysAttributeControlledValueDto historicValue = new SysAttributeControlledValueDto();
historicValue.setAttributeMapping(attributeMapping.getId());
historicValue.setHistoricValue(true);
historicValue.setValue(value);
this.save(historicValue);
}
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter 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.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.
the class ProvisioningMergeTest method testChangeStrategyAttribteControlledValues.
@Test
public void testChangeStrategyAttribteControlledValues() {
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);
SysSchemaObjectClassDto objectClass = schemaService.get(mapping.getObjectClass());
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setObjectClassId(objectClass.getId());
schemaAttributeService.find(schemaAttributeFilter, null);
SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
rightsSchemaAttribute.setObjectClass(objectClass.getId());
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.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.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());
// Set attribute TWO as SET (should be disappears from controlled values
// and appears in the history)
roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.SET);
roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
assertNotNull(controlledAttributeValues);
assertEquals(1, controlledAttributeValues.size());
assertTrue(controlledAttributeValues.contains(ONE_VALUE));
// Search historic controlled values for that attribute
historicControlledValues = //
attributeControlledValueService.find(attributeControlledValueFilter, //
null).getContent().stream().map(//
SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
assertNotNull(historicControlledValues);
assertEquals(1, historicControlledValues.size());
assertTrue(historicControlledValues.contains(TWO_VALUE));
// Set attribute TWO as MERGE (should be appears in controlled values
// and disappears from the history)
roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
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));
// Manual recalculation (needed for deleting redundant historic value)
attributeMappingService.recalculateAttributeControlledValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE, rightsAttribute);
// Search historic controlled values for that attribute
historicControlledValues = //
attributeControlledValueService.find(attributeControlledValueFilter, //
null).getContent().stream().map(//
SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
assertNotNull(historicControlledValues);
assertEquals(0, historicControlledValues.size());
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method getCachedControlledAndHistoricAttributeValues.
@Override
public List<Serializable> getCachedControlledAndHistoricAttributeValues(UUID systemId, SystemEntityType entityType, String schemaAttributeName) {
Assert.notNull(systemId, "System ID is mandatory for get controlled values!");
Assert.notNull(entityType, "Entity type is mandatory for get controlled values!");
Assert.notNull(schemaAttributeName, "Schema attribute name is mandatory for get controlled values!");
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(systemId, entityType);
Assert.notNull(mapping, "System provisioning mapping is mandatory for search controlled attribute values!");
List<SysSystemAttributeMappingDto> attributes = this.getAttributeMapping(schemaAttributeName, mapping, systemId);
Assert.notEmpty(attributes, "Mapping attribute must exists!");
Assert.isTrue(attributes.size() == 1, "Only one mapping attribute is allowed for same schema attribute in the provisioning!");
SysSystemAttributeMappingDto attributeMapping = attributes.get(0);
SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
attributeControlledValueFilter.setAttributeMappingId(attributeMapping.getId());
attributeControlledValueFilter.setHistoricValue(Boolean.FALSE);
// Search controlled values for that attribute
List<Serializable> cachedControlledValues = //
attributeControlledValueService.find(attributeControlledValueFilter, //
null).getContent().stream().map(//
SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
if (attributeMapping.isEvictControlledValuesCache()) {
List<Serializable> controlledAttributeValues = recalculateAttributeControlledValues(systemId, entityType, schemaAttributeName, attributeMapping);
cachedControlledValues = controlledAttributeValues;
}
// Set filter for search historic values
attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
// Search historic controlled values for that attribute
List<Serializable> historicControlledValues = //
attributeControlledValueService.find(attributeControlledValueFilter, //
null).getContent().stream().map(//
SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
List<Serializable> controlledValues = Lists.newArrayList();
controlledValues.addAll(cachedControlledValues);
controlledValues.addAll(historicControlledValues);
return controlledValues;
}
Aggregations