use of eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method operationTypeFilterTest.
@Test
public void operationTypeFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createRoleSystem();
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
provisioningArchive2.setOperationType(ProvisioningEventType.UPDATE);
archiveService.save(provisioningArchive2);
SysProvisioningArchiveDto provisioningArchive3 = createProvisioningArchive(entityType, system);
provisioningArchive3.setOperationType(ProvisioningEventType.UPDATE);
archiveService.save(provisioningArchive3);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setOperationType(ProvisioningEventType.UPDATE);
filter.setSystemId(system.getId());
Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
assertEquals(2, result.getTotalElements());
assertFalse(result.getContent().contains(provisioningArchive1));
assertTrue(result.getContent().contains(provisioningArchive2));
assertTrue(result.getContent().contains(provisioningArchive3));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method systemIdFilterTest.
@Test
public void systemIdFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system1 = createRoleSystem();
SysSystemDto system2 = createRoleSystem();
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system1);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system1);
SysProvisioningArchiveDto provisioningArchive3 = createProvisioningArchive(entityType, system2);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(system1.getId());
Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
assertEquals(2, result.getTotalElements());
assertTrue(result.getContent().contains(provisioningArchive1));
assertTrue(result.getContent().contains(provisioningArchive2));
assertFalse(result.getContent().contains(provisioningArchive3));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method resultStateFilterTest.
@Test
public void resultStateFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createRoleSystem();
OperationResult resultState = new OperationResult();
resultState.setState(OperationState.CREATED);
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
provisioningArchive2.setResult(resultState);
archiveService.save(provisioningArchive2);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setResultState(OperationState.CREATED);
Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
assertEquals(1, result.getTotalElements());
assertFalse(result.getContent().contains(provisioningArchive1));
assertTrue(result.getContent().contains(provisioningArchive2));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method compileAttributesOverrloadedStrategyMergeWithDuplTest.
@Test
public void compileAttributesOverrloadedStrategyMergeWithDuplTest() {
String sameValue = "sameValue-" + System.currentTimeMillis();
String eavAttribute = "EAV_ATTRIBUTE";
IdmRoleDto role1 = helper.createRole();
IdmRoleDto role2 = helper.createRole();
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, role1);
helper.createIdentityRole(identity, role2);
SysSystemDto system = helper.createTestResourceSystem(true);
systemService.generateSchema(system);
SysSchemaAttributeFilter schemaAttFilter = new SysSchemaAttributeFilter();
schemaAttFilter.setSystemId(system.getId());
schemaAttFilter.setName(eavAttribute);
List<SysSchemaAttributeDto> schemaAttrs = schemaAttributeService.find(schemaAttFilter, null).getContent();
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(eavAttribute);
List<SysSchemaAttributeDto> atts = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
assertEquals(1, atts.size());
SysSchemaAttributeDto sysSchemaAttributeEav = atts.get(0);
// create eav attribute with merge
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setExtendedAttribute(true);
attributeMapping.setName(eavAttribute);
attributeMapping.setIdmPropertyName(eavAttribute);
attributeMapping.setStrategyType(AttributeMappingStrategyType.MERGE);
attributeMapping.setSchemaAttribute(sysSchemaAttributeEav.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
SysRoleSystemDto roleSystem1 = helper.createRoleSystem(role1, system);
SysRoleSystemDto roleSystem2 = helper.createRoleSystem(role2, 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(eavAttribute);
overloadedRoleOne.setRoleSystem(roleSystem1.getId());
overloadedRoleOne.setTransformToResourceScript("return '" + sameValue + "';");
overloadedRoleOne = roleSystemAttributeService.save(overloadedRoleOne);
SysRoleSystemAttributeDto overloadedRoleTwo = new SysRoleSystemAttributeDto();
overloadedRoleTwo.setSystemAttributeMapping(attributeMapping.getId());
overloadedRoleTwo.setEntityAttribute(false);
overloadedRoleTwo.setExtendedAttribute(true);
overloadedRoleTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
overloadedRoleTwo.setName(attributeMapping.getName());
overloadedRoleTwo.setDisabledDefaultAttribute(false);
overloadedRoleTwo.setIdmPropertyName(eavAttribute);
overloadedRoleTwo.setRoleSystem(roleSystem2.getId());
overloadedRoleTwo.setTransformToResourceScript("return '" + sameValue + "';");
overloadedRoleTwo = roleSystemAttributeService.save(overloadedRoleTwo);
provisioningService.accountManagement(identity);
provisioningService.doProvisioning(identity);
List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
assertEquals(1, accounts.size());
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(system.getId());
List<SysProvisioningArchiveDto> archives = porvisioningArchiveService.find(filter, null).getContent();
assertEquals(1, archives.size());
SysProvisioningArchiveDto archive = archives.get(0);
assertEquals(OperationState.EXECUTED, archive.getResultState());
ProvisioningContext provisioningContext = archive.getProvisioningContext();
Object values = null;
for (ProvisioningAttributeDto key : provisioningContext.getAccountObject().keySet()) {
if (key.getSchemaAttributeName().equals(eavAttribute)) {
values = provisioningContext.getAccountObject().get(key);
break;
}
}
assertNotNull(values);
if (values instanceof ArrayList<?>) {
ArrayList<?> colleaction = (ArrayList<?>) values;
assertEquals(1, colleaction.size());
Object object = colleaction.get(0);
assertEquals(sameValue, object);
} else {
fail();
}
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processUpdate.
@SuppressWarnings("unchecked")
private void processUpdate(SysProvisioningOperationDto provisioningOperation, IcConnectorConfiguration connectorConfig, IcConnectorObject existsConnectorObject) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
String systemEntityUid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
ProvisioningContext provisioningContext = provisioningOperation.getProvisioningContext();
IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
IcObjectClass objectClass = connectorObject.getObjectClass();
//
IcConnectorObject updateConnectorObject;
if (provisioningContext.getAccountObject() == null) {
updateConnectorObject = connectorObject;
} else {
Map<ProvisioningAttributeDto, Object> fullAccountObject = provisioningOperationService.getFullAccountObject(provisioningOperation);
updateConnectorObject = new IcConnectorObjectImpl(systemEntityUid, objectClass, null);
SysSystemMappingDto mapping = getMapping(system, provisioningOperation.getEntityType());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
List<SysSchemaAttributeDto> schemaAttributes = findSchemaAttributes(system, schemaObjectClassDto);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(provisioningOperation.getEntityIdentifier());
filter.setEntityType(provisioningOperation.getEntityType());
filter.setResultState(OperationState.EXECUTED);
SysProvisioningArchiveDto lastSuccessEntity = null;
for (Entry<ProvisioningAttributeDto, Object> entry : fullAccountObject.entrySet()) {
ProvisioningAttributeDto provisioningAttribute = entry.getKey();
Optional<SysSchemaAttributeDto> schemaAttributeOptional = schemaAttributes.stream().filter(schemaAttribute -> {
return provisioningAttribute.getSchemaAttributeName().equals(schemaAttribute.getName());
}).findFirst();
if (!schemaAttributeOptional.isPresent()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_FOUND, ImmutableMap.of("attribute", provisioningAttribute.getSchemaAttributeName()));
}
SysSchemaAttributeDto schemaAttribute = schemaAttributeOptional.get();
if (schemaAttribute.isUpdateable()) {
if (schemaAttribute.isReturnedByDefault()) {
Object idmValue = fullAccountObject.get(provisioningAttribute);
IcAttribute attribute = existsConnectorObject.getAttributeByName(schemaAttribute.getName());
Object connectorValue = attribute != null ? (attribute.isMultiValue() ? attribute.getValues() : attribute.getValue()) : null;
Object resultValue = idmValue;
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
// We do update, attributes with create strategy will be skipped
continue;
}
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
// Skip this attribute (marked with flag sendOnlyIfNotNull), because idm value is null
continue;
}
}
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existAuthMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
List<IcAttribute> icAttributes = existsConnectorObject.getAttributes();
//
Optional<IcAttribute> icAttributeOptional = icAttributes.stream().filter(ica -> {
return schemaAttribute.getName().equals(ica.getName());
}).findFirst();
IcAttribute icAttribute = null;
if (icAttributeOptional.isPresent()) {
icAttribute = icAttributeOptional.get();
}
// We need do transform from resource first
Object transformedConnectorValue = this.transformValueFromResource(provisioningAttribute.getTransformValueFromResourceScript(), schemaAttribute, icAttribute, icAttributes, system);
if (transformedConnectorValue != null || existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
// or exists same attribute with SET/MERGE/AUTH_MERGE strategy (this strategies has higher priority)
continue;
}
}
}
if (AttributeMappingStrategyType.MERGE == provisioningAttribute.getStrategyType()) {
// Load last provisioning history
if (lastSuccessEntity == null) {
List<SysProvisioningArchiveDto> lastSuccessEntities = provisioningArchiveService.find(filter, new PageRequest(0, 1, new Sort(Direction.DESC, MODIFIED_FIELD_NAME))).getContent();
if (!lastSuccessEntities.isEmpty()) {
lastSuccessEntity = lastSuccessEntities.get(0);
}
}
// Merge IdM values with connector values
if (connectorValue instanceof List) {
List<Object> connectorValues = new ArrayList<>((List<Object>) connectorValue);
List<Object> idmValues = null;
if (idmValue instanceof List) {
idmValues = (List<Object>) idmValue;
}
if (idmValues != null) {
idmValues.stream().forEach(value -> {
if (!connectorValues.contains(value)) {
connectorValues.add(value);
}
});
}
resultValue = connectorValues;
}
// Delete missing values by last provisioning history
if (lastSuccessEntity != null && lastSuccessEntity.getProvisioningContext() != null && lastSuccessEntity.getProvisioningContext().getAccountObject() != null && lastSuccessEntity.getProvisioningContext().getAccountObject().containsKey(provisioningAttribute)) {
Object oldValue = lastSuccessEntity.getProvisioningContext().getAccountObject().get(provisioningAttribute);
if (oldValue instanceof List) {
if (!oldValue.equals(idmValue)) {
// Search all deleted values (managed by IdM) by founded last provisioning values
List<?> deletedValues = ((List<?>) oldValue).stream().filter(value -> {
List<?> idmValues = null;
if (idmValue instanceof List) {
idmValues = (List<?>) idmValue;
}
if (idmValues != null && idmValues.contains(value)) {
return false;
}
return true;
}).collect(Collectors.toList());
if (resultValue instanceof List) {
List<?> resultValues = new ArrayList<>((List<Object>) resultValue);
// Remove all deleted values (managed by IdM)
resultValues.removeAll(deletedValues);
resultValue = resultValues;
}
}
}
}
}
// Update attribute on resource by given mapping
// attribute and mapped value in entity
IcAttribute updatedAttribute = updateAttribute(systemEntityUid, resultValue, schemaAttribute, existsConnectorObject, system, provisioningAttribute);
if (updatedAttribute != null) {
updateConnectorObject.getAttributes().add(updatedAttribute);
}
} else {
// filled values only
if (fullAccountObject.get(provisioningAttribute) != null) {
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
updateConnectorObject.getAttributes().add(createdAttribute);
}
}
}
}
}
}
//
provisioningOperation.getProvisioningContext().setConnectorObject(updateConnectorObject);
provisioningOperation.setOperationType(ProvisioningEventType.UPDATE);
}
Aggregations