Search in sources :

Example 11 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method updateConfidentialAttributes.

/**
 * Update confidential attribute for given entity. Entity must be persisted
 * first.
 *
 * @param mappedAttributes
 * @param uid
 * @param icAttributes
 * @param entity
 * @param create
 *            (is create or update entity situation)
 * @param context
 * @return
 */
protected DTO updateConfidentialAttributes(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, DTO dto, boolean create, SynchronizationContext context) {
    mappedAttributes.stream().filter(attribute -> {
        // Skip disabled attributes
        // Only for confidential attribute
        boolean fastResult = !attribute.isDisabledAttribute() && attribute.isConfidentialAttribute();
        if (!fastResult) {
            return false;
        }
        // Can be value set by attribute strategy?
        return this.canSetValue(uid, attribute, dto, create);
    }).forEach(attribute -> {
        String attributeProperty = attribute.getIdmPropertyName();
        Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
        // secured storage
        if (!(transformedValue == null || transformedValue instanceof GuardedString)) {
            throw new ProvisioningException(AccResultCode.CONFIDENTIAL_VALUE_IS_NOT_GUARDED_STRING, ImmutableMap.of("property", attributeProperty, "class", transformedValue.getClass().getName()));
        }
        confidentialStorage.saveGuardedString(dto.getId(), dto.getClass(), attribute.getIdmPropertyName(), (GuardedString) transformedValue);
    });
    return dto;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AttributeValueWrapperDto(eu.bcvsolutions.idm.acc.dto.AttributeValueWrapperDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Pair(org.apache.commons.lang3.tuple.Pair) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Map(java.util.Map) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) Set(java.util.Set) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) IcSyncResultsHandler(eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler) SynchronizationEventType(eu.bcvsolutions.idm.acc.event.SynchronizationEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) Session(org.hibernate.Session) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) CacheManager(org.springframework.cache.CacheManager) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcOrFilter(eu.bcvsolutions.idm.ic.filter.impl.IcOrFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) IcFilterBuilder(eu.bcvsolutions.idm.ic.filter.impl.IcFilterBuilder) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) Throwables(com.google.common.base.Throwables) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) LocalDateTime(org.joda.time.LocalDateTime) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VariableScope(org.activiti.engine.delegate.VariableScope) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) ValueWrapper(org.springframework.cache.Cache.ValueWrapper) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Cache(org.springframework.cache.Cache) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) CollectionUtils(org.apache.commons.collections.CollectionUtils) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IcSyncDelta(eu.bcvsolutions.idm.ic.api.IcSyncDelta) IcAndFilter(eu.bcvsolutions.idm.ic.filter.impl.IcAndFilter) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) DateTime(org.joda.time.DateTime) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Beta(com.google.common.annotations.Beta) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SynchronizationService(eu.bcvsolutions.idm.acc.service.api.SynchronizationService) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 12 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveSynchronizationFilter.

/**
 * Compile filter for search from filter attribute and filter script
 *
 * @param config
 * @return
 */
