use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method processTreeSync.
/**
* Execute sync for tree and given accounts.
*
* @param context
* @param accountsMap
*/
private void processTreeSync(SynchronizationContext context, Map<String, IcConnectorObject> accountsMap) {
AbstractSysSyncConfigDto config = context.getConfig();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
SysSyncLogDto log = context.getLog();
List<SysSyncActionLogDto> actionsLog = context.getActionLogs();
AttributeMapping tokenAttribute = context.getTokenAttribute();
// Find UID/PARENT/CODE attribute
SysSystemAttributeMappingDto uidAttribute = attributeHandlingService.getUidAttribute(mappedAttributes, system);
SysSystemAttributeMappingDto parentAttribute = getAttributeByIdmProperty(PARENT_FIELD, mappedAttributes);
SysSystemAttributeMappingDto codeAttribute = getAttributeByIdmProperty(CODE_FIELD, mappedAttributes);
if (parentAttribute == null) {
LOG.warn("Parent attribute is not specified! Organization tree will not be recomputed.");
}
if (codeAttribute == null) {
LOG.warn("Code attribute is not specified!");
}
// Find all roots
Collection<String> roots = findRoots(parentAttribute, accountsMap, config, context);
if (roots.isEmpty()) {
log.addToLog("No roots to synchronization found!");
} else {
log.addToLog(MessageFormat.format("We found [{0}] roots: [{1}]", roots.size(), roots));
}
if (parentAttribute == null) {
// just alias all accounts as roots and process
roots.addAll(accountsMap.keySet());
}
Set<String> accountsUseInTreeList = new HashSet<>(roots.size());
for (String root : roots) {
accountsUseInTreeList.add(root);
IcConnectorObject account = accountsMap.get(root);
SynchronizationContext itemContext = cloneItemContext(context);
//
itemContext.addUid(//
root).addIcObject(//
account).addAccount(//
null).addTokenAttribute(//
tokenAttribute).addGeneratedUid(//
null);
boolean result = handleIcObject(itemContext);
if (!result) {
return;
}
if (parentAttribute != null) {
Object uidValueParent = this.getValueByMappedAttribute(uidAttribute, account.getAttributes(), context);
processChildren(parentAttribute, uidValueParent, uidAttribute, accountsMap, accountsUseInTreeList, itemContext, roots);
}
}
if (config.isReconciliation()) {
// We do reconciliation (find missing account)
startReconciliation(entityType, accountsUseInTreeList, config, system, log, actionsLog);
}
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class AbstractPasswordFilterIntegrationTest method checkProcessedPasswordOperation.
protected void checkProcessedPasswordOperation(IdmIdentityDto identity, SysSystemDto system, int expectedOperation, String password) {
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(identity.getId());
filter.setSystemId(system.getId());
List<SysProvisioningArchiveDto> archives = provisioningArchive.find(filter, null).getContent();
assertEquals(expectedOperation, archives.size());
for (SysProvisioningArchiveDto archive : archives) {
ProvisioningContext provisioningContext = archive.getProvisioningContext();
assertNotNull(provisioningContext);
IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
List<IcAttribute> attributes = connectorObject.getAttributes();
boolean passwordExists = false;
for (IcAttribute attribute : attributes) {
if (attribute instanceof IcPasswordAttribute) {
IcPasswordAttribute passAttr = (IcPasswordAttribute) attribute;
GuardedString passwordValue = passAttr.getPasswordValue();
assertNotNull(passwordValue);
String asString = passwordValue.asString();
assertEquals(GuardedString.SECRED_PROXY_STRING, asString);
String passwordOnTargetSystem = getPasswordOnTargetSystem(prepareUid(identity, system));
if (StringUtils.isNotBlank(password)) {
assertEquals(password, passwordOnTargetSystem);
}
// Only one password for whole operation
assertFalse(passwordExists);
passwordExists = true;
}
}
assertTrue(passwordExists);
}
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processUpdateByAttribute.
/**
* Resolve update for given attribute
*
* @param provisioningAttribute
* @param provisioningOperation
* @param existsConnectorObject
* @param system
* @param systemEntityUid
* @param updateConnectorObject
* @param fullAccountObject
* @param schemaAttributes
*/
private void processUpdateByAttribute(ProvisioningAttributeDto provisioningAttribute, SysProvisioningOperationDto provisioningOperation, IcConnectorObject existsConnectorObject, SysSystemDto system, String systemEntityUid, IcConnectorObject updateConnectorObject, Map<ProvisioningAttributeDto, Object> fullAccountObject, List<SysSchemaAttributeDto> schemaAttributes, ConnectorType connectorType) {
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()) {
Object idmValue = fullAccountObject.get(provisioningAttribute);
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
return;
}
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
return;
}
}
if (schemaAttribute.isReturnedByDefault()) {
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
});
boolean existMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
});
boolean existAuthMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
});
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) {
return;
}
}
}
Object resultValue = idmValue;
if (AttributeMappingStrategyType.MERGE == provisioningAttribute.getStrategyType()) {
List<Object> allConnectorValues = this.getAllConnectorValues(provisioningAttribute, existsConnectorObject);
resultValue = resolveMergeValues(provisioningAttribute, idmValue, allConnectorValues, provisioningOperation);
}
// Update attribute on resource by given mapping
// attribute and mapped value in entity
IcAttribute updatedAttribute = updateAttribute(systemEntityUid, resultValue, schemaAttribute, existsConnectorObject, system, provisioningAttribute);
// Add updated attribute to updateConnectorObject.
connectorType.addUpdatedAttribute(schemaAttribute, updatedAttribute, updateConnectorObject, existsConnectorObject);
} else {
// filled values only
if (fullAccountObject.get(provisioningAttribute) != null) {
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
updateConnectorObject.getAttributes().add(createdAttribute);
}
}
}
}
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method updateAttribute.
/**
* Update attribute on resource by given handling attribute and mapped value in
* entity.
*/
private IcAttribute updateAttribute(String uid, Object idmValue, SysSchemaAttributeDto schemaAttribute, IcConnectorObject existsConnectorObject, SysSystemDto system, ProvisioningAttributeDto provisioningAttributeDto) {
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();
}
return updateAttributeValue(uid, idmValue, schemaAttribute, icAttribute, icAttributes, system, provisioningAttributeDto.getTransformValueFromResourceScript(), provisioningAttributeDto.isSendAlways());
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method getAllConnectorValues.
private List<Object> getAllConnectorValues(ProvisioningAttributeDto provisioningAttribute, IcConnectorObject existsConnectorObject) {
if (existsConnectorObject == null) {
return Lists.newArrayList();
}
IcAttribute attribute = existsConnectorObject.getAttributeByName(provisioningAttribute.getSchemaAttributeName());
Object connectorValue = attribute != null ? (attribute.isMultiValue() ? attribute.getValues() : attribute.getValue()) : null;
if (connectorValue != null && !(connectorValue instanceof List)) {
connectorValue = Lists.newArrayList(connectorValue);
}
List<Object> connectorValues = Lists.newArrayList();
if (connectorValue != null) {
connectorValues.addAll((List<?>) connectorValue);
}
return connectorValues;
}
Aggregations