Skip to content

Commit

Permalink
Fix various minor issues
Browse files Browse the repository at this point in the history
1. Adapted VAR_ENTITLEMENT handling to now-embedded values in shadowRef.
2. Adapted Grouper-related tests to removed PrismContext from various
internal methods.
3. Fixed ResourceAttributeDefinitionImpl#getTypeClass.
4. Adapt the ways to hack the schema in TestStrangeCases.

This should make model-intest tests pass.
  • Loading branch information
mederly committed Mar 27, 2024
1 parent 000fe55 commit dec5164
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class NativeShadowItemDefinitionImpl<T>
}

@SuppressWarnings("SameParameterValue") // The participant role is always SUBJECT for simulated associations (as of today)
static NativeShadowItemDefinitionImpl<?> simulatedAssociation(
static NativeShadowItemDefinitionImpl<?> forSimulatedAssociation(
@NotNull ItemName itemName, @NotNull QName typeName, @NotNull ShadowAssociationParticipantRole participantRole) {
// Simulated associations cannot be connected to raw definitions (for now), so we can create our own definition
var simulatedNativeDef = new NativeShadowItemDefinitionImpl<>(itemName, typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public QName getMatchingRuleQName() {

@Override
public @NotNull Class<T> getTypeClass() {
return XsdTypeMapper.toJavaType(getTypeName()); // FIXME
// TODO cache this somehow
return PrismContext.get().getSchemaRegistry().determineClassForType(getTypeName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ static ShadowAssociationDefinitionImpl parseLegacy(
try {
return new ShadowAssociationDefinitionImpl(
associationTypeDefinition,
NativeShadowItemDefinitionImpl.simulatedAssociation(
definitionCI.getAssociationName(), associationTypeDefinition.getClassName(), ShadowAssociationParticipantRole.SUBJECT),
NativeShadowItemDefinitionImpl.forSimulatedAssociation(
definitionCI.getAssociationName(),
associationTypeDefinition.getClassName(),
ShadowAssociationParticipantRole.SUBJECT),
definitionCI.value());
} catch (SchemaException e) {
throw SystemException.unexpected(e, "TEMPORARY");
throw new ConfigurationException(e);
}
}

Expand All @@ -120,7 +122,7 @@ static ItemDefinition<?> fromSimulated(
try {
return new ShadowAssociationDefinitionImpl(
associationTypeDefinition,
NativeShadowItemDefinitionImpl.simulatedAssociation(
NativeShadowItemDefinitionImpl.forSimulatedAssociation(
simulationDefinition.getLocalSubjectItemName(), simulationDefinition.getQName(), ShadowAssociationParticipantRole.SUBJECT),
toExistingImmutable(assocDefBean));
} catch (SchemaException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private static void copyAttributes(Map<QName, Object> attributes, PrismContainer
throws SchemaException {
for (Map.Entry<QName, Object> entry : attributes.entrySet()) {
PrismProperty<Object> attribute = PrismContext.get().itemFactory().createProperty(entry.getKey());
if (entry.getValue() instanceof Collection) {
for (Object value : (Collection) entry.getValue()) {
if (entry.getValue() instanceof Collection<?> collection) {
for (Object value : collection) {
attribute.addValue(PrismContext.get().itemFactory().createPropertyValue(value));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ private void doLoad(@NotNull Context context)
void resolveInputEntitlements(
ContainerDelta<ShadowAssociationValueType> associationAPrioriDelta,
ShadowAssociation currentAssociation) {

// FIXME rework this!

Collection<PrismContainerValue<ShadowAssociationValueType>> associationsToResolve = new ArrayList<>();
if (currentAssociation != null) {
associationsToResolve.addAll(currentAssociation.getValues());
Expand All @@ -285,21 +288,30 @@ void resolveInputEntitlements(
}

for (PrismContainerValue<ShadowAssociationValueType> associationToResolve : associationsToResolve) {
PrismReference shadowRef = associationToResolve.findReference(ShadowAssociationValueType.F_SHADOW_REF);
if (shadowRef != null) {
resolveEntitlementFromResource(shadowRef);
}
resolveEntitlementFromResource(associationToResolve);
}
}

private void resolveEntitlementFromResource(PrismReference shadowRef) {
PrismReferenceValue value = shadowRef.getValue();
if (value == null || value.getObject() != null) {
private void resolveEntitlementFromResource(PrismContainerValue<ShadowAssociationValueType> associationToResolve) {
var associationValue = associationToResolve.asContainerable();

ObjectReferenceType shadowRef = associationValue.getShadowRef();
if (shadowRef == null) {
return;
}

PrismObject<ShadowType> object;
Map<String, PrismObject<ShadowType>> entitlementMap = projectionContext.getEntitlementMap();

if (!Boolean.TRUE.equals(associationValue.isIdentifiersOnly())) {
// If there's a full object (not ID only), we can use the embedded object directly
PrismObject<Objectable> existingObject = shadowRef.getObject();
if (existingObject != null && existingObject.getOid() != null) {
entitlementMap.put(existingObject.getOid(), PrismObject.cast(existingObject, ShadowType.class));
return;
}
}

PrismObject<ShadowType> object;
String oid = shadowRef.getOid();
if (entitlementMap.containsKey(oid)) {
object = entitlementMap.get(oid);
Expand All @@ -322,7 +334,7 @@ private void resolveEntitlementFromResource(PrismReference shadowRef) {
subResult.close();
}
}
value.setObject(object);
shadowRef.asReferenceValue().setObject(object);
}

@Override
Expand All @@ -331,13 +343,14 @@ void getEntitlementVariableProducer(

LOGGER.trace("getEntitlementVariableProducer: processing value {} in {}", value, source);

// We act on the default source that should contain the association value.
// So some safety checks first.
// We act on the default source that should contain the association value. So some safety checks first.
if (!ExpressionConstants.VAR_INPUT_QNAME.matches(source.getName())) {
LOGGER.trace("Source other than 'input', exiting");
return;
}

// FIXME rework this!

LOGGER.trace("Trying to resolve the entitlement object from association value {}", value);
PrismObject<ShadowType> entitlement;
if (!(value instanceof PrismContainerValue<?> pcv)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ SynchronizationContext<FocusType> createSynchronizationContext(
// exotic channels, like "external changes"? Let us try the classification once more.
//
// Note that the sorter result is used here (if it contains the classification)
ResourceObjectClassification classification = beans.provisioningService
.classifyResourceObject(
ResourceObjectClassification classification =
beans.provisioningService.classifyResourceObject(
shadow,
processingContext.getResource(),
sorterResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.evolveum.midpoint.model.intest;

import static com.evolveum.midpoint.util.MiscUtil.stateNonNull;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;

Expand All @@ -15,10 +17,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -1325,22 +1324,21 @@ public void test502EnumerationStoreGood() throws Exception {
/**
* Guybrush has stored mark "bravery". Change schema so this value becomes illegal.
* They try to read it.
*
* MID-2260
*/
@Test // MID-2260
@Test
public void test510EnumerationGetBad() throws Exception {

given("Removed 'bravery' from allowed values for 'mark'");
// FIXME how's that possible that we can modify the shared prism schema?! We should fix that.
PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PrismPropertyDefinition<String> markDef = userDef.findPropertyDefinition(ItemPath.create(UserType.F_EXTENSION, PIRACY_MARK));
Iterator<? extends DisplayableValue<String>> iterator = markDef.getAllowedValues().iterator();
DisplayableValue<String> braveryValue = null;
while (iterator.hasNext()) {
DisplayableValue<String> disp = iterator.next();
if (disp.getValue().equals("bravery")) {
braveryValue = disp;
iterator.remove();
}
}
var originalAllowedValues = Objects.requireNonNull(markDef.getAllowedValues());
var reducedAllowedValues = new ArrayList<>(originalAllowedValues);
reducedAllowedValues.removeIf(val -> "bravery".equals(val.getValue()));
markDef.mutator().setAllowedValues(reducedAllowedValues);

given();
Task task = getTestTask();
OperationResult result = getTestOperationResult();

Expand All @@ -1355,8 +1353,7 @@ public void test510EnumerationGetBad() throws Exception {
PrismProperty<String> markProp = user.findProperty(ItemPath.create(UserType.F_EXTENSION, PIRACY_MARK));
assertEquals("Bad mark", null, markProp.getRealValue());

//noinspection unchecked
((Collection<DisplayableValue<String>>) markDef.getAllowedValues()).add(braveryValue); // because of the following test
markDef.mutator().setAllowedValues(originalAllowedValues);
}

/**
Expand Down Expand Up @@ -1385,15 +1382,15 @@ public void test520ShipReadBadTolerateRawData() throws Exception {
}

private void changeDefinition(QName piracyShip, ItemName piracyShipBroken) {
PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(UserType.class);
// FIXME again, we shouldn't be able to modify the shared schema!
PrismObjectDefinition<UserType> userDef =
prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PrismContainerDefinition<?> extensionDefinition = userDef.getExtensionDefinition();
List<? extends ItemDefinition> extensionDefs = extensionDefinition.getComplexTypeDefinition().getDefinitions();
for (ItemDefinition<?> itemDefinition : extensionDefs) {
if (itemDefinition.getItemName().equals(piracyShip)) {
((ItemDefinitionTestAccess) itemDefinition).replaceName(piracyShipBroken);
}
}
ComplexTypeDefinition extensionCtd = extensionDefinition.getComplexTypeDefinition();
ItemDefinition<?> piracyShipDef = stateNonNull(
extensionCtd.findLocalItemDefinition(piracyShip), "No %s def in %s", piracyShip, extensionCtd);
extensionCtd.mutator().delete(piracyShip);
extensionCtd.mutator().add(piracyShipDef.cloneWithNewName(piracyShipBroken));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@
itemDelta = new ItemDeltaType()
itemDelta.modificationType = eventType == 'MEMBERSHIP_ADD' ? ModificationTypeType.ADD : ModificationTypeType.DELETE
itemDelta.path = new ItemPathType(ItemPath.create(ShadowType.F_ATTRIBUTES, 'group'))
itemDelta.value.add(RawType.fromPropertyRealValue(groupName, null, prismContext))
itemDelta.value.add(RawType.fromPropertyRealValue(groupName, null))
delta = new ObjectDeltaType()
delta.changeType = ChangeTypeType.MODIFY
delta.itemDelta.add(itemDelta)
} else {
delta = null
}
return UcfChangeUtil.create(RI_ACCOUNT_OBJECT_CLASS, identifiers, delta, prismContext)
return UcfChangeUtil.create(RI_ACCOUNT_OBJECT_CLASS, identifiers, delta)
} else if (eventType == 'GROUP_ADD' || eventType == 'GROUP_DELETE') {
groupName = esbEvent['name']
groupId = esbEvent['id']
Expand All @@ -138,7 +138,7 @@
} else {
delta = null
}
return UcfChangeUtil.create(RI_GROUP_OBJECT_CLASS, identifiers, delta, prismContext)
return UcfChangeUtil.create(RI_GROUP_OBJECT_CLASS, identifiers, delta)
} else {
log.warn('Unsupported event type: {} -> {}', eventType, esbEvent)
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ An authoritative resource, used to test for MID-2100 (inbound mappings acting bo
return entitlement?.name
</code>
</script>
<queryInterpretationOfNoValue>filterNone</queryInterpretationOfNoValue>
</expression>
</q:equal>
</filter>
Expand Down

0 comments on commit dec5164

Please sign in to comment.