Search in sources :

Example 86 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class SecurityViolationHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof SecurityViolationException) {
            throw (SecurityViolationException) ex;
        } else {
            throw new SecurityViolationException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
    }
    if (op != FailedOperation.GET) {
        //		Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
    //this should not happen. But if it happens, we should return original exception
    }
    throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Example 87 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class AbstractSearchExpressionEvaluator method createOnDemand.

private <O extends ObjectType> String createOnDemand(Class<O> targetTypeClass, ExpressionVariables variables, ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Going to create assignment targets on demand, variables:\n{}", variables.formatVariables());
    }
    PrismObjectDefinition<O> objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(targetTypeClass);
    PrismObject<O> newObject = objectDefinition.instantiate();
    PopulateType populateObject = getExpressionEvaluatorType().getPopulateObject();
    if (populateObject == null) {
        LOGGER.warn("No populateObject in assignment expression in {}, " + "object created on demand will be empty. Subsequent operations will most likely fail", contextDescription);
    } else {
        for (PopulateItemType populateItem : populateObject.getPopulateItem()) {
            ItemDelta<?, ?> itemDelta = evaluatePopulateExpression(populateItem, variables, params, objectDefinition, contextDescription, true, task, result);
            if (itemDelta != null) {
                itemDelta.applyTo(newObject);
            }
        }
    }
    LOGGER.debug("Creating object on demand from {}: {}", contextDescription, newObject);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Creating object on demand:\n{}", newObject.debugDump());
    }
    ObjectDelta<O> addDelta = newObject.createAddDelta();
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(addDelta);
    try {
        modelService.executeChanges(deltas, null, task, result);
    } catch (ObjectAlreadyExistsException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        throw new ExpressionEvaluationException(e.getMessage(), e);
    }
    return addDelta.getOid();
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PopulateItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PopulateType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)

Example 88 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class ImportAccountsFromResourceTaskHandler method launch.

/**
     * Launch an import. Calling this method will start import in a new
     * thread, possibly on a different node.
     */
public void launch(ResourceType resource, QName objectclass, Task task, OperationResult parentResult) {
    LOGGER.info("Launching import from resource {} as asynchronous task", ObjectTypeUtil.toShortString(resource));
    OperationResult result = parentResult.createSubresult(ImportAccountsFromResourceTaskHandler.class.getName() + ".launch");
    result.addParam("resource", resource);
    result.addParam("objectclass", objectclass);
    // TODO
    // Set handler URI so we will be called back
    task.setHandlerUri(HANDLER_URI);
    // Readable task name
    PolyStringType polyString = new PolyStringType("Import from resource " + resource.getName());
    task.setName(polyString);
    // Set reference to the resource
    task.setObjectRef(ObjectTypeUtil.createObjectRef(resource));
    try {
        PrismProperty<?> objectclassProp = objectclassPropertyDefinition.instantiate();
        objectclassProp.setRealValue(objectclass);
        task.setExtensionProperty(objectclassProp);
        // just to be sure (if the task was already persistent)
        task.savePendingModifications(result);
    //          task.modify(modifications, result);
    } catch (ObjectNotFoundException e) {
        LOGGER.error("Task object not found, expecting it to exist (task {})", task, e);
        result.recordFatalError("Task object not found", e);
        throw new IllegalStateException("Task object not found, expecting it to exist", e);
    } catch (ObjectAlreadyExistsException e) {
        LOGGER.error("Task object wasn't updated (task {})", task, e);
        result.recordFatalError("Task object wasn't updated", e);
        throw new IllegalStateException("Task object wasn't updated", e);
    } catch (SchemaException e) {
        LOGGER.error("Error dealing with schema (task {})", task, e);
        result.recordFatalError("Error dealing with schema", e);
        throw new IllegalStateException("Error dealing with schema", e);
    }
    // Switch task to background. This will start new thread and call
    // the run(task) method.
    // Note: the thread may be actually started on a different node
    taskManager.switchToBackground(task, result);
    result.setBackgroundTaskOid(task.getOid());
    result.computeStatus("Import launch failed");
    LOGGER.trace("Import from resource {} switched to background, control thread returning with task {}", ObjectTypeUtil.toShortString(resource), task);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 89 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class ShadowConstraintsChecker method check.

public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition projOcDef = projectionContext.getCompositeObjectClassDefinition();
    PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
    if (projectionNew == null) {
        // This must be delete
        LOGGER.trace("No new object in projection context. Current shadow satisfy constraints");
        satisfiesConstraints = true;
        return;
    }
    PrismContainer<?> attributesContainer = projectionNew.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // No attributes no constraint violations
        LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
        satisfiesConstraints = true;
        return;
    }
    ConstraintViolationConfirmer confirmer = new ConstraintViolationConfirmer() {

        @Override
        public boolean confirmViolation(String oid) {
            boolean violation = true;
            LensProjectionContext foundContext = context.findProjectionContextByOid(oid);
            if (foundContext != null) {
                if (foundContext.getResourceShadowDiscriminator() != null) {
                    if (foundContext.getResourceShadowDiscriminator().isThombstone()) {
                        violation = false;
                    }
                    LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
                }
            }
            return violation;
        }
    };
    constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, task, result);
    if (constraintsCheckingResult.isSatisfiesConstraints()) {
        satisfiesConstraints = true;
        return;
    }
    for (QName checkedAttributeName : constraintsCheckingResult.getCheckedAttributes()) {
        if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) {
            if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) {
                throw new ObjectAlreadyExistsException("Attribute " + checkedAttributeName + " conflicts with existing object (and it is present in primary " + "account delta therefore no iteration is performed)");
            }
        }
    }
    if (projectionContext.getResourceShadowDiscriminator() != null && projectionContext.getResourceShadowDiscriminator().isThombstone()) {
        satisfiesConstraints = true;
    } else {
        satisfiesConstraints = false;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 90 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class MidpointUtil method createTriggersForTimedActions.

public static void createTriggersForTimedActions(String workItemId, int escalationLevel, Date workItemCreateTime, Date workItemDeadline, Task wfTask, List<WorkItemTimedActionsType> timedActionsList, OperationResult result) {
    LOGGER.trace("Creating triggers for timed actions for work item {}, escalation level {}, create time {}, deadline {}, {} timed action(s)", workItemId, escalationLevel, workItemCreateTime, workItemDeadline, timedActionsList.size());
    try {
        PrismContext prismContext = getPrismContext();
        List<TriggerType> triggers = WfContextUtil.createTriggers(escalationLevel, workItemCreateTime, workItemDeadline, timedActionsList, prismContext, LOGGER, workItemId, WfTimedActionTriggerHandler.HANDLER_URI);
        LOGGER.trace("Adding {} triggers to {}:\n{}", triggers.size(), wfTask, PrismUtil.serializeQuietlyLazily(prismContext, triggers));
        if (!triggers.isEmpty()) {
            List<ItemDelta<?, ?>> itemDeltas = DeltaBuilder.deltaFor(TaskType.class, prismContext).item(TaskType.F_TRIGGER).add(PrismContainerValue.toPcvList(triggers)).asItemDeltas();
            getCacheRepositoryService().modifyObject(TaskType.class, wfTask.getOid(), itemDeltas, result);
        }
    } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
        throw new SystemException("Couldn't add trigger(s) to " + wfTask + ": " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)93 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)57 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)50 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)45 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)35 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)33 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)32 SystemException (com.evolveum.midpoint.util.exception.SystemException)31 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)25 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)18 Task (com.evolveum.midpoint.task.api.Task)17 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)14 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)14 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)12 ArrayList (java.util.ArrayList)11 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)9