Skip to content

Commit

Permalink
Fixing generation of superfluous deltas when reconciling parentOrgRef…
Browse files Browse the repository at this point in the history
…s. Fixing null-orgref bug in PasswordPolicyProcessor.
  • Loading branch information
mederly committed Oct 20, 2015
1 parent 9550134 commit f18f53d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
Expand Up @@ -1339,7 +1339,6 @@ public <F extends ObjectType> void processOrgAssignments(LensContext<F> context,

LOGGER.trace("Reconciliation requested, collecting all non-negative values");

ItemDelta orgRefDelta = orgRefDef.createEmptyDelta(orgRefPath);
Set<PrismReferenceValue> valuesToReplace = new HashSet<>();

for (EvaluatedAssignmentImpl assignment : evaluatedAssignmentTriple.getNonNegativeValues()) {
Expand All @@ -1349,15 +1348,36 @@ public <F extends ObjectType> void processOrgAssignments(LensContext<F> context,
valuesToReplace.add(canonical); // if valuesToReplace would be a list, we should check for duplicates!
}
}
orgRefDelta.setValuesToReplace(valuesToReplace);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Created parentOrgRef delta:\n{}", orgRefDelta.debugDump());
}
focusContext.swallowToProjectionWaveSecondaryDelta(orgRefDelta);
PrismObject<F> objectNew = focusContext.getObjectNew();
if (parentOrgRefDiffers(objectNew, valuesToReplace)) {
ItemDelta orgRefDelta = orgRefDef.createEmptyDelta(orgRefPath);
orgRefDelta.setValuesToReplace(valuesToReplace);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Created parentOrgRef delta:\n{}", orgRefDelta.debugDump());
}
focusContext.swallowToProjectionWaveSecondaryDelta(orgRefDelta);
} else {
LOGGER.trace("Computed parentOrgRef is the same as the value in objectNew -- skipping application of the delta");
}
}
LOGGER.trace("Processing org assignments into parentOrgRef delta(s) done.");
}


private <F extends ObjectType> boolean parentOrgRefDiffers(PrismObject<F> objectNew, Set<PrismReferenceValue> valuesToReplace) {
if (objectNew == null) {
return true; // the result is probably irrelevant, as the object is going to be deleted - but it's safer not to skip parentOrgRef delta
}
PrismReference parentOrgRef = objectNew.findReference(ObjectType.F_PARENT_ORG_REF);
List<PrismReferenceValue> existingValues;
if (parentOrgRef != null) {
existingValues = parentOrgRef.getValues();
} else {
existingValues = new ArrayList<>();
}
boolean equal = MiscUtil.unorderedCollectionEquals(existingValues, valuesToReplace);
return !equal;
}

public <F extends ObjectType> void checkForAssignmentConflicts(LensContext<F> context,
OperationResult result) throws PolicyViolationException {
for(LensProjectionContext projectionContext: context.getProjectionContexts()) {
Expand Down
Expand Up @@ -196,33 +196,38 @@ private <T extends ObjectType, F extends ObjectType> ValuePolicyType determineVa
private ValuePolicyType determineValuePolicy(ObjectDelta<UserType> userDelta, Task task, OperationResult result)
throws SchemaException {
ReferenceDelta orgDelta = userDelta.findReferenceModification(UserType.F_PARENT_ORG_REF);
ValuePolicyType passwordPolicy = null;

LOGGER.trace("Determining password policy from org delta.");
if (orgDelta != null) {
PrismReferenceValue orgRefValue = orgDelta.getAnyValue();
if (orgDelta == null) {
return null;
}

try {
PrismObject<OrgType> org = resolver.resolve(orgRefValue,
"resolving parent org ref", null, null, result);
OrgType orgType = org.asObjectable();
ObjectReferenceType ref = orgType.getPasswordPolicyRef();
if (ref != null) {
LOGGER.trace("Org {} has specified password policy.", orgType);
passwordPolicy = resolver.resolve(ref, ValuePolicyType.class, null,
"resolving password policy for organization", task, result);
LOGGER.trace("Resolved password policy {}", passwordPolicy);
}
PrismReferenceValue orgRefValue = orgDelta.getAnyValue();
if (orgRefValue == null) { // delta may be of type "replace to null"
return null;
}

if (passwordPolicy == null) {
passwordPolicy = determineValuePolicy(org, task, result);
}
ValuePolicyType passwordPolicy = null;
try {
PrismObject<OrgType> org = resolver.resolve(orgRefValue,
"resolving parent org ref", null, null, result);
OrgType orgType = org.asObjectable();
ObjectReferenceType ref = orgType.getPasswordPolicyRef();
if (ref != null) {
LOGGER.trace("Org {} has specified password policy.", orgType);
passwordPolicy = resolver.resolve(ref, ValuePolicyType.class, null,
"resolving password policy for organization", task, result);
LOGGER.trace("Resolved password policy {}", passwordPolicy);
}

} catch (ObjectNotFoundException e) {
throw new IllegalStateException(e);
if (passwordPolicy == null) {
passwordPolicy = determineValuePolicy(org, task, result);
}

} catch (ObjectNotFoundException e) {
throw new IllegalStateException(e);
}

return passwordPolicy;
}

Expand Down

0 comments on commit f18f53d

Please sign in to comment.