Search in sources :

Example 1 with SysSyncItemLogDto

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

the class IdentityContractSyncTest method checkSyncLog.

private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count) {
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(config.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return actionType == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(count, items.size());
    return log;
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 2 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method updateAccountUid.

/**
 * Update account UID from system. UID mapped attribute must exist and returned
 * value must be not null and must be String
 *
 * @param context
 */
private void updateAccountUid(SynchronizationContext context) {
    Assert.notNull(context, "Context is required!");
    SysSyncItemLogDto logItem = context.getLogItem();
    AccAccountDto account = context.getAccount();
    // Generate UID value from mapped attribute marked as UID (Unique ID).
    // UID mapped attribute must exist and returned value must be not null
    // and must be String
    String attributeUid = this.generateUID(context);
    if (!account.getUid().equals(attributeUid)) {
        addToItemLog(logItem, MessageFormat.format("IdM Account UID [{0}] is different [{1}]. We will update it.", account.getUid(), attributeUid));
        account.setUid(attributeUid);
        accountService.save(account);
    }
}
Also used : SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 3 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method resolveAccountNotExistSituation.

/**
 * Resolve "Account doesn't exist in IDM" situation. Result can be UNLINKED or
 * UNMATCHED situations.
 *
 * @param context
 * @param systemEntity
 * @param icAttributes
 */
protected void resolveAccountNotExistSituation(SynchronizationContext context, SysSystemEntityDto systemEntity, List<IcAttribute> icAttributes) {
    Assert.notNull(context, "Context is required.");
    AbstractSysSyncConfigDto config = context.getConfig();
    SysSyncItemLogDto logItem = context.getLogItem();
    addToItemLog(logItem, "Account doesn't exist in IdM");
    DTO entity = findByCorrelationAttribute(systemAttributeMappingService.get(config.getCorrelationAttribute()), icAttributes, context);
    if (entity != null) {
        // Account not exist but, entity by correlation was
        // found (UNLINKED)
        context.addActionType(config.getUnlinkedAction().getAction());
        SynchronizationSituationType situation = SynchronizationSituationType.UNLINKED;
        if (StringUtils.hasLength(config.getUnlinkedActionWfKey())) {
            SynchronizationUnlinkedActionType unlinkedActionType = config.getUnlinkedAction();
            SynchronizationActionType action = unlinkedActionType.getAction();
            // We will start specific workflow
            startWorkflow(config.getUnlinkedActionWfKey(), situation, action, entity, context);
        } else {
            context.addEntityId(entity.getId()).addSystemEntity(systemEntity);
            resolveUnlinkedSituation(config.getUnlinkedAction(), context);
        }
    } else {
        // Account not exist and entity too (UNMATCHED)
        context.addActionType(config.getMissingEntityAction().getAction());
        SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ENTITY;
        if (StringUtils.hasLength(config.getMissingEntityActionWfKey())) {
            SynchronizationMissingEntityActionType missingEntityAction = config.getMissingEntityAction();
            SynchronizationActionType action = missingEntityAction.getAction();
            // We will start specific workflow
            startWorkflow(config.getMissingEntityActionWfKey(), situation, action, entity, context);
        } else {
            resolveMissingEntitySituation(config.getMissingEntityAction(), context);
        }
    }
}
Also used : SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType)

Example 4 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method startReconciliation.

/**
 * Start reconciliation. Is call after synchronization. Main purpose is find and
 * resolve missing accounts
 *
 * @param entityType
 * @param allAccountsSet
 * @param config
 * @param system
 * @param log
 * @param actionsLog
 */
protected void startReconciliation(SystemEntityType entityType, Set<String> allAccountsSet, AbstractSysSyncConfigDto config, SysSystemDto system, SysSyncLogDto log, List<SysSyncActionLogDto> actionsLog) {
    if (!log.isRunning()) {
        return;
    }
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setSystemId(system.getId());
    List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
    for (AccAccountDto account : accounts) {
        if (!log.isRunning()) {
            return;
        }
        String uid = account.getRealUid();
        if (!allAccountsSet.contains(uid)) {
            SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
            try {
                // Default setting for log item
                itemLog.setIdentification(uid);
                itemLog.setDisplayName(uid);
                itemLog.setType(entityType.getEntityType().getSimpleName());
                // Do reconciliation for one item (produces event)
                // Start in new Transaction
                SynchronizationContext builder = new SynchronizationContext();
                builder.addUid(uid).addType(IcSyncDeltaTypeEnum.DELETE).addConfig(config).addSystem(system).addEntityType(entityType).addAccount(account).addLog(log).addLogItem(itemLog).addActionLogs(actionsLog);
                CoreEvent<SysSyncItemLogDto> event = new CoreEvent<>(SynchronizationEventType.START_ITEM, itemLog);
                event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, builder);
                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);
                }
                // Update (increased counter) and check state of sync (maybe was cancelled from
                // sync or LRT)
                updateAndCheckState(result, log);
            } catch (Exception ex) {
                String message = MessageFormat.format("Reconciliation - error for uid [{0}]", uid);
                log.addToLog(message);
                log.addToLog(Throwables.getStackTraceAsString(ex));
                LOG.error(message, ex);
            } 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);
                    syncItemLogService.save(itemLog);
                }
            }
        }
    }
}
Also used : SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) 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)

Example 5 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method resolveLinkedSituation.

/**
 * Method for resolve linked situation for one item.
 *
 * @param action
 * @param context
 */
@Override
public void resolveLinkedSituation(SynchronizationLinkedActionType 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, MessageFormat.format("IdM Account [{0}] exists in IDM (LINKED)", account.getUid()));
    addToItemLog(logItem, MessageFormat.format("Linked action is [{0}]", action));
    switch(action) {
        case IGNORE:
            // Linked action is IGNORE. We will do nothing
            initSyncActionLog(SynchronizationActionType.LINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case UNLINK:
            // Linked action is UNLINK
            updateAccountUid(context);
            doUnlink(account, false, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UNLINK_AND_REMOVE_ROLE:
            // Linked action is UNLINK_AND_REMOVE_ROLE
            updateAccountUid(context);
            doUnlink(account, true, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UPDATE_ENTITY:
            // Linked action is UPDATE_ENTITY
            updateAccountUid(context);
            doUpdateEntity(context);
            if (context.getConfig().isDifferentialSync() && !context.isEntityDifferent()) {
                // If differential sync is enabled and this entity should be not updated, then
                // set item to ignore action.
                initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.IGNORE, logItem, log, actionLogs);
                return;
            }
            initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UPDATE_ACCOUNT:
            // Linked action is UPDATE_ACCOUNT
            updateAccountUid(context);
            doUpdateAccount(account, entityType, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
        default:
            break;
    }
}
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)

Aggregations

SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)60 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)43 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)43 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)38 SysSyncActionLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter)29 SysSyncItemLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter)27 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)26 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)24 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)24 Test (org.junit.Test)24 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)20 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)19 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)17 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)16 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)11 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)10 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)10