Search in sources :

Example 21 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestRoleEntitlement method test103GetGroupRaw.

@Test
public void test103GetGroupRaw() throws Exception {
    final String TEST_NAME = "test103GetGroupRaw";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestRoleEntitlement.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
    // WHEN
    PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, groupOid, options, task, result);
    display("Account", shadow);
    display("Account def", shadow.getDefinition());
    PrismContainer<Containerable> accountContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    display("Account attributes def", accountContainer.getDefinition());
    display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition());
    assertDummyGroupShadowRepo(shadow, groupOid, GROUP_PIRATE_DUMMY_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("getObject result", result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 22 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestRoleEntitlement method test102GetGroupNoFetch.

@Test
public void test102GetGroupNoFetch() throws Exception {
    final String TEST_NAME = "test102GetGroupNoFetch";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestRoleEntitlement.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
    // WHEN
    PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, groupOid, options, task, result);
    display("Account", shadow);
    display("Account def", shadow.getDefinition());
    PrismContainer<Containerable> accountContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    display("Account attributes def", accountContainer.getDefinition());
    display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition());
    assertDummyGroupShadowRepo(shadow, groupOid, GROUP_PIRATE_DUMMY_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("getObject result", result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 23 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class ShadowManager method updateShadow.

/**
	 * Updates repository shadow based on shadow from resource. Handles rename cases,
	 * change of auxiliary object classes, etc.
	 * @returns repository shadow as it should look like after the update
	 */
@SuppressWarnings("unchecked")
public PrismObject<ShadowType> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> currentResourceShadow, PrismObject<ShadowType> oldRepoShadow, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition ocDef = ctx.computeCompositeObjectClassDefinition(currentResourceShadow);
    ObjectDelta<ShadowType> shadowDelta = oldRepoShadow.createModifyDelta();
    PrismContainer<Containerable> currentResourceAttributesContainer = currentResourceShadow.findContainer(ShadowType.F_ATTRIBUTES);
    PrismContainer<Containerable> oldRepoAttributesContainer = oldRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    ShadowType oldRepoShadowType = oldRepoShadow.asObjectable();
    ShadowType currentResourceShadowType = currentResourceShadow.asObjectable();
    if (oldRepoShadowType.isExists() != currentResourceShadowType.isExists()) {
        // Resource object obviously exists when we have got here
        shadowDelta.addModificationReplaceProperty(ShadowType.F_EXISTS, currentResourceShadowType.isExists());
    }
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    for (Item<?, ?> currentResourceItem : currentResourceAttributesContainer.getValue().getItems()) {
        if (currentResourceItem instanceof PrismProperty<?>) {
            PrismProperty<?> currentResourceAttrProperty = (PrismProperty<?>) currentResourceItem;
            RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(currentResourceAttrProperty.getElementName());
            if (ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy)) {
                MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
                PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributesContainer.findProperty(currentResourceAttrProperty.getElementName());
                if (oldRepoAttributeProperty == null) {
                    PropertyDelta<?> attrAddDelta = currentResourceAttrProperty.createDelta();
                    for (PrismPropertyValue pval : currentResourceAttrProperty.getValues()) {
                        Object normalizedRealValue;
                        if (matchingRule == null) {
                            normalizedRealValue = pval.getValue();
                        } else {
                            normalizedRealValue = matchingRule.normalize(pval.getValue());
                        }
                        attrAddDelta.addValueToAdd(new PrismPropertyValue(normalizedRealValue));
                        LOGGER.trace("CURRENT ATTR:\n{}\nATTR DELTA:\n{}", currentResourceAttrProperty.debugDump(1), attrAddDelta.debugDump(1));
                    }
                    shadowDelta.addModification(attrAddDelta);
                } else {
                    if (attrDef.isSingleValue()) {
                        Object currentResourceRealValue = currentResourceAttrProperty.getRealValue();
                        Object currentResourceNormalizedRealValue;
                        if (matchingRule == null) {
                            currentResourceNormalizedRealValue = currentResourceRealValue;
                        } else {
                            currentResourceNormalizedRealValue = matchingRule.normalize(currentResourceRealValue);
                        }
                        if (!currentResourceNormalizedRealValue.equals(oldRepoAttributeProperty.getRealValue())) {
                            LOGGER.trace("CURRENT ATTR:\n{}\ncurrentResourceNormalizedRealValue: {}", currentResourceAttrProperty.debugDump(1), currentResourceNormalizedRealValue);
                            shadowDelta.addModificationReplaceProperty(currentResourceAttrProperty.getPath(), currentResourceNormalizedRealValue);
                        }
                    } else {
                        PrismProperty<Object> normalizedCurrentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrProperty.clone();
                        if (matchingRule != null) {
                            for (PrismPropertyValue pval : normalizedCurrentResourceAttrProperty.getValues()) {
                                Object normalizedRealValue = matchingRule.normalize(pval.getValue());
                                pval.setValue(normalizedRealValue);
                            }
                        }
                        PropertyDelta<Object> attrDiff = oldRepoAttributeProperty.diff(normalizedCurrentResourceAttrProperty);
                        LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", oldRepoAttributeProperty == null ? null : oldRepoAttributeProperty.debugDump(1), normalizedCurrentResourceAttrProperty == null ? null : normalizedCurrentResourceAttrProperty.debugDump(1), attrDiff == null ? null : attrDiff.debugDump(1));
                        if (attrDiff != null && !attrDiff.isEmpty()) {
                            attrDiff.setParentPath(new ItemPath(ShadowType.F_ATTRIBUTES));
                            shadowDelta.addModification(attrDiff);
                        }
                    }
                }
            }
        }
    }
    for (Item<?, ?> oldRepoItem : oldRepoAttributesContainer.getValue().getItems()) {
        if (oldRepoItem instanceof PrismProperty<?>) {
            PrismProperty<?> oldRepoAttrProperty = (PrismProperty<?>) oldRepoItem;
            RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
            PrismProperty<Object> currentAttribute = currentResourceAttributesContainer.findProperty(oldRepoAttrProperty.getElementName());
            if (attrDef == null || !ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy) || currentAttribute == null) {
                // No definition for this property it should not be there or no current value: remove it from the shadow
                PropertyDelta<?> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
                oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(oldRepoAttrProperty.getValues()));
                shadowDelta.addModification(oldRepoAttrPropDelta);
            }
        }
    }
    PolyString currentShadowName = ShadowUtil.determineShadowName(currentResourceShadow);
    PolyString oldRepoShadowName = oldRepoShadow.getName();
    if (!currentShadowName.equalsOriginalValue(oldRepoShadowName)) {
        PropertyDelta<?> shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, oldRepoShadow.getDefinition(), currentShadowName);
        shadowDelta.addModification(shadowNameDelta);
    }
    PropertyDelta<QName> auxOcDelta = (PropertyDelta) PrismProperty.diff(oldRepoShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS), currentResourceShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS));
    if (auxOcDelta != null) {
        shadowDelta.addModification(auxOcDelta);
    }
    if (cachingStrategy == CachingStategyType.NONE) {
        if (oldRepoShadowType.getCachingMetadata() != null) {
            shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA);
        }
    } else if (cachingStrategy == CachingStategyType.PASSIVE) {
        compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, currentResourceShadow, oldRepoShadow);
        compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_FROM, currentResourceShadow, oldRepoShadow);
        compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_TO, currentResourceShadow, oldRepoShadow);
        compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, currentResourceShadow, oldRepoShadow);
        CachingMetadataType cachingMetadata = new CachingMetadataType();
        cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
        shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA, cachingMetadata);
    } else {
        throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
    }
    if (!shadowDelta.isEmpty()) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Updating repo shadow {} with delta:\n{}", oldRepoShadow, shadowDelta.debugDump(1));
        }
        ConstraintsChecker.onShadowModifyOperation(shadowDelta.getModifications());
        try {
            repositoryService.modifyObject(ShadowType.class, oldRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
        } catch (ObjectAlreadyExistsException e) {
            // This should not happen for shadows
            throw new SystemException(e.getMessage(), e);
        }
        PrismObject<ShadowType> newRepoShadow = oldRepoShadow.clone();
        shadowDelta.applyTo(newRepoShadow);
        return newRepoShadow;
    } else {
        LOGGER.trace("No need to update repo shadow {} (empty delta)", oldRepoShadow);
        return oldRepoShadow;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) Containerable(com.evolveum.midpoint.prism.Containerable) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) QName(javax.xml.namespace.QName) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class ShadowManager method fixShadow.

