Search in sources :

Example 21 with AbstractSysSyncConfigDto

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

the class IdentityContractSyncTest method defaultWorkPositionTest.

@Test
public void defaultWorkPositionTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    helper.createIdentity(CONTRACT_LEADER_TWO);
    // Set default tree type to sync configuration
    IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
    Assert.assertNotNull(treeType);
    SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
    configContract.setDefaultTreeType(treeType.getId());
    // Set default tree node to sync configuration
    IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
    nodeFilter.setCode("one");
    nodeFilter.setTreeTypeId(treeType.getId());
    List<IdmTreeNodeDto> nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(1, nodes.size());
    IdmTreeNodeDto defaultNode = nodes.get(0);
    configContract.setDefaultTreeNode(defaultNode.getId());
    config = syncConfigService.save(configContract);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    // Start sync
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // Default work positions must be set
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    Assert.assertEquals(defaultNode.getId(), contractsOne.get(0).getWorkPosition());
    contractFilter.setValue("2");
    List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsTwo.size());
    Assert.assertEquals(defaultNode.getId(), contractsTwo.get(0).getWorkPosition());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(defaultNode.getId(), contractsThree.get(0).getWorkPosition());
    // Delete log
    syncLogService.delete(log);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with AbstractSysSyncConfigDto

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

the class AbstractSynchronizationExecutor method handleIcObject.

/**
 * Handle IC connector object
 *
 * @param tokenAttribute
 * @param itemContext
 * @return
 */
protected boolean handleIcObject(SynchronizationContext itemContext) {
    Assert.notNull(itemContext);
    String uid = itemContext.getUid();
    IcConnectorObject icObject = itemContext.getIcObject();
    AbstractSysSyncConfigDto config = itemContext.getConfig();
    SysSyncLogDto log = itemContext.getLog();
    List<SysSyncActionLogDto> actionLogs = itemContext.getActionLogs();
    AttributeMapping tokenAttribute = itemContext.getTokenAttribute();
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    // Synchronization by custom filter not supported DELETE
    // event
    IcSyncDeltaTypeEnum type = IcSyncDeltaTypeEnum.CREATE_OR_UPDATE;
    itemContext.addLogItem(itemLog).addType(type);
    // Find token by token attribute
    // For Reconciliation can be token attribute null
    Object tokenObj = null;
    if (tokenAttribute != null) {
        tokenObj = getValueByMappedAttribute(tokenAttribute, icObject.getAttributes(), itemContext);
    }
    // Token is saved in Sync as String, therefore we transform token (from
    // IcObject) to String too.
    String token = tokenObj != null ? tokenObj.toString() : null;
    if (token != null && config.getToken() != null && token.compareTo(config.getToken()) <= -1) {
        token = config.getToken();
    }
    // Save token
    log.setToken(token);
    config.setToken(token);
    boolean result = startItemSynchronization(itemContext);
    // We reload log (maybe was synchronization canceled)
    longRunningTaskExecutor.increaseCounter();
    log.setRunning(synchronizationLogService.get(log.getId()).isRunning());
    if (!log.isRunning()) {
        result = false;
    }
    if (!result) {
        log.setRunning(false);
        log.addToLog(MessageFormat.format("Synchronization canceled during resolve UID [{0}]", uid));
        addToItemLog(itemLog, "Canceled!");
        initSyncActionLog(SynchronizationActionType.IGNORE, OperationResultType.WARNING, itemLog, log, actionLogs);
    }
    return result;
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 23 with AbstractSysSyncConfigDto

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

the class AbstractSynchronizationExecutor method exportEntity.

/**
 * Start export item (entity) to target resource
 *
 * @param itemBuilder
 * @param uidAttribute
 * @param entity
 */
protected void exportEntity(SynchronizationContext itemBuilder, SysSystemAttributeMappingDto uidAttribute, AbstractDto entity) {
    SystemEntityType entityType = itemBuilder.getEntityType();
    AbstractSysSyncConfigDto config = itemBuilder.getConfig();
    SysSyncLogDto log = itemBuilder.getLog();
    List<SysSyncActionLogDto> actionsLog = itemBuilder.getActionLogs();
    SysSystemDto system = itemBuilder.getSystem();
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    try {
        // Default setting for log item
        itemLog.setIdentification(entity.getId().toString());
        itemLog.setDisplayName(this.getDisplayNameForEntity(entity));
        itemLog.setType(entityType.getEntityType().getSimpleName());
        itemLog.addToLog(MessageFormat.format("Start export for entity [{0}].", this.getDisplayNameForEntity(entity)));
        UUID accountId = this.getAccountByEntity(entity.getId(), system.getId());
        if (accountId != null) {
            initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.IGNORE, itemLog, log, actionsLog);
            itemLog.addToLog(MessageFormat.format("For entity [{0}] was found AccAccount [{1}]. Export for this entity ends (only entity without AccAccount can be export)!", this.getDisplayNameForEntity(entity), accountId));
            return;
        }
        String uid = systemAttributeMappingService.generateUid(entity, uidAttribute);
        // Do export for one item (produces event)
        // Start in new Transaction
        // 
        itemBuilder.addUid(uid).addConfig(// 
        config).addSystem(// 
        system).addEntityType(// 
        entityType).addEntityId(entity.getId()).addLog(// 
        log).addLogItem(// 
        itemLog).addActionLogs(// 
        actionsLog).addExportAction(true);
        CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
        event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemBuilder);
        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);
        }
        // We reload log (maybe was synchronization canceled)
        log.setRunning(synchronizationLogService.get(log.getId()).isRunning());
        if (!log.isRunning()) {
            result = false;
        }
        if (!result) {
            log.setRunning(false);
            log.addToLog(MessageFormat.format("Synchronization canceled during resolve UID [{0}]", uid));
            addToItemLog(itemLog, "Canceled!");
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.WARNING, itemLog, log, actionsLog);
        }
    } catch (Exception ex) {
        String message = MessageFormat.format("Export - error for entity {0}", entity.getId());
        log.addToLog(message);
        log.addToLog(Throwables.getStackTraceAsString(ex));
        LOG.error(message, ex);
    } finally {
        config = synchronizationConfigService.save(config);
        boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
        actionsLog = (List<SysSyncActionLogDto>) syncActionLogService.saveAll(actionsLog);
        // 
        if (!existingItemLog) {
            addToItemLog(itemLog, MessageFormat.format("Missing action log for entity {0}!", entity.getId()));
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
            itemLog = syncItemLogService.save(itemLog);
        }
    }
}
Also used : SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) 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) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 24 with AbstractSysSyncConfigDto

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

