Search in sources :

Example 1 with ConstraintsCheckingResult

use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.

the class ConstraintsChecker method check.

public ConstraintsCheckingResult check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    constraintsCheckingResult = new ConstraintsCheckingResult();
    constraintsCheckingResult.setSatisfiesConstraints(true);
    PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // No attributes no constraint violations
        LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
        return constraintsCheckingResult;
    }
    Collection<? extends ResourceAttributeDefinition> uniqueAttributeDefs = MiscUtil.unionExtends(shadowDefinition.getPrimaryIdentifiers(), shadowDefinition.getSecondaryIdentifiers());
    LOGGER.trace("Secondary IDs {}", shadowDefinition.getSecondaryIdentifiers());
    for (ResourceAttributeDefinition attrDef : uniqueAttributeDefs) {
        PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getName());
        LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef);
        if (attr == null) {
            continue;
        }
        constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName());
        boolean unique = checkAttributeUniqueness(attr, shadowDefinition, resourceType, shadowOid, task, result);
        if (!unique) {
            LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, resourceShadowDiscriminator);
            constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName());
            constraintsCheckingResult.setSatisfiesConstraints(false);
        }
    }
    constraintsCheckingResult.setMessages(messageBuilder.toString());
    return constraintsCheckingResult;
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult)

Example 2 with ConstraintsCheckingResult

use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.

the class ConstraintsChecker method check.

public ConstraintsCheckingResult check(OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    OperationResult result = parentResult.subresult(ConstraintsChecker.class.getName() + ".check").setMinor().build();
    try {
        constraintsCheckingResult = new ConstraintsCheckingResult();
        constraintsCheckingResult.setSatisfiesConstraints(true);
        PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES);
        if (attributesContainer == null) {
            // No attributes no constraint violations
            LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
            return constraintsCheckingResult;
        }
        Collection<? extends ResourceAttributeDefinition<?>> uniqueAttributeDefs = getUniqueAttributesDefinitions();
        LOGGER.trace("Checking uniqueness of attributes: {}", uniqueAttributeDefs);
        for (ResourceAttributeDefinition<?> attrDef : uniqueAttributeDefs) {
            PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getItemName());
            LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef);
            if (attr == null) {
                continue;
            }
            constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName());
            boolean unique = checkAttributeUniqueness(attr, result);
            if (!unique) {
                LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, provisioningContext);
                constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName());
                constraintsCheckingResult.setSatisfiesConstraints(false);
            }
        }
        constraintsCheckingResult.setMessages(messageBuilder.toString());
        return constraintsCheckingResult;
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult)

Example 3 with ConstraintsCheckingResult

use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.

the class ProvisioningServiceImpl method checkConstraints.

@Override
public ConstraintsCheckingResult checkConstraints(RefinedObjectClassDefinition shadowDefinition, PrismObject<ShadowType> shadowObject, ResourceType resourceType, String shadowOid, ResourceShadowDiscriminator resourceShadowDiscriminator, ConstraintViolationConfirmer constraintViolationConfirmer, Task task, OperationResult parentResult) throws CommunicationException, ObjectAlreadyExistsException, SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException {
    OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".checkConstraints");
    ConstraintsChecker checker = new ConstraintsChecker();
    checker.setCacheRepositoryService(cacheRepositoryService);
    checker.setProvisioningService(this);
    checker.setPrismContext(prismContext);
    checker.setShadowDefinition(shadowDefinition);
    checker.setShadowObject(shadowObject);
    checker.setResourceType(resourceType);
    checker.setShadowOid(shadowOid);
    checker.setResourceShadowDiscriminator(resourceShadowDiscriminator);
    checker.setConstraintViolationConfirmer(constraintViolationConfirmer);
    try {
        ConstraintsCheckingResult retval = checker.check(task, result);
        result.computeStatus();
        return retval;
    } catch (CommunicationException | ObjectAlreadyExistsException | SchemaException | SecurityViolationException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
        result.recordFatalError(e.getMessage(), e);
        throw e;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 4 with ConstraintsCheckingResult

use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult in project midpoint by Evolveum.

the class AddHelper method checkConstraints.

private void checkConstraints(PrismObject<ShadowType> resourceObjectToAdd, ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState, ProvisioningContext ctx, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ObjectAlreadyExistsException, SecurityViolationException {
    ShadowCheckType shadowConstraintsCheck = ResourceTypeUtil.getShadowConstraintsCheck(ctx.getResource());
    if (shadowConstraintsCheck == ShadowCheckType.NONE) {
        return;
    }
    String shadowOid;
    if (opState.getRepoShadow() != null) {
        shadowOid = opState.getRepoShadow().getOid();
    } else {
        shadowOid = resourceObjectToAdd.getOid();
    }
    ConstraintsChecker checker = new ConstraintsChecker();
    checker.setCacheConfigurationManager(cacheConfigurationManager);
    // TODO ok?
    checker.setShadowsFacade(shadowsFacade);
    checker.setProvisioningContext(ctx);
    checker.setShadowObject(resourceObjectToAdd);
    checker.setShadowOid(shadowOid);
    checker.setConstraintViolationConfirmer(ShadowUtil::isNotDead);
    checker.setUseCache(false);
    ConstraintsCheckingResult checkingResult = checker.check(result);
    LOGGER.trace("Checked {} constraints, result={}", resourceObjectToAdd.debugDumpLazily(), checkingResult.isSatisfiesConstraints());
    if (!checkingResult.isSatisfiesConstraints()) {
        throw new ObjectAlreadyExistsException("Conflicting shadow already exists on " + ctx.getResource());
    }
}
Also used : ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil)

Example 5 with ConstraintsCheckingResult

use of com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult 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 {
    CompositeObjectDefinition projOcDef = projectionContext.getCompositeObjectDefinition();
    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 = (conflictingShadowCandidate) -> {
        boolean violation = true;
        LensProjectionContext foundContext = context.findProjectionContextByOid(conflictingShadowCandidate.getOid());
        if (foundContext != null) {
            if (foundContext.isGone()) {
                violation = false;
            }
            LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
        }
        return violation;
    };
    constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getObjectOld(), projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, context.getProjectionConstraintsCheckingStrategy(), 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.isGone()) {
        satisfiesConstraints = true;
    } else {
        satisfiesConstraints = false;
    }
}
Also used : PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CompositeObjectDefinition(com.evolveum.midpoint.schema.processor.CompositeObjectDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) 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) CompositeObjectDefinition(com.evolveum.midpoint.schema.processor.CompositeObjectDefinition) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ConstraintsCheckingResult (com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ConstraintViolationConfirmer (com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer)1 ProvisioningService (com.evolveum.midpoint.provisioning.api.ProvisioningService)1 CompositeObjectDefinition (com.evolveum.midpoint.schema.processor.CompositeObjectDefinition)1 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)1 ShadowUtil (com.evolveum.midpoint.schema.util.ShadowUtil)1