Search in sources :

Example 66 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method startWorkflow.

/**
 * Start workflow process by wfDefinitionKey. Create input variables and put
 * them to the process. If log variable is present after the process started,
 * then add the log to the synchronization log.
 *
 * @param wfDefinitionKey
 * @param situation
 * @param action
 * @param dto
 */
private void startWorkflow(String wfDefinitionKey, SynchronizationSituationType situation, SynchronizationActionType action, DTO dto, SynchronizationContext context) {
    SystemEntityType entityType = context.getEntityType();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    AccAccountDto account = context.getAccount();
    String uid = context.getUid();
    AbstractSysSyncConfigDto config = context.getConfig();
    addToItemLog(logItem, MessageFormat.format("Workflow for [{0}] situation was found. We will start it.", situation));
    Map<String, Object> variables = new HashMap<>();
    variables.put(SynchronizationService.WF_VARIABLE_KEY_UID, uid);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_TYPE, entityType);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_SITUATION, situation.name());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_IC_ATTRIBUTES, context.getIcObject() != null ? context.getIcObject().getAttributes() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ACTION_TYPE, action.name());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_ID, dto != null ? dto.getId() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ACC_ACCOUNT_ID, account != null ? account.getId() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYSTEM_ID, context.getSystem().getId());
    ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinitionKey, SysSyncConfig.class.getSimpleName(), uid, config.getId().toString(), variables);
    if (processInstance instanceof VariableScope) {
        Object logItemObj = ((VariableScope) processInstance).getVariable(SynchronizationService.WF_VARIABLE_KEY_LOG_ITEM);
        if (logItemObj instanceof String) {
            addToItemLog(logItem, (String) logItemObj);
        }
    }
    if (processInstance != null && processInstance.isEnded()) {
        addToItemLog(logItem, MessageFormat.format("Workflow (with id [{0}]) for missing entity situation ended.", processInstance.getId()));
        initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
        // We don't wont history for workflow executed in synchronization!
        processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
        addToItemLog(logItem, MessageFormat.format("Workflow history for process instance [{0}] was deleted.", processInstance.getId()));
    } else {
        // If workflow not ended, then the history will be not deleted!
        addToItemLog(logItem, MessageFormat.format("Workflow (with id [{0}]) for missing entity situation not ended (will be ended asynchronously).", processInstance != null ? processInstance.getId() : null));
        initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
    }
}
Also used : HashMap(java.util.HashMap) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) VariableScope(org.activiti.engine.delegate.VariableScope)

Example 67 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveMissingAccountSituation.

/**
 * Method for resolve missing account situation for one item.
 *
 * @param action
 * @param context
 */
