Search in sources :

Example 41 with SysSyncLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveMissingAccountSituation.

/**
 * Method for resolve missing account situation for one item.
 */
@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);
            return;
    }
}
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 42 with SysSyncLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto 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 uid
 * @param situation
 * @param action
 * @param icAttributes
 * @param dto
 * @param account
 * @param entityType
 * @param config
 * @param log
 * @param logItem
 * @param actionLogs
 */
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().getAttributes());
    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());
    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.isEnded()) {
        addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation ended.", processInstance.getId()));
        initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
    } else {
        addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation not ended (will be ended asynchronously).", processInstance.getId()));
        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 43 with SysSyncLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveUnlinkedSituation.

/**
 * Method for resolve unlinked situation for one item.
 */
@Override
public void resolveUnlinkedSituation(SynchronizationUnlinkedActionType action, SynchronizationContext context) {
    UUID entityId = context.getEntityId();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    addToItemLog(logItem, "Account doesn't exist, but an entity was found by correlation (entity unlinked).");
    addToItemLog(logItem, MessageFormat.format("Unlinked action is {0}", action));
    DTO entity = findById(entityId);
    switch(action) {
        case IGNORE:
            // Ignore we will do nothing
            initSyncActionLog(SynchronizationActionType.UNLINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case LINK:
            // Create idm account
            doCreateLink(entity, false, context);
            initSyncActionLog(SynchronizationActionType.LINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case LINK_AND_UPDATE_ACCOUNT:
            // Create idm account
            doCreateLink(entity, true, context);
            initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case LINK_AND_UPDATE_ENTITY:
            // Create idm account
            doCreateLink(entity, false, context);
            doUpdateEntity(context);
            initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 44 with SysSyncLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto 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 uid
 * @param icObject
 * @param type
 * @param entityType
 * @param itemLog
 * @param config
 * @param system
 * @param mappedAttributes
 * @param log
 * @param actionsLog
 * @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<SysSyncItemLogDto>(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 {
        config = 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);
            itemLog = 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) 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 45 with SysSyncLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.

the class TreeSynchronizationExecutor method process.

@Override
public AbstractSysSyncConfigDto process(UUID synchronizationConfigId) {
    // Clear cache
    this.clearCache();
    // Validate and create basic context
    SynchronizationContext context = this.validate(synchronizationConfigId);
    AbstractSysSyncConfigDto config = context.getConfig();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    IcConnectorConfiguration connectorConfig = context.getConnectorConfig();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    SysSystemMappingDto systemMapping = systemMappingService.get(context.getConfig().getSystemMapping());
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
    IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
    // Load last token
    Object lastToken = config.isReconciliation() ? null : config.getToken();
    // Create basic synchronization log
    SysSyncLogDto log = new SysSyncLogDto();
    log.setSynchronizationConfig(config.getId());
    log.setStarted(LocalDateTime.now());
    log.setRunning(true);
    log.setToken(lastToken != null ? lastToken.toString() : null);
    log.addToLog(MessageFormat.format("Synchronization was started in {0}.", log.getStarted()));
    // List of all accounts with full IC object (used in tree sync)
    Map<String, IcConnectorObject> accountsMap = new HashMap<>();
    longRunningTaskExecutor.setCounter(0L);
    try {
        log = synchronizationLogService.save(log);
        List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
        // Add logs to context
        context.addLog(log).addActionLogs(actionsLog);
        boolean export = false;
        if (export) {
            // Start exporting entities to resource
            log.addToLog("Exporting entities to resource started...");
            this.startExport(entityType, config, mappedAttributes, log, actionsLog);
        } else {
            if (config.getTokenAttribute() == null && !config.isReconciliation()) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
            }
            TreeResultsHandler resultHandler = new TreeResultsHandler(accountsMap);
            // We have to search all data for tree
            IcFilter filter = null;
            log.addToLog(MessageFormat.format("Start search with filter {0}.", "NONE"));
            log = synchronizationLogService.save(log);
            connectorFacade.search(system.getConnectorInstance(), connectorConfig, objectClass, filter, resultHandler);
            // Execute sync for this tree and searched accounts
            processTreeSync(context, accountsMap);
            log = context.getLog();
        }
        // 
        log.addToLog(MessageFormat.format("Synchronization was correctly ended in {0}.", LocalDateTime.now()));
        synchronizationConfigService.save(config);
    } catch (Exception e) {
        String message = "Error during synchronization";
        log.addToLog(message);
        log.setContainsError(true);
        log.addToLog(Throwables.getStackTraceAsString(e));
        LOG.error(message, e);
    } finally {
        log.setRunning(false);
        log.setEnded(LocalDateTime.now());
        log = synchronizationLogService.save(log);
        // 
        longRunningTaskExecutor.setCount(longRunningTaskExecutor.getCounter());
        longRunningTaskExecutor.updateState();
        // Clear cache
        this.clearCache();
    }
    return config;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) HashMap(java.util.HashMap) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Aggregations

SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)62 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)43 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)42 Test (org.junit.Test)42 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)41 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)38 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)31 SysSyncActionLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter)27 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)27 SysSyncItemLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter)25 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)22 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)21 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)14 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)12 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)12 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)12 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)10 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 DefaultSynchronizationServiceTest (eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)8