Search in sources :

Example 1 with ObjectSynchronizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.

the class CorrelationConfirmationEvaluator method matchUserCorrelationRule.

public <F extends FocusType> boolean matchUserCorrelationRule(Class<F> focusType, PrismObject<ShadowType> currentShadow, PrismObject<F> userType, ObjectSynchronizationType synchronization, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) {
    if (synchronization == null) {
        LOGGER.warn("Resource does not support synchronization. Skipping evaluation correlation/confirmation for  {} and  {}", userType, currentShadow);
        return false;
    }
    List<ConditionalSearchFilterType> conditionalFilters = synchronization.getCorrelation();
    try {
        for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
            if (matchUserCorrelationRule(focusType, currentShadow, userType, resourceType, configurationType, conditionalFilter, task, result)) {
                LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} match user: {}", currentShadow, userType);
                return true;
            }
        }
    } catch (SchemaException ex) {
        throw new SystemException("Failed to match user using correlation rule. " + ex.getMessage(), ex);
    }
    LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} does not match user: {}", new Object[] { currentShadow, userType });
    return false;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType)

Example 2 with ObjectSynchronizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(PrismObject<? extends ShadowType> currentShadow, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    ShadowType currentShadowType = currentShadow.asObjectable();
    // objectClass
    QName shadowObjectClass = currentShadowType.getObjectClass();
    Validate.notNull(shadowObjectClass, "No objectClass in currentShadow");
    return isPolicyApplicable(shadowObjectClass, currentShadowType.getKind(), currentShadowType.getIntent(), synchronizationPolicy, resource);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName)

Example 3 with ObjectSynchronizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
    if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
        String policyIntent = synchronizationPolicy.getIntent();
        ShadowKindType policyKind = synchronizationPolicy.getKind();
        ObjectClassComplexTypeDefinition policyObjectClass = null;
        RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (schema == null) {
            throw new SchemaException("No schema defined in resource. Possible configuration problem?");
        }
        if (policyKind == null && policyIntent == null) {
            policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
        }
        if (policyKind != null) {
            if (StringUtils.isEmpty(policyIntent)) {
                policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
            } else {
                policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
            }
        }
        if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
            return false;
        }
    }
    if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
        if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
            return false;
        }
    }
    // kind
    ShadowKindType policyKind = synchronizationPolicy.getKind();
    if (policyKind != null && kind != null && !policyKind.equals(kind)) {
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    String policyIntent = synchronizationPolicy.getIntent();
    if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
        return false;
    }
    return true;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 4 with ObjectSynchronizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.

the class ExpressionHandlerImplTest method testEvaluateExpression.

@SuppressWarnings("unchecked")
@Test
public void testEvaluateExpression() throws Exception {
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
    ShadowType accountType = account.asObjectable();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
    ResourceType resourceType = resource.asObjectable();
    accountType.setResource(resourceType);
    ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
    for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
        MapXNode clauseXNode = filter.getFilterClauseXNode();
        // key = q:equal, value = map (path + expression)
        RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
        ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
        LOGGER.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
        OperationResult result = new OperationResult("testCorrelationRule");
        String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
        LOGGER.info(result.debugDump());
        assertEquals("Wrong expression result", "hbarbossa", name);
    }
}
Also used : ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) File(java.io.File) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Test(org.testng.annotations.Test)

Example 5 with ObjectSynchronizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method notifyChange.