/**
	 * Re-reads the shadow, re-evaluates the identifiers and stored values, updates them if necessary. Returns
	 * fixed shadow.  
	 */
public PrismObject<ShadowType> fixShadow(ProvisioningContext ctx, PrismObject<ShadowType> origRepoShadow, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
    PrismObject<ShadowType> currentRepoShadow = repositoryService.getObject(ShadowType.class, origRepoShadow.getOid(), null, parentResult);
    ProvisioningContext shadowCtx = ctx.spawn(currentRepoShadow);
    RefinedObjectClassDefinition ocDef = shadowCtx.getObjectClassDefinition();
    PrismContainer<Containerable> attributesContainer = currentRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer != null && attributesContainer.getValue() != null) {
        ObjectDelta<ShadowType> shadowDelta = currentRepoShadow.createModifyDelta();
        for (Item<?, ?> item : attributesContainer.getValue().getItems()) {
            if (item instanceof PrismProperty<?>) {
                PrismProperty<?> attrProperty = (PrismProperty<?>) item;
                RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(attrProperty.getElementName());
                if (attrDef == null) {
                    // No definition for this property, it should not be in the shadow
                    PropertyDelta<?> oldRepoAttrPropDelta = attrProperty.createDelta();
                    oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(attrProperty.getValues()));
                    shadowDelta.addModification(oldRepoAttrPropDelta);
                } else {
                    MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
                    List<PrismPropertyValue> valuesToAdd = null;
                    List<PrismPropertyValue> valuesToDelete = null;
                    for (PrismPropertyValue attrVal : attrProperty.getValues()) {
                        Object currentRealValue = attrVal.getValue();
                        Object normalizedRealValue = matchingRule.normalize(currentRealValue);
                        if (!normalizedRealValue.equals(currentRealValue)) {
                            if (attrDef.isSingleValue()) {
                                shadowDelta.addModificationReplaceProperty(attrProperty.getPath(), normalizedRealValue);
                                break;
                            } else {
                                if (valuesToAdd == null) {
                                    valuesToAdd = new ArrayList<>();
                                }
                                valuesToAdd.add(new PrismPropertyValue(normalizedRealValue));
                                if (valuesToDelete == null) {
                                    valuesToDelete = new ArrayList<>();
                                }
                                valuesToDelete.add(new PrismPropertyValue(currentRealValue));
                            }
                        }
                    }
                    PropertyDelta attrDelta = attrProperty.createDelta(attrProperty.getPath());
                    if (valuesToAdd != null) {
                        attrDelta.addValuesToAdd(valuesToAdd);
                    }
                    if (valuesToDelete != null) {
                        attrDelta.addValuesToDelete(valuesToDelete);
                    }
                    shadowDelta.addModification(attrDelta);
                }
            }
        }
        if (!shadowDelta.isEmpty()) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Fixing shadow {} with delta:\n{}", origRepoShadow, shadowDelta.debugDump());
            }
            try {
                repositoryService.modifyObject(ShadowType.class, origRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
            } catch (ObjectAlreadyExistsException e) {
                // This should not happen for shadows
                throw new SystemException(e.getMessage(), e);
            }
            shadowDelta.applyTo(currentRepoShadow);
        } else {
            LOGGER.trace("No need to fixing shadow {} (empty delta)", origRepoShadow);
        }
    } else {
        LOGGER.trace("No need to fixing shadow {} (no atttributes)", origRepoShadow);
    }
    return currentRepoShadow;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException) Containerable(com.evolveum.midpoint.prism.Containerable) PrismObject(com.evolveum.midpoint.prism.PrismObject) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 25 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method resolvePrimaryIdentifiers.

