Skip to content

Commit

Permalink
Support for roleMembershipRef (no repo support yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Sep 24, 2015
1 parent 27370ae commit 3b384c8
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 36 deletions.
58 changes: 58 additions & 0 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd
Expand Up @@ -1893,6 +1893,64 @@
</xsd:annotation>
</xsd:element>

<xsd:element name="roleMembershipRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
<p>
References to abstract roles (roles and orgs) that this focus currently belongs to - directly
or indirectly. This reference points to all the roles in the role hierarchy. It only points to
the roles that were evaluted as active during last recompute (conditions were true, validity
constaints not violated).
</p>
<p>
Note: the value of this reference is only updated when a focal object is recomputed.
Therefore if a role definition changes then all the affected focal objects must be recomputed
for this reference to be consistent.
</p>
<p>
This is an operational property. It is set and managed by the system. It is used
for efficient search of all current role members, e.g. for the purpose of displaying this
information in the GUI.
</p>
<p>
TODO. NOT IMPLEMENTED YET.
</p>
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:AbstractRoleType</a:objectReferenceTargetType>
<a:operational>true</a:operational>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

<xsd:element name="roleInfluenceRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
<p>
References to abstract roles (roles and orgs) that this focus may directly belong to.
This reference only points to the next role in the hierarchy. However, it is backed by
a "closure" index in the repository subsystem. Therefore it can efficiently support tree-like
queries. This reference points to the roles for whose the condition is not true.
Therefore it does not reliably show
who actually has a role. It shows potential role members - all the object that are possibly
influenced when a role definition changes.
</p>
<p>
This is an operational property. It is set and managed by the system. It is used
for efficient search of all possible role members, e.g. for the purpose of recomputing
all role members after the role definition is changed.
</p>
<p>
TODO. NOT IMPLEMENTED YET. EXPERIMENAL. UNSTABLE.
</p>
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:AbstractRoleType</a:objectReferenceTargetType>
<a:operational>true</a:operational>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down
Expand Up @@ -52,6 +52,7 @@
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectResolver;
Expand Down Expand Up @@ -423,12 +424,17 @@ private void evaluateTarget(EvaluatedAssignmentImpl<F> assignment, AssignmentPat
if (targetType instanceof AbstractRoleType) {
boolean roleConditionTrue = evaluateAbstractRole(assignment, assignmentPathSegment, evaluateOld, mode, isValid, (AbstractRoleType)targetType, source, sourceDescription,
assignmentPath, task, result);
if (roleConditionTrue && mode != PlusMinusZero.MINUS && targetType instanceof OrgType && assignmentPath.getEvaluationOrder() == 1) {
if (roleConditionTrue && mode != PlusMinusZero.MINUS && assignmentPath.getEvaluationOrder() == 1) {
PrismReferenceValue refVal = new PrismReferenceValue();
refVal.setObject(targetType.asPrismObject());
refVal.setTargetType(ObjectTypes.getObjectType(targetType.getClass()).getTypeQName());
refVal.setRelation(relation);
assignment.addOrgRefVal(refVal);
}
refVal.setTargetName(targetType.getName().toPolyString());
assignment.addMembershipRefVal(refVal);
if (targetType instanceof OrgType) {
assignment.addOrgRefVal(refVal);
}
}
} else {
throw new SchemaException("Unknown assignment target type "+ObjectTypeUtil.toShortString(targetType)+" in "+sourceDescription);
}
Expand Down
Expand Up @@ -60,6 +60,7 @@ public class EvaluatedAssignmentImpl<F extends FocusType> implements EvaluatedAs
private DeltaSetTriple<Construction<F>> constructions;
private DeltaSetTriple<EvaluatedAbstractRoleImpl> roles;
private Collection<PrismReferenceValue> orgRefVals;
private Collection<PrismReferenceValue> membershipRefVals;
private Collection<Authorization> authorizations;
private Collection<Mapping<? extends PrismPropertyValue<?>,? extends PrismPropertyDefinition<?>>> focusMappings;
private PrismObject<?> target;
Expand All @@ -72,6 +73,7 @@ public EvaluatedAssignmentImpl() {
constructions = new DeltaSetTriple<>();
roles = new DeltaSetTriple<>();
orgRefVals = new ArrayList<>();
membershipRefVals = new ArrayList<>();
authorizations = new ArrayList<>();
focusMappings = new ArrayList<>();
}
Expand Down Expand Up @@ -154,6 +156,14 @@ public Collection<PrismReferenceValue> getOrgRefVals() {
public void addOrgRefVal(PrismReferenceValue org) {
orgRefVals.add(org);
}

public Collection<PrismReferenceValue> getMembershipRefVals() {
return membershipRefVals;
}

public void addMembershipRefVal(PrismReferenceValue org) {
membershipRefVals.add(org);
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#getAuthorizations()
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -72,6 +73,7 @@
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PlusMinusZero;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
Expand All @@ -89,6 +91,7 @@
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -1608,5 +1611,45 @@ private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> XM

return nextRecomputeTime;
}


public <F extends ObjectType> void processMembershipRef(LensContext<F> context,
OperationResult result) throws SchemaException {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext == null || !FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) {
return;
}
Collection<PrismReferenceValue> newValues = new ArrayList<>();
DeltaSetTriple<EvaluatedAssignmentImpl> evaluatedAssignmentTriple = context.getEvaluatedAssignmentTriple();
for (EvaluatedAssignmentImpl<?> evalAssignment: evaluatedAssignmentTriple.getNonNegativeValues()) {
for (PrismReferenceValue membershipRefVal: evalAssignment.getMembershipRefVals()) {
boolean found = false;
for (PrismReferenceValue exVal: newValues) {
if (exVal.getOid().equals(membershipRefVal.getOid())) {
found = true;
break;
}
}
if (!found) {
PrismReferenceValue ref = membershipRefVal.clone();
ref.setRelation(null);
newValues.add(ref);
}
}
}

PrismObject<F> focusOld = focusContext.getObjectOld();
if (focusOld != null) {
List<ObjectReferenceType> roleMembershipRefsOld = ((FocusType)focusOld.asObjectable()).getRoleMembershipRef();
if (MiscUtil.unorderedCollectionEquals(newValues, roleMembershipRefsOld)) {
return;
}
}

PrismReferenceDefinition membershipRefDef = focusContext.getObjectDefinition().findItemDefinition(FocusType.F_ROLE_MEMBERSHIP_REF,
PrismReferenceDefinition.class);
ReferenceDelta membershipRefDelta = new ReferenceDelta(FocusType.F_ROLE_MEMBERSHIP_REF, membershipRefDef,
focusContext.getObjectDefinition().getPrismContext());
membershipRefDelta.setValuesToReplace(newValues);
focusContext.swallowToSecondaryDelta(membershipRefDelta);
}
}
Expand Up @@ -224,6 +224,7 @@ private <F extends FocusType> void processFocusFocus(LensContext<F> context, Str

assignmentProcessor.processAssignmentsProjections(context, now, task, result);
assignmentProcessor.processOrgAssignments(context, result);
assignmentProcessor.processMembershipRef(context, result);
context.recompute();

assignmentProcessor.checkForAssignmentConflicts(context, result);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 3b384c8

Please sign in to comment.