Search in sources :

Example 66 with ObjectType

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

the class FocusProcessor method recordEffectiveStatusDelta.

private <F extends ObjectType> void recordEffectiveStatusDelta(LensFocusContext<F> focusContext, ActivationStatusType effectiveStatusNew, XMLGregorianCalendar now) throws SchemaException {
    PrismContainerDefinition<ActivationType> activationDefinition = getActivationDefinition();
    // We always want explicit delta for effective status even if there is no real change
    // we want to propagate enable/disable events to all the resources, even if we are enabling
    // already enabled user (some resources may be disabled)
    // This may produce duplicate delta, but that does not matter too much. The duplicate delta
    // will be filtered out later.
    PrismPropertyDefinition<ActivationStatusType> effectiveStatusDef = activationDefinition.findPropertyDefinition(ActivationType.F_EFFECTIVE_STATUS);
    PropertyDelta<ActivationStatusType> effectiveStatusDelta = effectiveStatusDef.createEmptyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS));
    effectiveStatusDelta.setValueToReplace(new PrismPropertyValue<ActivationStatusType>(effectiveStatusNew, OriginType.USER_POLICY, null));
    if (!focusContext.alreadyHasDelta(effectiveStatusDelta)) {
        focusContext.swallowToProjectionWaveSecondaryDelta(effectiveStatusDelta);
    }
    // It is not enough to check alreadyHasDelta(). The change may happen in previous waves
    // and the secondary delta may no longer be here. When it comes to disableTimestamp we even
    // cannot rely on natural filtering of already executed deltas as the timestamp here may
    // be off by several milliseconds. So explicitly check for the change here. 
    PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
    if (objectCurrent != null) {
        PrismProperty<ActivationStatusType> effectiveStatusPropCurrent = objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_EFFECTIVE_STATUS);
        if (effectiveStatusPropCurrent != null && effectiveStatusNew.equals(effectiveStatusPropCurrent.getRealValue())) {
            LOGGER.trace("Skipping setting disableTimestamp because there was no change");
            return;
        }
    }
    PropertyDelta<XMLGregorianCalendar> timestampDelta = LensUtil.createActivationTimestampDelta(effectiveStatusNew, now, activationDefinition, OriginType.USER_POLICY);
    if (!focusContext.alreadyHasDelta(timestampDelta)) {
        focusContext.swallowToProjectionWaveSecondaryDelta(timestampDelta);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 67 with ObjectType

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

the class ReconciliationProcessor method processReconciliationFocus.

private <F extends ObjectType> void processReconciliationFocus(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    OperationResult subResult = result.createMinorSubresult(PROCESS_RECONCILIATION);
    try {
        // reconciliation is cheap if the shadow is already fetched therefore just do it
        if (!projCtx.isDoReconciliation() && !projCtx.isFullShadow()) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Skipping reconciliation of {}: no doReconciliation and no full shadow", projCtx.getHumanReadableName());
            }
            return;
        }
        SynchronizationPolicyDecision policyDecision = projCtx.getSynchronizationPolicyDecision();
        if (policyDecision != null && (policyDecision == SynchronizationPolicyDecision.DELETE || policyDecision == SynchronizationPolicyDecision.UNLINK)) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Skipping reconciliation of {}: decision={}", projCtx.getHumanReadableName(), policyDecision);
            }
            return;
        }
        if (projCtx.getObjectCurrent() == null) {
            LOGGER.warn("Can't do reconciliation. Account context doesn't contain current version of account.");
            return;
        }
        if (!projCtx.isFullShadow()) {
            // We need to load the object
            GetOperationOptions rootOps = GetOperationOptions.createDoNotDiscovery();
            rootOps.setPointInTimeType(PointInTimeType.FUTURE);
            PrismObject<ShadowType> objectOld = provisioningService.getObject(ShadowType.class, projCtx.getOid(), SelectorOptions.createCollection(rootOps), task, result);
            ShadowType oldShadow = objectOld.asObjectable();
            projCtx.determineFullShadowFlag(oldShadow.getFetchResult());
            projCtx.setLoadedObject(objectOld);
            projCtx.recompute();
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Starting reconciliation of {}", projCtx.getHumanReadableName());
        }
        reconcileAuxiliaryObjectClasses(projCtx);
        RefinedObjectClassDefinition rOcDef = projCtx.getCompositeObjectClassDefinition();
        Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismPropertyValue<?>, PrismPropertyDefinition<?>>>> squeezedAttributes = projCtx.getSqueezedAttributes();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Attribute reconciliation processing {}", projCtx.getHumanReadableName());
        }
        reconcileProjectionAttributes(projCtx, squeezedAttributes, rOcDef);
        Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>>> squeezedAssociations = projCtx.getSqueezedAssociations();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Association reconciliation processing {}", projCtx.getHumanReadableName());
        }
        reconcileProjectionAssociations(projCtx, squeezedAssociations, rOcDef, task, result);
        reconcileMissingAuxiliaryObjectClassAttributes(projCtx);
    } catch (RuntimeException | SchemaException e) {
        subResult.recordFatalError(e);
        throw e;
    } finally {
        subResult.computeStatus();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions)