/**
	 * Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers. 
	 */
private ResourceObjectIdentification resolvePrimaryIdentifiers(ProvisioningContext ctx, ResourceObjectIdentification identification, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (identification == null) {
        return identification;
    }
    if (identification.hasPrimaryIdentifiers()) {
        return identification;
    }
    Collection<ResourceAttribute<?>> secondaryIdentifiers = (Collection<ResourceAttribute<?>>) identification.getSecondaryIdentifiers();
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        // TODO: we should attempt resource search here
        throw new ObjectNotFoundException("No repository shadow for " + secondaryIdentifiers + ", cannot resolve identifiers");
    }
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        throw new SchemaException("No attributes in " + repoShadow + ", cannot resolve identifiers " + secondaryIdentifiers);
    }
    RefinedObjectClassDefinition ocDef = ctx.getObjectClassDefinition();
    Collection primaryIdentifiers = new ArrayList<>();
    for (PrismProperty<?> property : attributesContainer.getValue().getProperties()) {
        if (ocDef.isPrimaryIdentifier(property.getElementName())) {
            RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName());
            ResourceAttribute<?> primaryIdentifier = new ResourceAttribute<>(property.getElementName(), attrDef, prismContext);
            primaryIdentifier.setRealValue(property.getRealValue());
            primaryIdentifiers.add(primaryIdentifier);
        }
    }
    LOGGER.trace("Resolved {} to primary identifiers {} (object class {})", identification, primaryIdentifiers, ocDef);
    return new ResourceObjectIdentification(identification.getObjectClassDefinition(), primaryIdentifiers, identification.getSecondaryIdentifiers());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ResourceObjectIdentification(com.evolveum.midpoint.schema.processor.ResourceObjectIdentification) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Test (org.testng.annotations.Test)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)9 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 QName (javax.xml.namespace.QName)7 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 Task (com.evolveum.midpoint.task.api.Task)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 Item (com.evolveum.midpoint.prism.Item)4 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 Collection (java.util.Collection)4