use of com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectPolicyRuleEvaluationContext in project midpoint by Evolveum.
the class EvaluatedPolicyRuleImpl method createVariablesMap.
private <AH extends AssignmentHolderType> VariablesMap createVariablesMap(PolicyRuleEvaluationContext<AH> rctx, PrismObject<AH> object) {
VariablesMap var = new VariablesMap();
var.put(ExpressionConstants.VAR_USER, object, object.getDefinition());
var.put(ExpressionConstants.VAR_FOCUS, object, object.getDefinition());
var.put(ExpressionConstants.VAR_OBJECT, object, object.getDefinition());
PrismContext prismContext = PrismContext.get();
if (rctx instanceof AssignmentPolicyRuleEvaluationContext) {
AssignmentPolicyRuleEvaluationContext<AH> actx = (AssignmentPolicyRuleEvaluationContext<AH>) rctx;
var.put(ExpressionConstants.VAR_TARGET, actx.evaluatedAssignment.getTarget(), actx.evaluatedAssignment.getTarget().getDefinition());
var.put(ExpressionConstants.VAR_EVALUATED_ASSIGNMENT, actx.evaluatedAssignment, EvaluatedAssignment.class);
AssignmentType assignment = actx.evaluatedAssignment.getAssignment(actx.state == ObjectState.BEFORE);
var.put(ExpressionConstants.VAR_ASSIGNMENT, assignment, getAssignmentDefinition(assignment, prismContext));
} else if (rctx instanceof ObjectPolicyRuleEvaluationContext) {
PrismObjectDefinition<ObjectType> targetDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ObjectType.class);
var.put(ExpressionConstants.VAR_TARGET, null, targetDef);
var.put(ExpressionConstants.VAR_EVALUATED_ASSIGNMENT, null, EvaluatedAssignment.class);
var.put(ExpressionConstants.VAR_ASSIGNMENT, null, getAssignmentDefinition(null, prismContext));
} else if (rctx != null) {
throw new AssertionError(rctx);
}
var.put(VAR_RULE_EVALUATION_CONTEXT, rctx, PolicyRuleEvaluationContext.class);
return var;
}
use of com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectPolicyRuleEvaluationContext in project midpoint by Evolveum.
the class ObjectModificationConstraintEvaluator method evaluate.
@Override
public <AH extends AssignmentHolderType> EvaluatedModificationTrigger evaluate(@NotNull JAXBElement<ModificationPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
try {
if (!(rctx instanceof ObjectPolicyRuleEvaluationContext)) {
LOGGER.trace("Policy rule evaluation context is not of type ObjectPolicyRuleEvaluationContext. Skipping processing.");
return null;
}
ObjectPolicyRuleEvaluationContext<AH> ctx = (ObjectPolicyRuleEvaluationContext<AH>) rctx;
if (modificationConstraintMatches(constraint, ctx, result)) {
LocalizableMessage message = createMessage(constraint, rctx, result);
LocalizableMessage shortMessage = createShortMessage(constraint, rctx, result);
return new EvaluatedModificationTrigger(PolicyConstraintKindType.OBJECT_MODIFICATION, constraint.getValue(), null, message, shortMessage);
} else {
LOGGER.trace("No operation matches.");
return null;
}
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
Aggregations