Search in sources :

Example 56 with FocusType

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

the class PersonaProcessor method personaAdd.

public <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    PrismObject<F> focus = context.getFocusContext().getObjectNew();
    LOGGER.debug("Adding persona {} for {} using construction {}", key, focus, construction);
    PersonaConstructionType constructionType = construction.getConstructionType();
    ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
    ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in " + focus, task, result);
    QName targetType = constructionType.getTargetType();
    PrismObjectDefinition<T> objectDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(targetType);
    PrismObject<T> target = objectDef.instantiate();
    FocusTypeUtil.setSubtype(target, constructionType.getTargetSubtype());
    // pretend ADD focusOdo. We need to push all the items through the object template
    ObjectDeltaObject<F> focusOdo = new ObjectDeltaObject<>(null, focus.createAddDelta(), focus);
    ObjectDelta<T> targetDelta = target.createAddDelta();
    String contextDesc = "object mapping " + objectMappingType + " for persona construction for " + focus;
    XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
    Collection<ItemDelta<?, ?>> itemDeltas = objectTemplateProcessor.processObjectMapping(context, objectMappingType, focusOdo, target, targetDelta, contextDesc, now, task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDump(itemDeltas));
    }
    for (ItemDelta itemDelta : itemDeltas) {
        itemDelta.applyTo(target);
    }
    LOGGER.trace("Creating persona:\n{}", target.debugDumpLazily());
    executePersonaDelta(targetDelta, task, result);
    link(context, target.asObjectable(), result);
}
Also used : QName(javax.xml.namespace.QName) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType)

Example 57 with FocusType

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

the class PersonaProcessor method personaModify.

public <F extends FocusType, T extends FocusType> void personaModify(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, PrismObject<T> existingPersona, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    PrismObject<F> focus = context.getFocusContext().getObjectNew();
    LOGGER.debug("Modifying persona {} for {} using construction {}", key, focus, construction);
    PersonaConstructionType constructionType = construction.getConstructionType();
    ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
    ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in " + focus, task, result);
    ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
    String contextDesc = "object mapping " + objectMappingType + " for persona construction for " + focus;
    XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
    Collection<ItemDelta<?, ?>> itemDeltas = objectTemplateProcessor.processObjectMapping(context, objectMappingType, focusOdo, existingPersona, null, contextDesc, now, task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDump(itemDeltas));
    }
    ObjectDelta<T> targetDelta = existingPersona.createModifyDelta();
    for (ItemDelta itemDelta : itemDeltas) {
        targetDelta.addModification(itemDelta);
    }
    executePersonaDelta(targetDelta, task, result);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 58 with FocusType

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

the class SynchronizationServiceImpl method executeActions.

