Search in sources :

Example 1 with IcSyncToken

use of eu.bcvsolutions.idm.ic.api.IcSyncToken in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method process.

@Override
public AbstractSysSyncConfigDto process(UUID synchronizationConfigId) {
    // Clear cache
    idmCacheManager.evictCache(CACHE_NAME);
    SysSyncLogDto log = new SysSyncLogDto();
    // Create basic synchronization log
    log.setSynchronizationConfig(synchronizationConfigId);
    log.setStarted(ZonedDateTime.now());
    try {
        // 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();
        SysSystemMappingDto systemMapping = systemMappingService.get(config.getSystemMapping());
        SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
        IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
        // Load last token
        String lastToken = config.isReconciliation() ? null : config.getToken();
        IcSyncToken lastIcToken = Strings.isNullOrEmpty(lastToken) ? null : new IcSyncTokenImpl(lastToken);
        log.setToken(lastToken != null ? lastToken : null);
        log.setRunning(true);
        log = syncStarted(log, context);
        // List of all accounts keys (used in reconciliation)
        Set<String> systemAccountsList = new HashSet<>();
        longRunningTaskExecutor.setCounter(0L);
        log = synchronizationLogService.save(log);
        List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
        // add logs to context
        context.addLog(log).addActionLogs(actionsLog);
        // Is differential sync enabled?
        if (config.isDifferentialSync()) {
            log.addToLog("Synchronization is running as differential (entities will be updated only if least one attribute was changed).");
        }
        if (config.isCustomFilter() || config.isReconciliation()) {
            // Custom filter Sync
            log.addToLog("Synchronization will use custom filter (not synchronization implemented in connector).");
            AttributeMapping tokenAttribute = null;
            if (config.getTokenAttribute() != null) {
                tokenAttribute = systemAttributeMappingService.get(config.getTokenAttribute());
            }
            if (tokenAttribute == null && !config.isReconciliation()) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
            }
            context.addTokenAttribute(tokenAttribute);
            // Resolve filter for custom search
            IcFilter filter = resolveSynchronizationFilter(config);
            log.addToLog(MessageFormat.format("Start search with filter [{0}].", filter != null ? filter : "NONE"));
            connectorFacade.search(systemService.getConnectorInstance(system), connectorConfig, objectClass, filter, new DefaultResultHandler(context, systemAccountsList));
        } else {
            // Inner Sync
            log.addToLog("Synchronization will use inner connector synchronization implementation.");
            DefalutSyncResultHandler syncResultsHandler = new DefalutSyncResultHandler(context, systemAccountsList);
            connectorFacade.synchronization(systemService.getConnectorInstance(system), connectorConfig, objectClass, lastIcToken, syncResultsHandler);
        }
        // We do reconciliation (find missing account)
        if (config.isReconciliation() && log.isRunning()) {
            startReconciliation(entityType, systemAccountsList, config, system, log, actionsLog);
        }
        // Sync is correctly ends if wasn't cancelled
        if (log.isRunning()) {
            log = syncCorrectlyEnded(log, context);
        }
        return synchronizationConfigService.save(config);
    } catch (Exception e) {
        String message = "Error during synchronization";
        log.addToLog(message);
        log.setContainsError(true);
        log.addToLog(Throwables.getStackTraceAsString(e));
        throw e;
    } finally {
        syncEnd(log, syncContext);
        log.setRunning(false);
        log.setEnded(ZonedDateTime.now());
        synchronizationLogService.save(log);
        // 
        longRunningTaskExecutor.setCount(longRunningTaskExecutor.getCounter());
        longRunningTaskExecutor.updateState();
        // Clear cache
        idmCacheManager.evictCache(CACHE_NAME);
    }
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) ArrayList(java.util.ArrayList) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) 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) 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) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) HashSet(java.util.HashSet)

Example 2 with IcSyncToken

use of eu.bcvsolutions.idm.ic.api.IcSyncToken in project CzechIdMng by bcvsolutions.

the class ConnIdIcConnectorService method synchronization.

@Override
public IcSyncToken synchronization(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcSyncToken token, IcSyncResultsHandler handler) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(objectClass, "Object class is required.");
    Assert.notNull(handler, "Handler is required.");
    LOG.debug("Start synchronization for connector {} and objectClass {} - ConnId", connectorInstance.getConnectorKey().toString(), objectClass.getDisplayName());
    ConnectorFacade conn = facadeFactory.getConnectorFacade(connectorInstance, connectorConfiguration);
    ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
    if (objectClassConnId == null) {
        objectClassConnId = ObjectClass.ACCOUNT;
    }
    SyncToken syncToken = ConnIdIcConvertUtil.convertIcSyncToken(token);
    SyncResultsHandler handlerConnId = new SyncResultsHandler() {

        @Override
        public boolean handle(SyncDelta delta) {
            return handler.handle(ConnIdIcConvertUtil.convertConnIdSyncDelta(delta));
        }
    };
    SyncToken resultToken = conn.sync(objectClassConnId, syncToken, handlerConnId, new OperationOptions(connectorConfiguration.getSystemOperationOptions()));
    return ConnIdIcConvertUtil.convertConnIdSyncToken(resultToken);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) IcSyncResultsHandler(eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler) SyncResultsHandler(org.identityconnectors.framework.common.objects.SyncResultsHandler)

Example 3 with IcSyncToken

use of eu.bcvsolutions.idm.ic.api.IcSyncToken in project CzechIdMng by bcvsolutions.

the class ConnIdIcConvertUtil method convertConnIdSyncDelta.

public static IcSyncDelta convertConnIdSyncDelta(SyncDelta delta) {
    if (delta == null) {
        return null;
    }
    IcSyncToken token = ConnIdIcConvertUtil.convertConnIdSyncToken(delta.getToken());
    IcSyncDeltaTypeEnum deltaType = IcSyncDeltaTypeEnum.valueOf(delta.getDeltaType().name());
    IcUidAttribute previousUid = ConnIdIcConvertUtil.convertConnIdUid(delta.getPreviousUid());
    IcObjectClass objectClass = ConnIdIcConvertUtil.convertConnIdObjectClass(delta.getObjectClass());
    IcUidAttribute uid = ConnIdIcConvertUtil.convertConnIdUid(delta.getUid());
    IcConnectorObject object = ConnIdIcConvertUtil.convertConnIdConnectorObject(delta.getObject());
    return new IcSyncDeltaImpl(token, deltaType, previousUid, objectClass, uid, object);
}
Also used : IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcSyncDeltaImpl(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaImpl) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute)

Aggregations

IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)3 IcSyncToken (eu.bcvsolutions.idm.ic.api.IcSyncToken)3 AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)1 SynchronizationContext (eu.bcvsolutions.idm.acc.domain.SynchronizationContext)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)1 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)1 IcSyncResultsHandler (eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler)1 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)1 IcFilter (eu.bcvsolutions.idm.ic.filter.api.IcFilter)1 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)1