Search in sources :

Example 1 with ExclusionPolicyConstraintType

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

the class AbstractModelIntegrationTest method createExclusionPolicyRule.

protected PolicyRuleType createExclusionPolicyRule(String excludedRoleOid) {
    PolicyRuleType policyRule = new PolicyRuleType();
    PolicyConstraintsType policyConstraints = new PolicyConstraintsType();
    ExclusionPolicyConstraintType exclusionConstraint = new ExclusionPolicyConstraintType();
    ObjectReferenceType targetRef = new ObjectReferenceType();
    targetRef.setOid(excludedRoleOid);
    targetRef.setType(RoleType.COMPLEX_TYPE);
    exclusionConstraint.setTargetRef(targetRef);
    policyConstraints.getExclusion().add(exclusionConstraint);
    policyRule.setPolicyConstraints(policyConstraints);
    return policyRule;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)

Example 2 with ExclusionPolicyConstraintType

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

the class RAbstractRole method copyFromJAXB.

public static <T extends AbstractRoleType> void copyFromJAXB(AbstractRoleType jaxb, RAbstractRole<T> repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    RFocus.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setRequestable(jaxb.isRequestable());
    repo.setDisplayName(RPolyString.copyFromJAXB(jaxb.getDisplayName()));
    repo.setIdentifier(jaxb.getIdentifier());
    repo.setRiskLevel(jaxb.getRiskLevel());
    for (AssignmentType inducement : jaxb.getInducement()) {
        RAssignment rInducement = new RAssignment(repo, RAssignmentOwner.ABSTRACT_ROLE);
        RAssignment.copyFromJAXB(inducement, rInducement, jaxb, repositoryContext, generatorResult);
        repo.getAssignments().add(rInducement);
    }
    for (ExclusionPolicyConstraintType exclusion : jaxb.getExclusion()) {
        RExclusion rExclusion = new RExclusion(repo);
        RExclusion.copyFromJAXB(exclusion, rExclusion, jaxb, repositoryContext, generatorResult);
        repo.getExclusion().add(rExclusion);
    }
    for (ObjectReferenceType approverRef : jaxb.getApproverRef()) {
        RObjectReference ref = RUtil.jaxbRefToRepo(approverRef, repositoryContext.prismContext, repo, RReferenceOwner.ROLE_APPROVER);
        if (ref != null) {
            repo.getApproverRef().add(ref);
        }
    }
    //PrismObjectDefinition<AbstractRoleType> roleDefinition = jaxb.asPrismObject().getDefinition();
    repo.setApprovalProcess(jaxb.getApprovalProcess());
    repo.setOwnerRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getOwnerRef(), repositoryContext.prismContext));
}
Also used : RAssignment(com.evolveum.midpoint.repo.sql.data.common.container.RAssignment) ExclusionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) RExclusion(com.evolveum.midpoint.repo.sql.data.common.container.RExclusion)

Example 3 with ExclusionPolicyConstraintType

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

the class RExclusion method toJAXB.

public ExclusionPolicyConstraintType toJAXB(PrismContext prismContext) throws DtoTranslationException {
    ExclusionPolicyConstraintType object = new ExclusionPolicyConstraintType();
    RExclusion.copyToJAXB(this, object, prismContext);
    return object;
}
Also used : ExclusionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType)

Example 4 with ExclusionPolicyConstraintType

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