the class AbstractSynchronizationExecutor method doItemSynchronization.

@Override
public boolean doItemSynchronization(SynchronizationContext context) {
    Assert.notNull(context);
    String uid = context.getUid();
    IcConnectorObject icObject = context.getIcObject();
    IcSyncDeltaTypeEnum type = context.getType();
    AbstractSysSyncConfigDto config = context.getConfig();
    SysSystemDto system = context.getSystem();
    SystemEntityType entityType = context.getEntityType();
    AccAccountDto account = context.getAccount();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    // Set default unknown action type
    context.addActionType(SynchronizationActionType.UNKNOWN);
    try {
        // Find system entity for uid
        SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
        context.addSystemEntity(systemEntity);
        // Find acc account for uid or system entity
        if (account == null) {
            account = findAccount(context);
            if (systemEntity == null) {
                addToItemLog(logItem, "SystemEntity for this uid doesn't exist. We will create it.");
                systemEntity = createSystemEntity(uid, entityType, system);
            }
        }
        context.addSystemEntity(systemEntity).addAccount(account);
        if (IcSyncDeltaTypeEnum.CREATE == type || IcSyncDeltaTypeEnum.UPDATE == type || IcSyncDeltaTypeEnum.CREATE_OR_UPDATE == type) {
            // Update or create
            Assert.notNull(icObject);
            List<IcAttribute> icAttributes = icObject.getAttributes();
            if (account == null) {
                // Account doesn't exist in IDM
                resolveAccountNotExistSituation(context, systemEntity, icAttributes);
            } else {
                // Account exist in IdM (LINKED)
                context.addActionType(config.getLinkedAction().getAction());
                SynchronizationSituationType situation = SynchronizationSituationType.LINKED;
                if (StringUtils.hasLength(config.getLinkedActionWfKey())) {
                    SynchronizationLinkedActionType linkedAction = config.getLinkedAction();
                    SynchronizationActionType action = linkedAction.getAction();
                    // We will start specific workflow
                    startWorkflow(config.getLinkedActionWfKey(), situation, action, null, context);
                } else {
                    resolveLinkedSituation(config.getLinkedAction(), context);
                }
                addToItemLog(logItem, "Account exist in IdM (LINKED) - ended");
            }
        } else if (IcSyncDeltaTypeEnum.DELETE == type) {
            // Missing account situation, can be call from connector
            // (support delete account event) and from reconciliation
            context.addActionType(config.getMissingAccountAction().getAction());
            SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ACCOUNT;
            if (StringUtils.hasLength(config.getMissingAccountActionWfKey())) {
                ReconciliationMissingAccountActionType missingAccountActionType = config.getMissingAccountAction();
                SynchronizationActionType action = missingAccountActionType.getAction();
                // We will start specific workflow
                startWorkflow(config.getMissingAccountActionWfKey(), situation, action, null, context);
            } else {
                // Resolve missing account situation for one item
                this.resolveMissingAccountSituation(config.getMissingAccountAction(), context);
            }
        } else if (context.isExportAction()) {
            // Export situation - create account to system
            this.resolveUnlinkedSituation(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT, context);
        }
        // Call hard hibernate session flush and clear
        if (getHibernateSession().isOpen()) {
            getHibernateSession().flush();
            getHibernateSession().clear();
        }
        return true;
    } catch (Exception e) {
        loggingException(context.getActionType(), log, logItem, actionLogs, uid, e);
        throw e;
    }
}
Also used : SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 25 with AbstractSysSyncConfigDto

use of eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto 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
 * @return
 */
protected void resolveAccountNotExistSituation(SynchronizationContext context, SysSystemEntityDto systemEntity, List<IcAttribute> icAttributes) {
    Assert.notNull(context);
    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)

Aggregations

AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)63 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)42 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 Test (org.junit.Test)38 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)33 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)31 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)31 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)29 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)24 SysSyncActionLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter)24 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)24 SysSyncItemLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter)23 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)17 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)11 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)10 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)10 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)9 SynchronizationContext (eu.bcvsolutions.idm.acc.domain.SynchronizationContext)8