protected IcFilter resolveSynchronizationFilter(AbstractSysSyncConfigDto config) {
    // If is reconciliation, then is filter null
    if (config.isReconciliation()) {
        return null;
    }
    IcFilter filter = null;
    AttributeMapping filterAttributeMapping = null;
    if (config.getFilterAttribute() != null) {
        filterAttributeMapping = systemAttributeMappingService.get(config.getFilterAttribute());
    }
    String configToken = config.getToken();
    String filterScript = config.getCustomFilterScript();
    if (filterAttributeMapping == null && configToken == null && StringUtils.isEmpty(filterScript)) {
        return null;
    }
    if (filterAttributeMapping != null) {
        Object transformedValue = systemAttributeMappingService.transformValueToResource(null, configToken, filterAttributeMapping, config);
        if (transformedValue != null) {
            SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(filterAttributeMapping.getSchemaAttribute());
            IcAttributeImpl filterAttribute = new IcAttributeImpl(schemaAttributeDto.getName(), transformedValue);
            switch(config.getFilterOperation()) {
                case GREATER_THAN:
                    filter = IcFilterBuilder.greaterThan(filterAttribute);
                    break;
                case LESS_THAN:
                    filter = IcFilterBuilder.lessThan(filterAttribute);
                    break;
                case EQUAL_TO:
                    filter = IcFilterBuilder.equalTo(filterAttribute);
                    break;
                case CONTAINS:
                    filter = IcFilterBuilder.contains(filterAttribute);
                    break;
                case ENDS_WITH:
                    filter = IcFilterBuilder.endsWith(filterAttribute);
                    break;
                case STARTS_WITH:
                    filter = IcFilterBuilder.startsWith(filterAttribute);
                    break;
            }
        }
    }
    if (StringUtils.hasLength(filterScript)) {
        Map<String, Object> variables = new HashMap<>();
        variables.put("filter", filter);
        variables.put("token", configToken);
        List<Class<?>> allowTypes = new ArrayList<>();
        // Allow all IC filter operator
        for (IcFilterOperationType operation : IcFilterOperationType.values()) {
            allowTypes.add(operation.getImplementation());
        }
        allowTypes.add(IcAndFilter.class);
        allowTypes.add(IcOrFilter.class);
        allowTypes.add(IcFilterBuilder.class);
        allowTypes.add(IcAttributeImpl.class);
        allowTypes.add(IcAttribute.class);
        Object filterObj = groovyScriptService.evaluate(filterScript, variables, allowTypes);
        if (filterObj != null && !(filterObj instanceof IcFilter)) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_FILTER_VALUE_WRONG_TYPE, ImmutableMap.of("type", filterObj.getClass().getName()));
        }
        filter = (IcFilter) filterObj;
    }
    return filter;
}
Also used : HashMap(java.util.HashMap) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Example 13 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method fillEntity.

/**
 * Fill entity with attributes from IC module (by mapped attributes).
 *
 * @param mappedAttributes
 * @param uid
 * @param icAttributes
 * @param entity
 * @param create
 *            (is create or update entity situation)
 * @param context
 * @return
 */