the class ExclusionConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedExclusionTrigger evaluate(@NotNull JAXBElement<ExclusionPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        LOGGER.trace("Evaluating exclusion constraint {} on {}", lazy(() -> PolicyRuleTypeUtil.toShortString(constraint)), rctx);
        if (!(rctx instanceof AssignmentPolicyRuleEvaluationContext)) {
            return null;
        }
        AssignmentPolicyRuleEvaluationContext<AH> ctx = (AssignmentPolicyRuleEvaluationContext<AH>) rctx;
        if (!ctx.isAdded && !ctx.isKept) {
            LOGGER.trace("Assignment not being added nor kept, skipping evaluation.");
            return null;
        }
        if (sourceOrderConstraintsDoNotMatch(constraint, ctx)) {
            // logged in the called method body
            return null;
        }
        /*
             * Now let us check the exclusions.
             *
             * Assignment A is the current evaluated assignment. It has directly or indirectly attached the exclusion policy rule.
             * We now go through all other assignments B and check the exclusions.
             */
        List<OrderConstraintsType> targetOrderConstraints = defaultIfEmpty(constraint.getValue().getTargetOrderConstraint());
        List<EvaluatedAssignmentTargetImpl> nonNegativeTargetsA = ctx.evaluatedAssignment.getNonNegativeTargets();
        ConstraintReferenceMatcher<AH> refMatcher = new ConstraintReferenceMatcher<>(ctx, constraint.getValue().getTargetRef(), expressionFactory, result, LOGGER);
        for (EvaluatedAssignmentImpl<AH> assignmentB : ctx.evaluatedAssignmentTriple.getNonNegativeValues()) {
            // MID-6403
            if (assignmentB == ctx.evaluatedAssignment) {
                // currently there is no other way of comparing the evaluated assignments
                continue;
            }
            targetB: for (EvaluatedAssignmentTargetImpl targetB : assignmentB.getNonNegativeTargets()) {
                if (!pathMatches(targetB.getAssignmentPath(), targetOrderConstraints)) {
                    LOGGER.trace("Skipping considering exclusion target {} because it does not match target path constraints." + " Path={}, constraints={}", targetB, targetB.getAssignmentPath(), targetOrderConstraints);
                    continue;
                }
                if (!refMatcher.refMatchesTarget(targetB.getTarget(), "exclusion constraint")) {
                    LOGGER.trace("Target {} OID does not match exclusion filter", targetB);
                    continue;
                }
                // To avoid false positives let us check if this target is not already covered by assignment being evaluated
                for (EvaluatedAssignmentTargetImpl targetA : nonNegativeTargetsA) {
                    if (targetIsAlreadyCovered(targetB, targetA)) {
                        continue targetB;
                    }
                }
                EvaluatedExclusionTrigger rv = createTrigger(ctx.evaluatedAssignment, assignmentB, targetB, constraint, ctx.policyRule, ctx, result);
                result.addReturn("trigger", rv.toDiagShortcut());
                return rv;
            }
        }
        return null;
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) EvaluatedAssignmentTargetImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)

Example 5 with ExclusionPolicyConstraintType

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

the class ExclusionConstraintEvaluator method createTrigger.

private <AH extends AssignmentHolderType> EvaluatedExclusionTrigger createTrigger(EvaluatedAssignmentImpl<AH> assignmentA, @NotNull EvaluatedAssignmentImpl<AH> assignmentB, EvaluatedAssignmentTargetImpl targetB, JAXBElement<ExclusionPolicyConstraintType> constraintElement, EvaluatedPolicyRule policyRule, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    AssignmentPath pathA = policyRule.getAssignmentPath();
    AssignmentPath pathB = targetB.getAssignmentPath();
    LocalizableMessage infoA = createObjectInfo(pathA, assignmentA.getTarget(), true);
    LocalizableMessage infoB = createObjectInfo(pathB, targetB.getTarget(), false);
    ObjectType objectA = getConflictingObject(pathA, assignmentA.getTarget());
    ObjectType objectB = getConflictingObject(pathB, targetB.getTarget());
    LocalizableMessage message = createMessage(infoA, infoB, constraintElement, ctx, result);
    LocalizableMessage shortMessage = createShortMessage(infoA, infoB, constraintElement, ctx, result);
    return new EvaluatedExclusionTrigger(constraintElement.getValue(), message, shortMessage, assignmentB, objectA, objectB, pathA, pathB);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath)

Aggregations

EvaluatedExclusionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)2 ExclusionPolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType)2 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)2 AssignmentPath (com.evolveum.midpoint.model.api.context.AssignmentPath)1 EvaluatedAssignmentTargetImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl)1 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)1 RAssignment (com.evolveum.midpoint.repo.sql.data.common.container.RAssignment)1 RExclusion (com.evolveum.midpoint.repo.sql.data.common.container.RExclusion)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)1 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 OrderConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType)1