use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method determineDeputyValidity.
private boolean determineDeputyValidity(PrismObject<UserType> potentialDeputy, List<ObjectReferenceType> assignees, @Nullable AbstractWorkItemType workItem, QName privilegeLimitationItemName, Task task, OperationResult result) {
AssignmentEvaluator.Builder<UserType> builder = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(potentialDeputy, null, potentialDeputy, potentialDeputy.getDefinition())).channel(null).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).loginMode(true).lensContext(new LensContextPlaceholder<>(potentialDeputy));
AssignmentEvaluator<UserType> assignmentEvaluator = builder.build();
for (AssignmentType assignmentType : potentialDeputy.asObjectable().getAssignment()) {
if (!DeputyUtils.isDelegationAssignment(assignmentType, relationRegistry)) {
continue;
}
try {
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType));
// TODO some special mode for verification of the validity - we don't need complete calculation here!
EvaluatedAssignment<UserType> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, potentialDeputy.asObjectable(), potentialDeputy.toString(), AssignmentOrigin.createInObject(), task, result);
if (!assignment.isValid()) {
continue;
}
for (EvaluatedAssignmentTarget target : assignment.getRoles().getNonNegativeValues()) {
// MID-6403
if (target.getTarget().getOid() != null && DeputyUtils.isDelegationPath(target.getAssignmentPath(), relationRegistry) && ObjectTypeUtil.containsOid(assignees, target.getTarget().getOid())) {
List<OtherPrivilegesLimitationType> limitations = DeputyUtils.extractLimitations(target.getAssignmentPath());
if (workItem != null && DeputyUtils.limitationsAllow(limitations, privilegeLimitationItemName, workItem) || workItem == null && SchemaDeputyUtil.limitationsAllow(limitations, privilegeLimitationItemName)) {
return true;
}
}
}
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't verify 'deputy' relation between {} and {} for work item {}; assignment: {}", e, potentialDeputy, assignees, workItem, assignmentType);
}
}
return false;
}
use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class AssignmentProcessor method evaluateFocusMappings.
private <AH extends AssignmentHolderType> void evaluateFocusMappings(LensContext<AH> context, XMLGregorianCalendar now, LensFocusContext<AH> focusContext, DeltaSetTriple<EvaluatedAssignmentImpl<AH>> evaluatedAssignmentTriple, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, PolicyViolationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, CommunicationException {
OperationResult result = parentResult.subresult(OP_EVALUATE_FOCUS_MAPPINGS).setMinor().build();
try {
LOGGER.trace("Starting evaluation of assignment-held mappings");
ObjectDeltaObject<AH> focusOdoRelative = focusContext.getObjectDeltaObjectRelative();
List<AssignedFocusMappingEvaluationRequest> allRequests = new ArrayList<>();
for (EvaluatedAssignmentImpl<AH> evaluatedAssignment : evaluatedAssignmentTriple.getAllValues()) {
allRequests.addAll(evaluatedAssignment.getFocusMappingEvaluationRequests());
}
FocalMappingSetEvaluation.TripleCustomizer<?, ?> customizer = (triple, abstractRequest) -> {
if (triple == null) {
return null;
}
DeltaSetTriple<ItemValueWithOrigin<PrismValue, ItemDefinition<?>>> rv = prismContext.deltaFactory().createDeltaSetTriple();
AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
// noinspection unchecked
EvaluatedAssignmentImpl<AH> evaluatedAssignment = (EvaluatedAssignmentImpl<AH>) request.getEvaluatedAssignment();
PlusMinusZero relativeMode = request.getRelativeMode();
Set<PlusMinusZero> presence = new HashSet<>();
PlusMinusZero resultingMode = null;
if (evaluatedAssignmentTriple.presentInPlusSet(evaluatedAssignment)) {
resultingMode = PlusMinusZero.compute(PlusMinusZero.PLUS, relativeMode);
presence.add(PlusMinusZero.PLUS);
}
if (evaluatedAssignmentTriple.presentInMinusSet(evaluatedAssignment)) {
resultingMode = PlusMinusZero.compute(PlusMinusZero.MINUS, relativeMode);
presence.add(PlusMinusZero.MINUS);
}
if (evaluatedAssignmentTriple.presentInZeroSet(evaluatedAssignment)) {
resultingMode = PlusMinusZero.compute(PlusMinusZero.ZERO, relativeMode);
presence.add(PlusMinusZero.ZERO);
}
LOGGER.trace("triple customizer: presence = {}, relativeMode = {}, resultingMode = {}", presence, relativeMode, resultingMode);
if (presence.isEmpty()) {
throw new IllegalStateException("Evaluated assignment is not present in any of plus/minus/zero sets " + "of the triple. Assignment = " + evaluatedAssignment + ", triple = " + triple);
} else if (presence.size() > 1) {
// TODO think about this
throw new IllegalStateException("Evaluated assignment is present in more than one plus/minus/zero sets " + "of the triple: " + presence + ". Assignment = " + evaluatedAssignment + ", triple = " + triple);
}
if (resultingMode != null) {
switch(resultingMode) {
case PLUS:
// MID-6403
rv.addAllToPlusSet(triple.getNonNegativeValues());
break;
case MINUS:
// MID-6403
rv.addAllToMinusSet(triple.getNonPositiveValues());
break;
case ZERO:
rv = triple;
break;
}
}
return rv;
};
FocalMappingSetEvaluation.EvaluatedMappingConsumer mappingConsumer = (mapping, abstractRequest) -> {
AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
request.getEvaluatedAssignment().addFocusMapping(mapping);
};
TargetObjectSpecification<AH> targetSpecification = new FixedTargetSpecification<>(focusOdoRelative.getNewObject(), true);
MappingEvaluationEnvironment env = new MappingEvaluationEnvironment("focus mappings in assignments of " + focusContext.getHumanReadableName(), now, task);
FocalMappingSetEvaluation<AH, AH> mappingSetEvaluation = new FocalMappingSetEvaluationBuilder<AH, AH>().context(context).evaluationRequests(allRequests).phase(null).focusOdo(focusOdoRelative).targetSpecification(targetSpecification).tripleCustomizer(customizer).mappingConsumer(mappingConsumer).iteration(focusContext.getIteration()).iterationToken(focusContext.getIterationToken()).beans(beans).env(env).result(result).build();
mappingSetEvaluation.evaluateMappingsToTriples();
PathKeyedMap<DeltaSetTriple<ItemValueWithOrigin<?, ?>>> focusOutputTripleMap = mappingSetEvaluation.getOutputTripleMap();
logOutputTripleMap(focusOutputTripleMap);
DeltaSetTripleMapConsolidation<AH> consolidation = new DeltaSetTripleMapConsolidation<>(focusOutputTripleMap, focusOdoRelative.getNewObject(), focusOdoRelative.getObjectDelta(), context::primaryFocusItemDeltaExists, null, null, focusContext.getObjectDefinition(), env, beans, context, result);
consolidation.computeItemDeltas();
Collection<ItemDelta<?, ?>> focusDeltas = consolidation.getItemDeltas();
LOGGER.trace("Computed focus deltas: {}", focusDeltas);
focusContext.swallowToSecondaryDelta(focusDeltas);
focusContext.recompute();
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class FocalMappingSetEvaluation method createFocusMapping.
private <V extends PrismValue, D extends ItemDefinition<?>, AH extends AssignmentHolderType, T extends AssignmentHolderType> MappingImpl<V, D> createFocusMapping(LensContext<AH> context, FocalMappingEvaluationRequest<?, ?> request, ObjectDeltaObject<AH> focusOdo, @NotNull PrismObject<T> targetContext, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
MappingType mappingBean = request.getMapping();
MappingKindType mappingKind = request.getMappingKind();
ObjectType originObject = request.getOriginObject();
Source<V, D> defaultSource = request.constructDefaultSource(focusOdo);
AssignmentPathVariables assignmentPathVariables = request.getAssignmentPathVariables();
if (!MappingImpl.isApplicableToChannel(mappingBean, context.getChannel())) {
LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingBean, context.getChannel());
return null;
}
ConfigurableValuePolicySupplier valuePolicySupplier = new ConfigurableValuePolicySupplier() {
private ItemDefinition<?> outputDefinition;
@Override
public void setOutputDefinition(ItemDefinition<?> outputDefinition) {
this.outputDefinition = outputDefinition;
}
@Override
public ValuePolicyType get(OperationResult result) {
// TODO need to switch to ObjectValuePolicyEvaluator
if (outputDefinition.getItemName().equals(PasswordType.F_VALUE)) {
return beans.credentialsProcessor.determinePasswordPolicy(context.getFocusContext());
}
if (mappingBean.getExpression() != null) {
List<JAXBElement<?>> evaluators = mappingBean.getExpression().getExpressionEvaluator();
if (evaluators != null) {
for (JAXBElement jaxbEvaluator : evaluators) {
Object object = jaxbEvaluator.getValue();
if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
try {
ValuePolicyType valuePolicyType = beans.mappingFactory.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getItemName() + " value", task, result);
if (valuePolicyType != null) {
return valuePolicyType;
}
} catch (CommonException ex) {
throw new SystemException(ex.getMessage(), ex);
}
}
}
}
}
return null;
}
};
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_FOCUS, focusOdo, focusOdo.getDefinition());
variables.put(ExpressionConstants.VAR_USER, focusOdo, focusOdo.getDefinition());
variables.registerAlias(ExpressionConstants.VAR_USER, ExpressionConstants.VAR_FOCUS);
variables.put(ExpressionConstants.VAR_ITERATION, iteration, Integer.class);
variables.put(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken, String.class);
variables.put(ExpressionConstants.VAR_CONFIGURATION, configuration, SystemConfigurationType.class);
variables.put(ExpressionConstants.VAR_OPERATION, context.getFocusContext().getOperation().getValue(), String.class);
variables.put(ExpressionConstants.VAR_SOURCE, originObject, ObjectType.class);
PrismContext prismContext = beans.prismContext;
TypedValue<PrismObject<T>> defaultTargetContext = new TypedValue<>(targetContext);
Collection<V> targetValues = ExpressionUtil.computeTargetValues(mappingBean.getTarget(), defaultTargetContext, variables, beans.mappingFactory.getObjectResolver(), contextDesc, prismContext, task, result);
MappingSpecificationType specification = new MappingSpecificationType(prismContext).mappingName(mappingBean.getName()).definitionObjectRef(ObjectTypeUtil.createObjectRef(originObject, prismContext)).assignmentId(createAssignmentId(assignmentPathVariables));
MappingBuilder<V, D> mappingBuilder = beans.mappingFactory.<V, D>createMappingBuilder(mappingBean, contextDesc).sourceContext(focusOdo).defaultSource(defaultSource).targetContext(targetContext.getDefinition()).variablesFrom(variables).variablesFrom(LensUtil.getAssignmentPathVariablesMap(assignmentPathVariables, prismContext)).originalTargetValues(targetValues).mappingKind(mappingKind).originType(OriginType.USER_POLICY).originObject(originObject).valuePolicySupplier(valuePolicySupplier).rootNode(focusOdo).mappingPreExpression(// Used to populate autoassign assignments
request.getMappingPreExpression()).mappingSpecification(specification).now(now);
MappingImpl<V, D> mapping = mappingBuilder.build();
ItemPath itemPath = mapping.getOutputPath();
if (itemPath == null) {
// no output element, i.e. this is a "validation mapping"
return mapping;
}
Item<V, D> existingTargetItem = targetContext.findItem(itemPath);
if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
return null;
}
return mapping;
}
use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class VariablesMap method addVariableDefinitionsNew.
/**
* Adds map of extra variables to the expression.
* If there are variables with deltas (ObjectDeltaObject) it takes the "new" version
* of the object.
*/
public void addVariableDefinitionsNew(VariablesMap extraVariables) {
for (Entry<String, TypedValue> entry : extraVariables.entrySet()) {
TypedValue valueDef = entry.getValue();
Object value = valueDef.getValue();
if (value instanceof ObjectDeltaObject<?>) {
ObjectDeltaObject<?> odo = (ObjectDeltaObject<?>) value;
value = odo.getNewObject();
} else if (value instanceof ItemDeltaItem<?, ?>) {
ItemDeltaItem<?, ?> idi = (ItemDeltaItem<?, ?>) value;
value = idi.getItemNew();
}
put(entry.getKey(), valueDef.createTransformed(value));
}
registerAliasesFrom(extraVariables);
}
use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class VariablesMap method addVariableDefinitionsOld.
/**
* Adds map of extra variables to the expression.
* If there are variables with deltas (ObjectDeltaObject) it takes the "old" version
* of the object.
*/
public void addVariableDefinitionsOld(VariablesMap extraVariables) {
for (Entry<String, TypedValue> entry : extraVariables.entrySet()) {
TypedValue valueDef = entry.getValue();
Object value = valueDef.getValue();
if (value instanceof ObjectDeltaObject<?>) {
ObjectDeltaObject<?> odo = (ObjectDeltaObject<?>) value;
value = odo.getOldObject();
} else if (value instanceof ItemDeltaItem<?, ?>) {
ItemDeltaItem<?, ?> idi = (ItemDeltaItem<?, ?>) value;
value = idi.getItemOld();
}
put(entry.getKey(), valueDef.createTransformed(value));
}
registerAliasesFrom(extraVariables);
}
Aggregations