Example 68 with ObjectType

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

the class DependencyProcessor method preprocessDependencies.

public <F extends ObjectType> void preprocessDependencies(LensContext<F> context) {
    //in the first wave we do not have enough information to preprocess contexts
    if (context.getExecutionWave() == 0) {
        return;
    }
    for (LensProjectionContext projContext : context.getProjectionContexts()) {
        if (!projContext.isCanProject()) {
            continue;
        }
        for (ResourceObjectTypeDependencyType dependency : projContext.getDependencies()) {
            ResourceShadowDiscriminator refRat = new ResourceShadowDiscriminator(dependency, projContext.getResource().getOid(), projContext.getKind());
            LOGGER.trace("LOOKING FOR {}", refRat);
            LensProjectionContext dependencyAccountContext = context.findProjectionContext(refRat);
            ResourceObjectTypeDependencyStrictnessType strictness = ResourceTypeUtil.getDependencyStrictness(dependency);
            if (dependencyAccountContext != null) {
                if (!dependencyAccountContext.isCanProject()) {
                    continue;
                }
                // We have the context of the object that we depend on. We need to check if it was provisioned.
                if (strictness == ResourceObjectTypeDependencyStrictnessType.STRICT || strictness == ResourceObjectTypeDependencyStrictnessType.RELAXED) {
                    if (wasExecuted(dependencyAccountContext)) {
                        // everything OK
                        if (ResourceTypeUtil.isForceLoadDependentShadow(dependency) && !dependencyAccountContext.isDelete()) {
                            dependencyAccountContext.setDoReconciliation(true);
                            projContext.setDoReconciliation(true);
                        }
                    }
                }
            }
        }
    }
}
Also used : ResourceObjectTypeDependencyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyType) ResourceObjectTypeDependencyStrictnessType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyStrictnessType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 69 with ObjectType

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

the class DependencyProcessor method determineProjectionWaveProvision.

