use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareProvisioningForAttribute.
private SysProvisioningOperationDto prepareProvisioningForAttribute(SysSystemEntityDto systemEntity, AttributeMapping attributeMapping, Object value, ProvisioningOperationType operationType, DTO dto) {
Assert.notNull(systemEntity, "System entity is required.");
Assert.notNull(systemEntity.getSystem(), "Relation to system is required for system entity.");
Assert.notNull(systemEntity.getEntityType(), "System entity type is required.");
Assert.notNull(systemEntity.getUid(), "System entity uid is required.");
Assert.notNull(attributeMapping, "Attribute mapping is required.");
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeMapping);
if (!schemaAttributeDto.isUpdateable()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_NOT_UPDATEABLE, ImmutableMap.of("attribute", StringUtils.defaultIfBlank(attributeMapping.getIdmPropertyName(), attributeMapping.getName()), "entity", systemEntity.getUid()));
}
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(schemaAttributeDto.getObjectClass());
String objectClassName = schemaObjectClassDto.getObjectClassName();
// We do transformation to system if is attribute only constant
Object valueTransformed = value;
if (!attributeMapping.isEntityAttribute() && !attributeMapping.isExtendedAttribute()) {
// If is attribute handling resolve as constant, then we don't want
// do transformation again (was did in getAttributeValue)
} else {
valueTransformed = attributeMappingService.transformValueToResource(systemEntity.getUid(), value, attributeMapping, dto);
}
IcAttribute icAttributeForCreate = attributeMappingService.createIcAttribute(schemaAttributeDto, valueTransformed);
//
// Call IC modul for update single attribute
IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(objectClassName), ImmutableList.of(icAttributeForCreate));
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(ProvisioningEventType.UPDATE).setSystemEntity(systemEntity).setEntityIdentifier(dto == null ? null : dto.getId()).setProvisioningContext(new ProvisioningContext(connectorObject));
//
return operationBuilder.build();
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method validateAttributesStrategy.
/**
* Validate attributes on incompatible strategies
*
* @param finalAttributes
*/
protected void validateAttributesStrategy(List<AttributeMapping> finalAttributes) {
if (finalAttributes == null) {
return;
}
finalAttributes.forEach(parentAttribute -> {
if (AttributeMappingStrategyType.MERGE == parentAttribute.getStrategyType() || AttributeMappingStrategyType.AUTHORITATIVE_MERGE == parentAttribute.getStrategyType()) {
Optional<AttributeMapping> conflictAttributeOptional = finalAttributes.stream().filter(att -> {
UUID attributeSchemaId = getSchemaAttributeId(att);
UUID parentSchemaId = getSchemaAttributeId(parentAttribute);
return attributeSchemaId.equals(parentSchemaId) && !(att.getStrategyType() == parentAttribute.getStrategyType() || att.getStrategyType() == AttributeMappingStrategyType.CREATE || att.getStrategyType() == AttributeMappingStrategyType.WRITE_IF_NULL);
}).findFirst();
if (conflictAttributeOptional.isPresent()) {
AttributeMapping conflictAttribute = conflictAttributeOptional.get();
IdmRoleDto roleParent = this.getRole(parentAttribute);
IdmRoleDto roleConflict = this.getRole(conflictAttribute);
throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_STRATEGY_CONFLICT, //
ImmutableMap.of(//
"strategyParent", //
parentAttribute.getStrategyType(), //
"strategyConflict", //
conflictAttribute.getStrategyType(), //
"attribute", //
conflictAttribute.getName(), //
"roleParent", //
roleParent != null ? roleParent.getCode() : "-", "roleConflict", //
roleConflict != null ? roleConflict.getCode() : "-"));
}
}
});
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class ContractSliceSynchronizationExecutor method validate.
@Override
protected SynchronizationContext validate(UUID synchronizationConfigId) {
AbstractSysSyncConfigDto config = synchronizationConfigService.get(synchronizationConfigId);
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
Assert.notNull(mapping, "Mapping is required.");
SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
attributeHandlingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> mappedAttributes = systemAttributeMappingService.find(attributeHandlingFilter, null).getContent();
// Owner attribute check
mappedAttributes.stream().filter(attribute -> {
return CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName());
}).findFirst().orElseThrow(() -> new ProvisioningException(AccResultCode.SYNCHRONIZATION_MAPPED_ATTR_MUST_EXIST, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD)));
// Code of contract attribute check
mappedAttributes.stream().filter(attribute -> {
return CONTRACT_SLICE_CONTRACT_CODE_FIELD.equals(attribute.getIdmPropertyName());
}).findFirst().orElseThrow(() -> new ProvisioningException(AccResultCode.SYNCHRONIZATION_MAPPED_ATTR_MUST_EXIST, ImmutableMap.of("property", CONTRACT_SLICE_CONTRACT_CODE_FIELD)));
return super.validate(synchronizationConfigId);
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException 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, MappingContext mappingContext) {
AccAccountDto account = getAccountSystemEntity(systemEntity.getId());
String uid = systemEntity.getUid();
SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system);
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() && !attribute.isPasswordAttribute() && 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, system, mappingContext);
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(), schemaAttributeDto.getClassType()), uidValue);
} else {
accountAttributes.put(ProvisioningAttributeDto.createProvisioningAttributeKey(attribute, schemaAttributeDto.getName(), schemaAttributeDto.getClassType()), getAttributeValue(uid, dto, attribute, system, mappingContext));
}
});
// 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(), schemaAttributeParent.getClassType());
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<>();
//
attributesMerge.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, system, mappingContext);
// 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.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method findSystemEntity.
private SysSystemEntityDto findSystemEntity(String uid, SysSystemDto system, SystemEntityType entityType) {
SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
systemEntityFilter.setEntityType(entityType);
systemEntityFilter.setSystemId(system.getId());
systemEntityFilter.setUid(uid);
List<SysSystemEntityDto> systemEntities = systemEntityService.find(systemEntityFilter, null).getContent();
SysSystemEntityDto systemEntity = null;
if (systemEntities.size() == 1) {
systemEntity = systemEntities.get(0);
} else if (systemEntities.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TO_MANY_SYSTEM_ENTITY, uid);
}
return systemEntity;
}
Aggregations