Search in sources :

Example 21 with FocusType

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

the class ProjectionCredentialsProcessor method applyMetadata.

private <F extends FocusType> void applyMetadata(LensContext<F> context, final LensProjectionContext projectionContext, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<ShadowType> accountDelta = projectionContext.getDelta();
    if (projectionContext.isDelete()) {
        return;
    }
    if (accountDelta == null) {
        LOGGER.trace("Skipping application of password metadata. Shadow delta not specified.");
        return;
    }
    PropertyDelta<ProtectedStringType> passwordValueDelta = accountDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
    if (passwordValueDelta == null) {
        LOGGER.trace("Skipping application of password metadata. No password change.");
        return;
    }
    if (projectionContext.isAdd()) {
        MetadataType metadataType = operationalDataManager.createCreateMetadata(context, now, task);
        ContainerDelta<MetadataType> metadataDelta = ContainerDelta.createDelta(SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition());
        PrismContainerValue cval = metadataType.asPrismContainerValue();
        cval.setOriginTypeRecursive(OriginType.OUTBOUND);
        metadataDelta.addValuesToAdd(metadataType.asPrismContainerValue());
        projectionContext.swallowToSecondaryDelta(metadataDelta);
    } else if (projectionContext.isModify()) {
        ContainerDelta<MetadataType> metadataDelta = accountDelta.findContainerDelta(SchemaConstants.PATH_PASSWORD_METADATA);
        if (metadataDelta == null) {
            Collection<? extends ItemDelta<?, ?>> modifyMetadataDeltas = operationalDataManager.createModifyMetadataDeltas(context, SchemaConstants.PATH_PASSWORD_METADATA, projectionContext.getObjectDefinition(), now, task);
            for (ItemDelta itemDelta : modifyMetadataDeltas) {
                itemDelta.setOriginTypeRecursive(OriginType.OUTBOUND);
                projectionContext.swallowToSecondaryDelta(itemDelta);
            }
        }
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 22 with FocusType

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

the class EnableDisableExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean isEnable = NAME_ENABLE.equals(expression.getType());
    boolean raw = getParamRaw(expression, input, context, globalResult);
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        result.addParam("operation", expression.getType());
        context.checkTaskStop();
        if (value instanceof PrismObjectValue) {
            PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
            ObjectType objectType = prismObject.asObjectable();
            long started = operationsHelper.recordStart(context, objectType);
            Throwable exception = null;
            try {
                if (objectType instanceof FocusType) {
                    operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
                } else if (objectType instanceof ShadowType) {
                    operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
                } else {
                    throw new ScriptExecutionException("Item is not a FocusType nor ShadowType: " + value.toString());
                }
                operationsHelper.recordEnd(context, objectType, started, null);
            } catch (Throwable ex) {
                operationsHelper.recordEnd(context, objectType, started, ex);
                exception = processActionException(ex, expression.getType(), value, context);
            }
            context.println((exception != null ? "Attempted to " + expression.getType() : (isEnable ? "Enabled " : "Disabled ")) + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject"), expression.getType(), value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return input;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 23 with FocusType

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

the class RecomputeExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && FocusType.class.isAssignableFrom(((PrismObjectValue) value).asPrismObject().getCompileTimeClass())) {
            PrismObject<FocusType> focalPrismObject = ((PrismObjectValue) value).asPrismObject();
            FocusType focusType = focalPrismObject.asObjectable();
            long started = operationsHelper.recordStart(context, focusType);
            Throwable exception = null;
            try {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Recomputing object {} with dryRun={}: context:\n{}", focalPrismObject, dryRun);
                }
                ObjectDelta<? extends FocusType> emptyDelta = ObjectDelta.createEmptyDelta(focusType.getClass(), focusType.getOid(), prismContext, ChangeType.MODIFY);
                operationsHelper.applyDelta(emptyDelta, ModelExecuteOptions.createReconcile(), dryRun, context, result);
                LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
                operationsHelper.recordEnd(context, focusType, started, null);
            } catch (Throwable e) {
                operationsHelper.recordEnd(context, focusType, started, e);
                exception = processActionException(e, NAME, value, context);
            }
            context.println((exception != null ? "Attempted to recompute " : "Recomputed ") + focalPrismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<FocusType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return input;
}
Also used : PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 24 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType 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)

Example 25 with FocusType

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

the class InactivateFocusAction method handle.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.sync.Action#handle(com.evolveum.midpoint.model.lens.LensContext, com.evolveum.midpoint.model.sync.SynchronizationSituation, java.util.Map, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public <F extends FocusType> void handle(LensContext<F> context, SynchronizationSituation<F> situation, Map<QName, Object> parameters, Task task, OperationResult parentResult) {
    ActivationStatusType desiredStatus = ActivationStatusType.DISABLED;
    LensFocusContext<F> focusContext = context.getFocusContext();
    if (focusContext != null) {
        PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
        if (objectCurrent != null) {
            PrismProperty<Object> administrativeStatusProp = objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
            if (administrativeStatusProp != null) {
                if (desiredStatus.equals(administrativeStatusProp.getRealValue())) {
                    // Desired status already set, nothing to do
                    return;
                }
            }
        }
        ObjectDelta<F> activationDelta = ObjectDelta.createModificationReplaceProperty(focusContext.getObjectTypeClass(), focusContext.getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getPrismContext(), desiredStatus);
        focusContext.setPrimaryDelta(activationDelta);
    }
}
Also used : ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7