protected DTO fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, DTO dto, boolean create, SynchronizationContext context) {
    mappedAttributes.stream().filter(attribute -> {
        // Skip disabled attributes
        // Skip extended attributes (we need update/ create entity first)
        // Skip confidential attributes (we need update/ create entity
        // first)
        boolean fastResult = !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && !attribute.isConfidentialAttribute();
        if (!fastResult) {
            return false;
        }
        // Can be value set by attribute strategy?
        return this.canSetValue(uid, attribute, dto, create);
    }).forEach(attribute -> {
        String attributeProperty = attribute.getIdmPropertyName();
        Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
        // Set transformed value from target system to entity
        try {
            EntityUtils.setEntityValue(dto, attributeProperty, transformedValue);
        } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException e) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_NOT_SET, ImmutableMap.of("property", attributeProperty, "uid", uid), e);
        }
    });
    return dto;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AttributeValueWrapperDto(eu.bcvsolutions.idm.acc.dto.AttributeValueWrapperDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Pair(org.apache.commons.lang3.tuple.Pair) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Map(java.util.Map) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) Set(java.util.Set) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) IcSyncResultsHandler(eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler) SynchronizationEventType(eu.bcvsolutions.idm.acc.event.SynchronizationEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) Session(org.hibernate.Session) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) CacheManager(org.springframework.cache.CacheManager) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcOrFilter(eu.bcvsolutions.idm.ic.filter.impl.IcOrFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) IcFilterBuilder(eu.bcvsolutions.idm.ic.filter.impl.IcFilterBuilder) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) Throwables(com.google.common.base.Throwables) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) LocalDateTime(org.joda.time.LocalDateTime) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VariableScope(org.activiti.engine.delegate.VariableScope) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) ValueWrapper(org.springframework.cache.Cache.ValueWrapper) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Cache(org.springframework.cache.Cache) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) CollectionUtils(org.apache.commons.collections.CollectionUtils) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IcSyncDelta(eu.bcvsolutions.idm.ic.api.IcSyncDelta) IcAndFilter(eu.bcvsolutions.idm.ic.filter.impl.IcAndFilter) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) DateTime(org.joda.time.DateTime) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Beta(com.google.common.annotations.Beta) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SynchronizationService(eu.bcvsolutions.idm.acc.service.api.SynchronizationService) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IntrospectionException(java.beans.IntrospectionException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 14 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor 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();
    SysSystemMappingDto systemMapping = systemMappingService.get(config.getSystemMapping());
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
    IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
    // Load last token
    Object lastToken = config.isReconciliation() ? null : config.getToken();
    IcSyncToken lastIcToken = lastToken != null ? new IcSyncTokenImpl(lastToken) : null;
    // 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 keys (used in reconciliation)
    Set<String> systemAccountsList = new HashSet<>();
    // TODO: Export is not fully implemented (FE, configuration and Groovy
    // part missing)
    boolean export = false;
    longRunningTaskExecutor.setCounter(0L);
    try {
        log = synchronizationLogService.save(log);
        List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
        // add logs to context
        context.addLog(log).addActionLogs(actionsLog);
        if (export) {
            // Start exporting entities to resource
            log.addToLog("Exporting entities to resource started...");
            this.startExport(entityType, config, context.getMappedAttributes(), log, actionsLog);
        } else 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(system.getConnectorInstance(), 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(system.getConnectorInstance(), 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);
        }
        config = 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) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) HashSet(java.util.HashSet) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) 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) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Example 15 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method validate.

/**
 * Validate synchronization on: Exist, enable, running, has mapping, has
 * connector key, has connector configuration
 *
 * @param synchronizationConfigId
 * @return
 */
protected SynchronizationContext validate(UUID synchronizationConfigId) {
    SynchronizationContext context = new SynchronizationContext();
    AbstractSysSyncConfigDto config = synchronizationConfigService.get(synchronizationConfigId);
    // 
    if (config == null) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_NOT_FOUND, ImmutableMap.of("id", synchronizationConfigId));
    }
    // Synchronization must be enabled
    if (!config.isEnabled()) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_NOT_ENABLED, ImmutableMap.of("name", config.getName()));
    }
    // Synchronization can not be running twice
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(config.getId());
    logFilter.setRunning(Boolean.TRUE);
    if (!synchronizationLogService.find(logFilter, null).getContent().isEmpty()) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_RUNNING, ImmutableMap.of("name", config.getName()));
    }
    SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
    Assert.notNull(mapping);
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(schemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    Assert.notNull(system);
    // System must be enabled
    if (system.isDisabled()) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_SYSTEM_IS_NOT_ENABLED, ImmutableMap.of("name", config.getName(), "system", system.getName()));
    }
    SystemEntityType entityType = mapping.getEntityType();
    SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
    attributeHandlingFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> mappedAttributes = systemAttributeMappingService.find(attributeHandlingFilter, null).getContent();
    // Find connector identification persisted in system
    IcConnectorKey connectorKey = system.getConnectorKey();
    if (connectorKey == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // Find connector configuration persisted in system
    IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
    if (connectorConfig == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    context.addConfig(config).addSystem(system).addEntityType(entityType).addMappedAttributes(mappedAttributes).addConnectorConfig(connectorConfig);
    return context;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Aggregations

ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)41 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)19 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)15 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)14 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)14 List (java.util.List)13 UUID (java.util.UUID)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)12 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)12 SysSchemaObjectClassService (eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService)12 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)12 SysSystemMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService)12 ArrayList (java.util.ArrayList)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)11 SysSchemaAttributeService (eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService)11