@Override
public void resolveMissingAccountSituation(ReconciliationMissingAccountActionType action, SynchronizationContext context) {
    SystemEntityType entityType = context.getEntityType();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    AccAccountDto account = context.getAccount();
    addToItemLog(logItem, "Account doesn't exist on target system, but account in IdM was found (missing account).");
    addToItemLog(logItem, MessageFormat.format("Missing account action is [{0}]", action));
    switch(action) {
        case IGNORE:
            // Ignore we will do nothing
            initSyncActionLog(SynchronizationActionType.MISSING_ACCOUNT, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case CREATE_ACCOUNT:
            doUpdateAccount(account, entityType, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case DELETE_ENTITY:
            doDeleteEntity(account, entityType, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UNLINK:
            doUnlink(account, false, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UNLINK_AND_REMOVE_ROLE:
            doUnlink(account, true, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK_AND_REMOVE_ROLE, OperationResultType.SUCCESS, logItem, log, actionLogs);
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 68 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method findByCorrelationAttribute.

/**
 * Find entity by correlation attribute
 *
 * @param attribute
 * @param icAttributes
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
protected DTO findByCorrelationAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Assert.notNull(attribute, "Attribute is required.");
    Assert.notNull(icAttributes, "Connector attribues are required.");
    Object value = getValueByMappedAttribute(attribute, icAttributes, context);
    if (value == null) {
        return null;
    }
    if (attribute.isEntityAttribute()) {
        return findByAttribute(attribute.getIdmPropertyName(), value.toString(), context);
    } else if (attribute.isExtendedAttribute()) {
        try {
            Serializable serializableValue = Serializable.class.cast(value);
            SystemEntityType entityType = context.getEntityType();
            Assert.notNull(entityType, "Entity type is required!");
            List<? extends BaseDto> entities = formService.findOwners(entityType.getExtendedAttributeOwnerType(), attribute.getIdmPropertyName(), serializableValue, null).getContent();
            if (CollectionUtils.isEmpty(entities)) {
                return null;
            }
            if (entities.size() > 1) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", attribute.getName(), "value", value));
            }
            if (entities.size() == 1) {
                return (DTO) entities.get(0);
            }
        } catch (ClassCastException e) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_BAD_VALUE, ImmutableMap.of("value", value), e);
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) List(java.util.List) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto)

Example 69 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method startItemSynchronization.

/**
 * Main method for synchronization item. This method is call form "custom
 * filter" and "connector sync" mode.
 *
 * @param itemContext
 * @return
 */
protected boolean startItemSynchronization(SynchronizationContext itemContext) {
    String uid = itemContext.getUid();
    AbstractSysSyncConfigDto config = itemContext.getConfig();
    SystemEntityType entityType = itemContext.getEntityType();
    SysSyncLogDto log = itemContext.getLog();
    SysSyncItemLogDto itemLog = itemContext.getLogItem();
    List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
    try {
        SysSyncActionLogFilter actionFilter = new SysSyncActionLogFilter();
        actionFilter.setSynchronizationLogId(log.getId());
        actionsLog.addAll(syncActionLogService.find(actionFilter, null).getContent());
        itemContext.addActionLogs(actionsLog);
        // Default setting for log item
        itemLog.setIdentification(uid);
        itemLog.setDisplayName(uid);
        itemLog.setType(entityType.getEntityType().getSimpleName());
        // Do synchronization for one item (produces item)
        // Start in new Transaction
        CoreEvent<SysSyncItemLogDto> event = new CoreEvent<>(SynchronizationEventType.START_ITEM, itemLog);
        event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemContext);
        EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
        boolean result = false;
        if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
            result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
        }
        return result;
    } catch (Exception ex) {
        Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionsLog, itemLog);
        if (actionWithItemLog != null) {
            // We have to decrement count and log as error
            itemLog = actionWithItemLog.getRight();
            SysSyncActionLogDto actionLogDto = actionWithItemLog.getLeft();
            actionLogDto.setOperationCount(actionLogDto.getOperationCount() - 1);
            actionLogDto.getLogItems().remove(itemLog);
            loggingException(actionLogDto.getSyncAction(), log, itemLog, actionsLog, uid, ex);
        } else {
            loggingException(SynchronizationActionType.UNKNOWN, log, itemLog, actionsLog, uid, ex);
        }
        return true;
    } finally {
        synchronizationConfigService.save(config);
        boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
        actionsLog = saveActionLogs(actionsLog, log.getId());
        // 
        if (!existingItemLog) {
            addToItemLog(itemLog, MessageFormat.format("Missing action log for UID [{0}]!", uid));
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
            syncItemLogService.save(itemLog);
        }
    }
}
Also used : SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 70 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class DefaultAccAccountService method toDto.

@Override
protected AccAccountDto toDto(AccAccount entity, AccAccountDto dto) {
    AccAccountDto newDto = super.toDto(entity, dto);
    // if dto exists add real uid
    if (newDto != null) {
        if (newDto.getSystemEntity() != null) {
            SysSystemEntityDto systemEntity = DtoUtils.getEmbedded(newDto, AccAccount_.systemEntity);
            newDto.setRealUid(systemEntity.getUid());
        } else {
            // If system entity do not exist, then return uid from account.
            newDto.setRealUid(newDto.getUid());
        }
        // Load and set target entity. For loading a target entity is using sync
        // executor.
        SystemEntityType entityType = newDto.getEntityType();
        if (entityType != null && entityType.isSupportsSync()) {
            SynchronizationEntityExecutor executor = this.getSyncExecutor(entityType);
            UUID targetEntity = executor.getEntityByAccount(newDto.getId());
            newDto.setTargetEntityType(entityType.getEntityType().getName());
            newDto.setTargetEntityId(targetEntity);
        }
    }
    return newDto;
}
Also used : SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) UUID(java.util.UUID)

Aggregations

SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)71 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)36 Test (org.junit.Test)36 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)28 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)28 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)26 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)21 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)17 UUID (java.util.UUID)17 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)15 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)15 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)13 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)11 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)11 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)10 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)10