private <F extends ObjectType> LensProjectionContext determineProjectionWaveProvision(LensContext<F> context, LensProjectionContext projectionContext, ResourceObjectTypeDependencyType inDependency, List<ResourceObjectTypeDependencyType> depPath) throws PolicyViolationException {
    if (depPath == null) {
        depPath = new ArrayList<ResourceObjectTypeDependencyType>();
    }
    int determinedWave = 0;
    int determinedOrder = 0;
    for (ResourceObjectTypeDependencyType outDependency : projectionContext.getDependencies()) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("DEP: {}", outDependency);
        }
        if (inDependency != null && isHigerOrder(outDependency, inDependency)) {
            // otherwise we can end up in endless loop even for legal dependencies.
            continue;
        }
        checkForCircular(depPath, outDependency);
        depPath.add(outDependency);
        ResourceShadowDiscriminator refDiscr = new ResourceShadowDiscriminator(outDependency, projectionContext.getResource().getOid(), projectionContext.getKind());
        LensProjectionContext dependencyProjectionContext = findDependencyTargetContext(context, projectionContext, outDependency);
        //			}
        if (dependencyProjectionContext == null || dependencyProjectionContext.isDelete()) {
            ResourceObjectTypeDependencyStrictnessType outDependencyStrictness = ResourceTypeUtil.getDependencyStrictness(outDependency);
            if (outDependencyStrictness == ResourceObjectTypeDependencyStrictnessType.STRICT) {
                throw new PolicyViolationException("Unsatisfied strict dependency of account " + projectionContext.getResourceShadowDiscriminator() + " dependent on " + refDiscr + ": Account not provisioned");
            } else if (outDependencyStrictness == ResourceObjectTypeDependencyStrictnessType.LAX) {
                // independent object not in the context, just ignore it
                LOGGER.debug("Unsatisfied lax dependency of account " + projectionContext.getResourceShadowDiscriminator() + " dependent on " + refDiscr + "; dependency skipped");
            } else if (outDependencyStrictness == ResourceObjectTypeDependencyStrictnessType.RELAXED) {
                // independent object not in the context, just ignore it
                LOGGER.debug("Unsatisfied relaxed dependency of account " + projectionContext.getResourceShadowDiscriminator() + " dependent on " + refDiscr + "; dependency skipped");
            } else {
                throw new IllegalArgumentException("Unknown dependency strictness " + outDependency.getStrictness() + " in " + refDiscr);
            }
        } else {
            dependencyProjectionContext = determineProjectionWave(context, dependencyProjectionContext, outDependency, depPath);
            if (dependencyProjectionContext.getWave() + 1 > determinedWave) {
                determinedWave = dependencyProjectionContext.getWave() + 1;
                if (outDependency.getOrder() == null) {
                    determinedOrder = 0;
                } else {
                    determinedOrder = outDependency.getOrder();
                }
            }
        }
        depPath.remove(outDependency);
    }
    LensProjectionContext resultAccountContext = projectionContext;
    if (projectionContext.getWave() >= 0 && projectionContext.getWave() != determinedWave) {
        // Wave for this context was set during the run of this method (it was not set when we
        // started, we checked at the beginning). Therefore this context must have been visited again.
        // therefore there is a circular dependency. Therefore we need to create another context to split it.
        ResourceShadowDiscriminator origDiscr = projectionContext.getResourceShadowDiscriminator();
        ResourceShadowDiscriminator discr = new ResourceShadowDiscriminator(origDiscr.getResourceOid(), origDiscr.getKind(), origDiscr.getIntent(), origDiscr.isThombstone());
        discr.setOrder(determinedOrder);
        if (!projectionContext.compareResourceShadowDiscriminator(discr, true)) {
            resultAccountContext = createAnotherContext(context, projectionContext, discr);
        }
    }
    //		LOGGER.trace("Wave for {}: {}", resultAccountContext.getResourceAccountType(), wave);
    resultAccountContext.setWave(determinedWave);
    return resultAccountContext;
}
Also used : ResourceObjectTypeDependencyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyType) ResourceObjectTypeDependencyStrictnessType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyStrictnessType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException)

Example 70 with ObjectType

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

the class DependencyProcessor method checkDependencies.

/**
	 * Check that the dependencies are still satisfied. Also check for high-ordes vs low-order operation consistency
	 * and stuff like that. 
	 */
