use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto 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);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareMappedAttributesValues.
/**
* Prepare all mapped attribute values (= account)
*
* @param dto
* @param operationType
* @param systemEntity
* @param attributes
* @return
*/
protected Map<ProvisioningAttributeDto, Object> prepareMappedAttributesValues(DTO dto, ProvisioningOperationType operationType, SysSystemEntityDto systemEntity, List<? extends AttributeMapping> attributes) {
AccAccountDto account = getAccountSystemEntity(systemEntity.getId());
String uid = systemEntity.getUid();
SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system, SysSystemDto.class);
Map<ProvisioningAttributeDto, Object> accountAttributes = new HashMap<>();
// delete - account attributes is not needed
if (ProvisioningOperationType.DELETE == operationType) {
return accountAttributes;
}
// First we will resolve attribute without MERGE strategy
attributes.stream().filter(attribute -> {
return !attribute.isDisabledAttribute() && AttributeMappingStrategyType.AUTHORITATIVE_MERGE != attribute.getStrategyType() && AttributeMappingStrategyType.MERGE != attribute.getStrategyType();
}).forEach(attribute -> {
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attribute);
if (attribute.isUid()) {
// TODO: now we set UID from SystemEntity, may be UID from
// AccAccount will be more correct
Object uidValue = getAttributeValue(uid, dto, attribute);
if (uidValue == null) {
throw new ProvisioningException(AccResultCode.PROVISIONING_GENERATED_UID_IS_NULL, ImmutableMap.of("system", system.getName()));
}
if (!(uidValue instanceof String)) {
throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_UID_IS_NOT_STRING, ImmutableMap.of("uid", uidValue, "system", system.getName()));
}
updateAccountUid(account, uid, (String) uidValue);
accountAttributes.put(ProvisioningAttributeDto.createProvisioningAttributeKey(attribute, schemaAttributeDto.getName()), uidValue);
} else {
accountAttributes.put(ProvisioningAttributeDto.createProvisioningAttributeKey(attribute, schemaAttributeDto.getName()), getAttributeValue(uid, dto, attribute));
}
});
// Second we will resolve MERGE attributes
List<? extends AttributeMapping> attributesMerge = attributes.stream().filter(attribute -> {
return !attribute.isDisabledAttribute() && (AttributeMappingStrategyType.AUTHORITATIVE_MERGE == attribute.getStrategyType() || AttributeMappingStrategyType.MERGE == attribute.getStrategyType());
}).collect(Collectors.toList());
for (AttributeMapping attributeParent : attributesMerge) {
SysSchemaAttributeDto schemaAttributeParent = getSchemaAttribute(attributeParent);
ProvisioningAttributeDto attributeParentKey = ProvisioningAttributeDto.createProvisioningAttributeKey(attributeParent, schemaAttributeParent.getName());
if (!schemaAttributeParent.isMultivalued()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_MERGE_ATTRIBUTE_IS_NOT_MULTIVALUE, ImmutableMap.of("object", uid, "attribute", schemaAttributeParent.getName(), "system", system.getName()));
}
// we use SET collection because we want collection of merged values without duplicates
Set<Object> mergedValues = new LinkedHashSet<>();
attributes.stream().filter(attribute -> {
SysSchemaAttributeDto schemaAttribute = getSchemaAttribute(attribute);
return !accountAttributes.containsKey(attributeParentKey) && schemaAttributeParent.equals(schemaAttribute) && attributeParent.getStrategyType() == attribute.getStrategyType();
}).forEach(attribute -> {
Object value = getAttributeValue(uid, dto, attribute);
// provisioning in IC)
if (value != null) {
// main list!
if (value instanceof Collection) {
Collection<?> collectionNotNull = ((Collection<?>) value).stream().filter(item -> {
return item != null;
}).collect(Collectors.toList());
mergedValues.addAll(collectionNotNull);
} else {
mergedValues.add(value);
}
}
});
if (!accountAttributes.containsKey(attributeParentKey)) {
// we must put merged values as array list
accountAttributes.put(attributeParentKey, new ArrayList<>(mergedValues));
}
}
return accountAttributes;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method getAttributeValue.
/**
* Find value for this mapped attribute by property name. Returned value can be list of objects. Returns transformed value.
*
* @param uid - Account identifier
* @param entity
* @param attributeHandling
* @param idmValue
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling) {
Object idmValue = null;
//
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeHandling);
//
if (attributeHandling.isExtendedAttribute() && entity != null && formService.isFormable(entity.getClass())) {
List<IdmFormValueDto> formValues = formService.getValues(entity, attributeHandling.getIdmPropertyName());
if (formValues.isEmpty()) {
idmValue = null;
} else if (schemaAttributeDto.isMultivalued()) {
// Multiple value extended attribute
List<Object> values = new ArrayList<>();
formValues.stream().forEachOrdered(formValue -> {
values.add(formValue.getValue());
});
idmValue = values;
} else {
// Single value extended attribute
IdmFormValueDto formValue = formValues.get(0);
if (formValue.isConfidential()) {
Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
// If is confidential value String and schema attribute is GuardedString type, then convert to GuardedString will be did.
if (confidentialValue instanceof String && schemaAttributeDto.getClassType().equals(GuardedString.class.getName())) {
idmValue = new GuardedString((String) confidentialValue);
} else {
idmValue = confidentialValue;
}
} else {
idmValue = formValue.getValue();
}
}
} else // Find value from entity
if (attributeHandling.isEntityAttribute()) {
if (attributeHandling.isConfidentialAttribute()) {
// If is attribute isConfidential, then we will find value in
// secured storage
idmValue = confidentialStorage.getGuardedString(entity.getId(), entity.getClass(), attributeHandling.getIdmPropertyName());
} else {
try {
// We will search value directly in entity by property name
idmValue = EntityUtils.getEntityValue(entity, attributeHandling.getIdmPropertyName());
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException o_O) {
throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass()), o_O);
}
}
} else {
// If Attribute value is not in entity nor in extended attribute, then idmValue is null.
// It means attribute is static ... we will call transformation to resource.
}
return this.transformValueToResource(uid, idmValue, attributeHandling, entity);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountService method getConnectorObject.
@Override
public IcConnectorObject getConnectorObject(AccAccountDto account, BasePermission... permissions) {
Assert.notNull(account, "Account cannot be null!");
this.checkAccess(account, permissions);
List<SysSchemaAttributeDto> schemaAttributes = this.getSchemaAttributes(account.getSystem(), null);
if (schemaAttributes == null) {
return null;
}
try {
// Find connector-type.
SysSystemDto systemDto = lookupService.lookupEmbeddedDto(account, AccAccount_.system);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
// Find first mapping for entity type and system, from the account and return his object class.
IcObjectClass icObjectClass = schemaObjectClassService.findByAccount(account.getSystem(), account.getEntityType());
IcConnectorObject fullObject = this.systemService.readConnectorObject(account.getSystem(), account.getRealUid(), icObjectClass, connectorType);
return this.getConnectorObjectForSchema(fullObject, schemaAttributes);
} catch (Exception ex) {
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_READ_FROM_TARGET, ImmutableMap.of("account", account.getUid(), "system", system != null ? system.getName() : account.getSystem()), ex);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemAttributeService method getSchemaAttr.
/**
* Returns schema attribute
*
* @param systemId
* @param attributeName
* @param objectClassName
* @return
*/
private SysSchemaAttributeDto getSchemaAttr(UUID systemId, String attributeName, String objectClassName) {
SysSchemaAttributeFilter filter = new SysSchemaAttributeFilter();
filter.setObjectClassId(getObjectClassId(systemId, objectClassName));
filter.setName(attributeName);
List<SysSchemaAttributeDto> schemas = schemaAttributeService.find(filter, null).getContent();
if (schemas.isEmpty()) {
throw new ResultCodeException(AccResultCode.SYSTEM_SCHEMA_ATTRIBUTE_NOT_FOUND, ImmutableMap.of("objectClassName", objectClassName, "attributeName", attributeName));
}
return schemas.get(0);
}
Aggregations