@Override
public void notifyChange(ResourceObjectShadowChangeDescription change, Task task, OperationResult parentResult) {
    validate(change);
    Validate.notNull(parentResult, "Parent operation result must not be null.");
    boolean logDebug = isLogDebug(change);
    if (logDebug) {
        LOGGER.debug("SYNCHRONIZATION: received change notification {}", change);
    } else {
        LOGGER.trace("SYNCHRONIZATION: received change notification {}", change);
    }
    OperationResult subResult = parentResult.createSubresult(NOTIFY_CHANGE);
    PrismObject<? extends ShadowType> currentShadow = change.getCurrentShadow();
    PrismObject<? extends ShadowType> applicableShadow = currentShadow;
    if (applicableShadow == null) {
        // We need this e.g. in case of delete
        applicableShadow = change.getOldShadow();
    }
    SynchronizationEventInformation eventInfo = new SynchronizationEventInformation(applicableShadow, change.getSourceChannel(), task);
    try {
        ResourceType resourceType = change.getResource().asObjectable();
        PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(subResult);
        ObjectSynchronizationType synchronizationPolicy = determineSynchronizationPolicy(resourceType, applicableShadow, configuration, task, subResult);
        if (LOGGER.isTraceEnabled()) {
            String policyDesc = null;
            if (synchronizationPolicy != null) {
                if (synchronizationPolicy.getName() == null) {
                    policyDesc = "(kind=" + synchronizationPolicy.getKind() + ", intent=" + synchronizationPolicy.getIntent() + ", objectclass=" + synchronizationPolicy.getObjectClass() + ")";
                } else {
                    policyDesc = synchronizationPolicy.getName();
                }
            }
            LOGGER.trace("SYNCHRONIZATION determined policy: {}", policyDesc);
        }
        if (synchronizationPolicy == null) {
            String message = "SYNCHRONIZATION no matching policy for " + applicableShadow + " (" + applicableShadow.asObjectable().getObjectClass() + ") " + " on " + resourceType + ", ignoring change from channel " + change.getSourceChannel();
            LOGGER.debug(message);
            subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
            eventInfo.setNoSynchronizationPolicy();
            eventInfo.record(task);
            return;
        }
        if (!isSynchronizationEnabled(synchronizationPolicy)) {
            String message = "SYNCHRONIZATION is not enabled for " + resourceType + " ignoring change from channel " + change.getSourceChannel();
            LOGGER.debug(message);
            subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
            eventInfo.setSynchronizationNotEnabled();
            eventInfo.record(task);
            return;
        }
        // defined in task
        if (!satisfyTaskConstraints(synchronizationPolicy, task)) {
            LOGGER.trace("SYNCHRONIZATION skipping {} because it does not match kind/intent defined in task", new Object[] { applicableShadow });
            subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Skipped because it does not match objectClass/kind/intent");
            eventInfo.setDoesNotMatchTaskSpecification();
            eventInfo.record(task);
            return;
        }
        if (isProtected((PrismObject<ShadowType>) currentShadow)) {
            if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
                List<PropertyDelta<?>> modifications = SynchronizationUtils.createSynchronizationTimestampsDelta(currentShadow);
                PropertyDelta<String> intentDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, currentShadow.getDefinition(), synchronizationPolicy.getIntent());
                modifications.add(intentDelta);
                try {
                    repositoryService.modifyObject(ShadowType.class, currentShadow.getOid(), modifications, subResult);
                    task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, null);
                } catch (Throwable t) {
                    task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, t);
                } finally {
                    task.markObjectActionExecutedBoundary();
                }
            }
            subResult.recordSuccess();
            eventInfo.record(task);
            LOGGER.debug("SYNCHRONIZATION: DONE (dry run) for protected shadow {}", currentShadow);
            return;
        }
        Class<? extends FocusType> focusType = determineFocusClass(synchronizationPolicy, resourceType);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Synchronization is enabled, focus class: {}, found applicable policy: {}", focusType, Utils.getPolicyDesc(synchronizationPolicy));
        }
        SynchronizationSituation situation = determineSituation(focusType, change, synchronizationPolicy, configuration.asObjectable(), task, subResult);
        if (logDebug) {
            LOGGER.debug("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
        } else {
            LOGGER.trace("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
        }
        eventInfo.setOriginalSituation(situation.getSituation());
        // overwritten
        eventInfo.setNewSituation(situation.getSituation());
        if (change.isUnrelatedChange() || Utils.isDryRun(task)) {
            PrismObject object = null;
            if (change.getCurrentShadow() != null) {
                object = change.getCurrentShadow();
            } else if (change.getOldShadow() != null) {
                object = change.getOldShadow();
            }
            Collection modifications = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(object, situation.getSituation(), task.getChannel(), false);
            if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
                modifications.add(PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, object.getDefinition(), synchronizationPolicy.getIntent()));
            }
            try {
                repositoryService.modifyObject(ShadowType.class, object.getOid(), modifications, subResult);
                task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
            } catch (Throwable t) {
                task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
            } finally {
                task.markObjectActionExecutedBoundary();
            }
            subResult.recordSuccess();
            eventInfo.record(task);
            LOGGER.debug("SYNCHRONIZATION: DONE (dry run/unrelated) for {}", object);
            return;
        }
        // must be here, because when the reaction has no action, the
        // situation will be not set.
        PrismObject<ShadowType> newCurrentShadow = saveSyncMetadata((PrismObject<ShadowType>) currentShadow, situation, change, synchronizationPolicy, task, parentResult);
        if (newCurrentShadow != null) {
            change.setCurrentShadow(newCurrentShadow);
        }
        SynchronizationSituationType newSituation = reactToChange(focusType, change, synchronizationPolicy, situation, resourceType, logDebug, configuration, task, subResult);
        eventInfo.setNewSituation(newSituation);
        eventInfo.record(task);
        subResult.computeStatus();
    } catch (SystemException ex) {
        // avoid unnecessary re-wrap
        eventInfo.setException(ex);
        eventInfo.record(task);
        subResult.recordFatalError(ex);
        throw ex;
    } catch (Exception ex) {
        eventInfo.setException(ex);
        eventInfo.record(task);
        subResult.recordFatalError(ex);
        throw new SystemException(ex);
    } finally {
        task.markObjectActionExecutedBoundary();
    // if (LOGGER.isTraceEnabled()) {
    // LOGGER.trace(subResult.dump());
    // }
    }
    LOGGER.debug("SYNCHRONIZATION: DONE for {}", currentShadow);
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) Collection(java.util.Collection) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectSynchronizationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 SystemException (com.evolveum.midpoint.util.exception.SystemException)5 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)5 SynchronizationSituationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType)5 QName (javax.xml.namespace.QName)5 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)4 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ConditionalSearchFilterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType)4 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3