public <F extends ObjectType> boolean checkDependencies(LensContext<F> context, LensProjectionContext projContext, OperationResult result) throws PolicyViolationException {
    if (projContext.isDelete()) {
        // It is OK if we depend on something that is not there if we are being removed ... for now
        return true;
    }
    if (projContext.getOid() == null || projContext.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.ADD) {
        // Check for lower-order contexts
        LensProjectionContext lowerOrderContext = null;
        for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
            if (projContext == projectionContext) {
                continue;
            }
            if (projectionContext.compareResourceShadowDiscriminator(projContext.getResourceShadowDiscriminator(), false) && projectionContext.getResourceShadowDiscriminator().getOrder() < projContext.getResourceShadowDiscriminator().getOrder()) {
                if (projectionContext.getOid() != null) {
                    lowerOrderContext = projectionContext;
                    break;
                }
            }
        }
        if (lowerOrderContext != null) {
            if (lowerOrderContext.getOid() != null) {
                if (projContext.getOid() == null) {
                    projContext.setOid(lowerOrderContext.getOid());
                }
                if (projContext.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.ADD) {
                    // This context cannot be ADD. There is a lower-order context with an OID
                    // it means that the lower-order projection exists, we cannot add it twice
                    projContext.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.KEEP);
                }
            }
            if (lowerOrderContext.isDelete()) {
                projContext.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.DELETE);
            }
        }
    }
    for (ResourceObjectTypeDependencyType dependency : projContext.getDependencies()) {
        ResourceShadowDiscriminator refRat = new ResourceShadowDiscriminator(dependency, projContext.getResource().getOid(), projContext.getKind());
        LOGGER.trace("LOOKING FOR {}", refRat);
        LensProjectionContext dependencyAccountContext = context.findProjectionContext(refRat);
        ResourceObjectTypeDependencyStrictnessType strictness = ResourceTypeUtil.getDependencyStrictness(dependency);
        if (dependencyAccountContext == null) {
            if (strictness == ResourceObjectTypeDependencyStrictnessType.STRICT) {
                // This should not happen, it is checked before projection
                throw new PolicyViolationException("Unsatisfied strict dependency of " + projContext.getResourceShadowDiscriminator().toHumanReadableDescription() + " dependent on " + refRat.toHumanReadableDescription() + ": No context in dependency check");
            } else if (strictness == ResourceObjectTypeDependencyStrictnessType.LAX) {
                // independent object not in the context, just ignore it
                LOGGER.trace("Unsatisfied lax dependency of account " + projContext.getResourceShadowDiscriminator().toHumanReadableDescription() + " dependent on " + refRat.toHumanReadableDescription() + "; dependency skipped");
            } else if (strictness == ResourceObjectTypeDependencyStrictnessType.RELAXED) {
                // independent object not in the context, just ignore it
                LOGGER.trace("Unsatisfied relaxed dependency of account " + projContext.getResourceShadowDiscriminator().toHumanReadableDescription() + " dependent on " + refRat.toHumanReadableDescription() + "; dependency skipped");
            } else {
                throw new IllegalArgumentException("Unknown dependency strictness " + dependency.getStrictness() + " in " + refRat);
            }
        } else {
            // We have the context of the object that we depend on. We need to check if it was provisioned.
            if (strictness == ResourceObjectTypeDependencyStrictnessType.STRICT || strictness == ResourceObjectTypeDependencyStrictnessType.RELAXED) {
                if (wasProvisioned(dependencyAccountContext, context.getExecutionWave())) {
                // everything OK
                } else {
                    // We do not want to throw exception here. That will stop entire projection.
                    // Let's just mark the projection as broken and skip it.
                    LOGGER.warn("Unsatisfied dependency of account " + projContext.getResourceShadowDiscriminator() + " dependent on " + refRat + ": Account not provisioned in dependency check (execution wave " + context.getExecutionWave() + ", account wave " + projContext.getWave() + ", dependency account wave " + dependencyAccountContext.getWave() + ")");
                    projContext.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
                    return false;
                }
            } else if (strictness == ResourceObjectTypeDependencyStrictnessType.LAX) {
                // TODO why return here? shouldn't we check other dependencies as well? [med]
                return true;
            } else {
                throw new IllegalArgumentException("Unknown dependency strictness " + dependency.getStrictness() + " in " + refRat);
            }
        }
    }
    return true;
}
Also used : ResourceObjectTypeDependencyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyType) ResourceObjectTypeDependencyStrictnessType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyStrictnessType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)321 Test (org.testng.annotations.Test)267 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)252 Task (com.evolveum.midpoint.task.api.Task)251 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)230 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)170 ArrayList (java.util.ArrayList)136 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)65 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)61 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)53 Holder (javax.xml.ws.Holder)51 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)50 QName (javax.xml.namespace.QName)46 PrismObject (com.evolveum.midpoint.prism.PrismObject)42 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)36 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)36 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)34