use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method getValueByMappedAttribute.
@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
if (transformedValue != null && PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
String parentUid = transformedValue.toString();
SysSystemMappingDto systemMapping = systemMappingService.get(((SysSystemAttributeMappingDto) attribute).getSystemMapping());
SysSchemaObjectClassDto schemaObjectClass = schemaObjectClassService.get(systemMapping.getObjectClass());
UUID systemId = schemaObjectClass.getSystem();
// Find account by UID from parent field
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(parentUid);
accountFilter.setSystemId(systemId);
transformedValue = null;
List<AccAccountDto> parentAccounts = accountService.find(accountFilter, null).getContent();
if (!parentAccounts.isEmpty()) {
UUID parentAccount = parentAccounts.get(0).getId();
// Find relation between tree and account
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setAccountId(parentAccount);
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (!treeAccounts.isEmpty()) {
// Find parent tree node by ID
// TODO: resolve more treeAccounts situations
// parent uuid - we are working with dtos
transformedValue = treeAccounts.get(0).getTreeNode();
} else {
LOG.warn("For parent UID: [{}] on system ID [{}] and acc account: [{}], was not found tree accounts! Return null value in parent!!", parentUid, systemId, parentAccount);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_TREE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId, "parentAccount", parentAccount));
}
} else {
LOG.warn("For parent UID: [{}] on system ID [{}], was not found parents account! Return null value in parent!!", parentUid, systemId);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId));
}
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method findRoots.
/**
* Find all roots for this tree (uses groovy script for root definition)
*
* @param parentAttribute
* @param accountsMap
* @param config
* @return
*/
private Collection<String> findRoots(SysSystemAttributeMappingDto parentAttribute, Map<String, IcConnectorObject> accountsMap, AbstractSysSyncConfigDto config, SynchronizationContext context) {
Set<String> roots = Sets.newHashSet();
if (parentAttribute == null) {
return roots;
}
accountsMap.forEach((uid, account) -> {
if (StringUtils.hasLength(config.getRootsFilterScript())) {
Map<String, Object> variables = new HashMap<>();
variables.put("account", account);
List<Class<?>> allowTypes = new ArrayList<>();
allowTypes.add(IcAttributeImpl.class);
allowTypes.add(IcAttribute.class);
allowTypes.add(IcLoginAttributeImpl.class);
Object isRoot = groovyScriptService.evaluate(config.getRootsFilterScript(), variables, allowTypes);
if (isRoot != null && !(isRoot instanceof Boolean)) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_ROOT_FILTER_VALUE_WRONG_TYPE, ImmutableMap.of("type", isRoot.getClass().getName()));
}
if ((Boolean) isRoot) {
roots.add(uid);
}
} else {
// Default search root strategy (if is parent null, then is node root)
Object parentValue = super.getValueByMappedAttribute(parentAttribute, account.getAttributes(), context);
if (parentValue == null) {
roots.add(uid);
}
}
});
return roots;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareProvisioning.
private SysProvisioningOperationDto prepareProvisioning(SysSystemEntityDto systemEntity, DTO dto, UUID entityId, ProvisioningOperationType operationType, List<? extends AttributeMapping> attributes) {
Assert.notNull(systemEntity);
Assert.notNull(systemEntity.getUid());
Assert.notNull(systemEntity.getEntityType());
SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system, SysSystemDto.class);
Assert.notNull(system);
// If are input attributes null, then we load default mapped attributes
if (attributes == null) {
attributes = findAttributeMappings(system, systemEntity.getEntityType());
}
if (attributes == null || attributes.isEmpty()) {
return null;
}
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// One IDM object can be mapped to one connector object (= one connector
// class).
SysSystemMappingDto mapping = getMapping(system, systemEntity.getEntityType());
if (mapping == null) {
// TODO: delete operation?
return null;
}
//
Map<ProvisioningAttributeDto, Object> accountAttributes = prepareMappedAttributesValues(dto, operationType, systemEntity, attributes);
// public provisioning event
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName()), null);
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(operationType).setSystemEntity(systemEntity).setEntityIdentifier(entityId).setProvisioningContext(new ProvisioningContext(accountAttributes, connectorObject));
//
return operationBuilder.build();
}
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) {
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.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method authenticate.
@Override
public IcUidAttribute authenticate(String username, GuardedString password, SysSystemDto system, SystemEntityType entityType) {
Assert.notNull(username);
Assert.notNull(system);
Assert.notNull(entityType);
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Call IC module for check authenticate
return connectorFacade.authenticateObject(system.getConnectorInstance(), connectorConfig, null, username, password);
}
Aggregations