private <F extends FocusType> void executeActions(SynchronizationReactionType reactionDef, LensContext<F> context, SynchronizationSituation<F> situation, BeforeAfterType order, ResourceType resource, boolean logDebug, Task task, OperationResult parentResult) throws ConfigurationException, SchemaException {
    for (SynchronizationActionType actionDef : reactionDef.getAction()) {
        if ((actionDef.getOrder() == null && order == BeforeAfterType.BEFORE) || (actionDef.getOrder() != null && actionDef.getOrder() == order)) {
            String handlerUri = actionDef.getHandlerUri();
            if (handlerUri == null) {
                handlerUri = actionDef.getRef();
            }
            if (handlerUri == null) {
                LOGGER.error("Action definition in resource {} doesn't contain handler URI", resource);
                throw new ConfigurationException("Action definition in resource " + resource + " doesn't contain handler URI");
            }
            Action action = actionManager.getActionInstance(handlerUri);
            if (action == null) {
                LOGGER.warn("Couldn't create action with uri '{}' in resource {}, skipping action.", new Object[] { handlerUri, resource });
                continue;
            }
            // TODO: legacy userTemplate
            Map<QName, Object> parameters = null;
            if (actionDef.getParameters() != null) {
            // TODO: process parameters
            // parameters = actionDef.getParameters().getAny();
            }
            if (logDebug) {
                LOGGER.debug("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
            } else {
                LOGGER.trace("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
            }
            action.handle(context, situation, parameters, task, parentResult);
        }
    }
}
Also used : SynchronizationActionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationActionType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 59 with FocusType

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

the class SynchronizationServiceImpl method determineSituation.

/**
	 * XXX: in situation when one account belongs to two different idm users
	 * (repository returns only first user, method
	 * {@link com.evolveum.midpoint.model.api.ModelService#findShadowOwner(String, Task, OperationResult)}
	 * (String, com.evolveum.midpoint.schema.result.OperationResult)} ). It
	 * should be changed because otherwise we can't find
	 * {@link SynchronizationSituationType#DISPUTED} situation
	 */
private <F extends FocusType> SynchronizationSituation determineSituation(Class<F> focusType, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, SystemConfigurationType configurationType, Task task, OperationResult result) {
    OperationResult subResult = result.createSubresult(CHECK_SITUATION);
    LOGGER.trace("Determining situation for resource object shadow.");
    SynchronizationSituation situation = null;
    try {
        String shadowOid = getOidFromChange(change);
        Validate.notEmpty(shadowOid, "Couldn't get resource object shadow oid from change.");
        PrismObject<F> owner = repositoryService.searchShadowOwner(shadowOid, SelectorOptions.createCollection(GetOperationOptions.createAllowNotFound()), subResult);
        if (owner != null) {
            F ownerType = owner.asObjectable();
            LOGGER.trace("Shadow OID {} does have owner: {}", shadowOid, ownerType.getName());
            SynchronizationSituationType state = null;
            switch(getModificationType(change)) {
                case ADD:
                case MODIFY:
                    // if user is found it means account/group is linked to
                    // resource
                    state = SynchronizationSituationType.LINKED;
                    break;
                case DELETE:
                    state = SynchronizationSituationType.DELETED;
            }
            situation = new SynchronizationSituation<>(ownerType, null, state);
        } else {
            LOGGER.trace("Resource object shadow doesn't have owner.");
            situation = determineSituationWithCorrelation(focusType, change, synchronizationPolicy, owner, configurationType, task, result);
        }
    } catch (Exception ex) {
        LOGGER.error("Error occurred during resource object shadow owner lookup.");
        throw new SystemException("Error occurred during resource object shadow owner lookup, reason: " + ex.getMessage(), ex);
    } finally {
        subResult.computeStatus();
    }
    return situation;
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) 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)

Example 60 with FocusType

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

the class SynchronizationServiceImpl method reactToChange.

private <F extends FocusType> SynchronizationSituationType reactToChange(Class<F> focusClass, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ResourceType resource, boolean logDebug, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult parentResult) throws ConfigurationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, CommunicationException, SecurityViolationException {
    SynchronizationSituationType newSituation = situation.getSituation();
    SynchronizationReactionType reactionDefinition = findReactionDefinition(synchronizationPolicy, situation, change.getSourceChannel(), resource);
    if (reactionDefinition == null) {
        LOGGER.trace("No reaction is defined for situation {} in {}", situation.getSituation(), resource);
        return newSituation;
    }
    // seems to be unused so commented it out [med]
    // PrismObject<? extends ObjectType> shadow = null;
    // if (change.getCurrentShadow() != null) {
    // shadow = change.getCurrentShadow();
    // } else if (change.getOldShadow() != null) {
    // shadow = change.getOldShadow();
    // }
    Boolean doReconciliation = determineReconciliation(synchronizationPolicy, reactionDefinition);
    if (doReconciliation == null) {
        // shadow.
        if (change.getObjectDelta() == null) {
            doReconciliation = true;
        }
    }
    Boolean limitPropagation = determinePropagationLimitation(synchronizationPolicy, reactionDefinition, change.getSourceChannel());
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setReconcile(doReconciliation);
    options.setLimitPropagation(limitPropagation);
    final boolean willSynchronize = isSynchronize(reactionDefinition);
    LensContext<F> lensContext = null;
    if (willSynchronize) {
        lensContext = createLensContext(focusClass, change, reactionDefinition, synchronizationPolicy, situation, options, configuration, parentResult);
    }
    if (LOGGER.isTraceEnabled() && lensContext != null) {
        LOGGER.trace("---[ SYNCHRONIZATION context before action execution ]-------------------------\n" + "{}\n------------------------------------------", lensContext.debugDump());
    }
    if (willSynchronize) {
        // there's no point in calling executeAction without context - so
        // the actions are executed only if synchronize == true
        executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.BEFORE, resource, logDebug, task, parentResult);
        Iterator<LensProjectionContext> iterator = lensContext.getProjectionContextsIterator();
        LensProjectionContext originalProjectionContext = iterator.hasNext() ? iterator.next() : null;
        try {
            clockwork.run(lensContext, task, parentResult);
        } catch (ConfigurationException | ObjectNotFoundException | SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectAlreadyExistsException | CommunicationException | SecurityViolationException e) {
            LOGGER.error("SYNCHRONIZATION: Error in synchronization on {} for situation {}: {}: {}. Change was {}", new Object[] { resource, situation.getSituation(), e.getClass().getSimpleName(), e.getMessage(), change, e });
        // what to do here? We cannot throw the error back. All that the notifyChange method
        // could do is to convert it to SystemException. But that indicates an internal error and it will
        // break whatever code called the notifyChange in the first place. We do not want that.
        // If the clockwork could not do anything with the exception then perhaps nothing can be done at all.
        // So just log the error (the error should be remembered in the result and task already)
        // and then just go on.
        }
        // note: actions "AFTER" seem to be useless here (basically they
        // modify lens context - which is relevant only if followed by
        // clockwork run)
        executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.AFTER, resource, logDebug, task, parentResult);
        if (originalProjectionContext != null) {
            newSituation = originalProjectionContext.getSynchronizationSituationResolved();
        }
    } else {
        LOGGER.trace("Skipping clockwork run on {} for situation {}, synchronize is set to false.", new Object[] { resource, situation.getSituation() });
    }
    return newSituation;
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) SynchronizationReactionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

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