Search in sources :

Example 36 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method getLinkRefOid.

protected <F extends FocusType> String getLinkRefOid(PrismObject<F> focus, String resourceOid, ShadowKindType kind, String intent) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    F focusType = focus.asObjectable();
    for (ObjectReferenceType linkRefType : focusType.getLinkRef()) {
        String linkTargetOid = linkRefType.getOid();
        assertFalse("No linkRef oid", StringUtils.isBlank(linkTargetOid));
        PrismObject<ShadowType> account = getShadowModel(linkTargetOid, GetOperationOptions.createNoFetch(), false);
        ShadowType shadowType = account.asObjectable();
        if (kind != null && !kind.equals(shadowType.getKind())) {
            continue;
        }
        if (!MiscUtil.equals(intent, shadowType.getIntent())) {
            continue;
        }
        if (resourceOid.equals(shadowType.getResourceRef().getOid())) {
            // This is noFetch. Therefore there is no fetchResult
            return linkTargetOid;
        }
    }
    AssertJUnit.fail("Linked shadow for resource " + resourceOid + ", kind " + kind + " and intent " + intent + " not found in " + focus);
    // Never reached. But compiler complains about missing return
    return null;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 37 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class ProvisioningTestUtil method checkRepoShadow.

public static void checkRepoShadow(PrismObject<ShadowType> repoShadow, ShadowKindType kind, Integer expectedNumberOfAttributes) {
    ShadowType repoShadowType = repoShadow.asObjectable();
    assertNotNull("No OID in repo shadow " + repoShadow, repoShadowType.getOid());
    assertNotNull("No name in repo shadow " + repoShadow, repoShadowType.getName());
    assertNotNull("No objectClass in repo shadow " + repoShadow, repoShadowType.getObjectClass());
    assertEquals("Wrong kind in repo shadow " + repoShadow, kind, repoShadowType.getKind());
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    assertNotNull("No attributes in repo shadow " + repoShadow, attributesContainer);
    Collection<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
    assertFalse("Empty attributes in repo shadow " + repoShadow, attributes.isEmpty());
    if (expectedNumberOfAttributes != null) {
        assertEquals("Unexpected number of attributes in repo shadow " + repoShadow, (int) expectedNumberOfAttributes, attributes.size());
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Containerable(com.evolveum.midpoint.prism.Containerable)

Example 38 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class KindIntentFilterHelper method processEvent.

public boolean processEvent(Event event, BaseEventHandlerType eventHandlerConfig) {
    if (eventHandlerConfig.getObjectKind().isEmpty() && eventHandlerConfig.getObjectIntent().isEmpty()) {
        return true;
    }
    if (!(event instanceof ResourceObjectEvent)) {
        // or should we return false?
        return true;
    }
    ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
    logStart(LOGGER, event, eventHandlerConfig, eventHandlerConfig.getStatus());
    boolean retval = true;
    if (!eventHandlerConfig.getObjectKind().isEmpty()) {
        retval = false;
        for (ShadowKindType shadowKindType : eventHandlerConfig.getObjectKind()) {
            if (shadowKindType == null) {
                LOGGER.warn("Filtering on null shadowKindType; filter = " + eventHandlerConfig);
            } else if (resourceObjectEvent.isShadowKind(shadowKindType)) {
                retval = true;
                break;
            }
        }
    }
    if (retval) {
        // now check the intent
        if (!eventHandlerConfig.getObjectIntent().isEmpty()) {
            retval = false;
            for (String intent : eventHandlerConfig.getObjectIntent()) {
                if (intent == null) {
                    LOGGER.warn("Filtering on null intent; filter = " + eventHandlerConfig);
                } else if (resourceObjectEvent.isShadowIntent(intent)) {
                    retval = true;
                    break;
                }
            }
        }
    }
    logEnd(LOGGER, event, eventHandlerConfig, retval);
    return retval;
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 39 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class EntitlementConverter method collectEntitlementsAsObjectOperationDelete.

// endregion
// region Delete
// ///////
// DELETE
// ///////
/**
 * This is somehow different that all the other methods. We are not following the content of a shadow or delta.
 * We are following the definitions. This is to avoid the need to read the object that is going to be deleted.
 * In fact, the object should not be there any more, but we still want to clean up entitlement membership
 * based on the information from the shadow.
 *
 * @param <T> Type of the association (referencing) attribute
 */
<T> void collectEntitlementsAsObjectOperationDelete(Map<ResourceObjectDiscriminator, ResourceObjectOperations> roMap, PrismObject<ShadowType> subjectShadow, ProvisioningContext subjectCtx, OperationResult result) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ResourceObjectDefinition subjectDef = subjectCtx.getObjectDefinitionRequired();
    Collection<ResourceAssociationDefinition> associationDefs = subjectDef.getAssociationDefinitions();
    if (associationDefs.isEmpty()) {
        LOGGER.trace("No associations in deleted shadow, nothing to do");
        return;
    }
    ResourceAttributeContainer subjectAttributesContainer = ShadowUtil.getAttributesContainer(subjectShadow);
    for (ResourceAssociationDefinition associationDef : associationDefs) {
        if (associationDef.getDirection() != ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
            // We can ignore these. They will die together with the object. No need to explicitly delete them.
            LOGGER.trace("Ignoring subject-to-object association in deleted shadow");
            continue;
        }
        if (!associationDef.requiresExplicitReferentialIntegrity()) {
            LOGGER.trace("Ignoring association in deleted shadow because it does not require explicit" + " referential integrity assurance");
            continue;
        }
        if (associationDef.getAuxiliaryObjectClass() != null && !subjectDef.hasAuxiliaryObjectClass(associationDef.getAuxiliaryObjectClass())) {
            LOGGER.trace("Ignoring association in deleted shadow because subject does not have {} auxiliary object class", associationDef.getAuxiliaryObjectClass());
            continue;
        }
        QName associationName = associationDef.getName();
        ShadowKindType entitlementKind = associationDef.getKind();
        for (String entitlementIntent : associationDef.getIntents()) {
            // TODO deduplicate the code
            // TODO error handling
            ProvisioningContext entitlementCtx = subjectCtx.spawnForKindIntent(entitlementKind, entitlementIntent);
            ResourceObjectDefinition entitlementDef = entitlementCtx.getObjectDefinitionRequired();
            QName assocAttrName = associationDef.getDefinitionBean().getAssociationAttribute();
            QName valueAttrName = associationDef.getDefinitionBean().getValueAttribute();
            schemaCheck(assocAttrName != null, "No association attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
            schemaCheck(valueAttrName != null, "No value attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
            // noinspection unchecked
            ResourceAttributeDefinition<T> assocAttrDef = (ResourceAttributeDefinition<T>) entitlementDef.findAttributeDefinitionRequired(assocAttrName, () -> " in entitlement association '" + associationName + "' in " + entitlementCtx + " [association attribute]");
            final ResourceAttribute<T> valueAttr = subjectAttributesContainer.findAttribute(valueAttrName);
            if (valueAttr == null || valueAttr.isEmpty()) {
                // Although we cannot really remedy the situation now, we at least throw an error so the problem is detected.
                throw new SchemaException("Value attribute " + valueAttrName + " has no value; attribute defined in entitlement " + "association '" + associationName + "' in " + subjectCtx);
            }
            if (valueAttr.size() > 1) {
                throw new SchemaException("Value attribute " + valueAttrName + " has no more than one value; attribute defined" + " in entitlement association '" + associationName + "' in " + subjectCtx);
            }
            ResourceAttributeDefinition<T> valueAttrDef = valueAttr.getDefinition();
            PrismPropertyValue<T> valueAttrValue = valueAttr.getAnyValue();
            ObjectQuery query = createEntitlementQuery(valueAttrValue, valueAttrDef, assocAttrDef, associationDef);
            AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(entitlementCtx);
            SearchHierarchyConstraints searchHierarchyConstraints = determineSearchHierarchyConstraints(entitlementCtx, result);
            ObjectHandler handler = (ucfObject, lResult) -> {
                PrismObject<ShadowType> entitlementShadow = ucfObject.getResourceObject();
                Collection<? extends ResourceAttribute<?>> primaryIdentifiers = ShadowUtil.getPrimaryIdentifiers(entitlementShadow);
                ResourceObjectDiscriminator disc = new ResourceObjectDiscriminator(entitlementDef.getTypeName(), primaryIdentifiers);
                ResourceObjectOperations operations = roMap.get(disc);
                if (operations == null) {
                    operations = new ResourceObjectOperations();
                    roMap.put(disc, operations);
                    operations.setResourceObjectContext(entitlementCtx);
                    Collection<? extends ResourceAttribute<?>> allIdentifiers = ShadowUtil.getAllIdentifiers(entitlementShadow);
                    operations.setAllIdentifiers(allIdentifiers);
                }
                PropertyDelta<T> attributeDelta = null;
                for (Operation operation : operations.getOperations()) {
                    if (operation instanceof PropertyModificationOperation) {
                        PropertyModificationOperation<?> propOp = (PropertyModificationOperation<?>) operation;
                        if (propOp.getPropertyDelta().getElementName().equals(assocAttrName)) {
                            // noinspection unchecked
                            attributeDelta = (PropertyDelta<T>) propOp.getPropertyDelta();
                        }
                    }
                }
                if (attributeDelta == null) {
                    attributeDelta = assocAttrDef.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, assocAttrName));
                    PropertyModificationOperation<?> attributeModification = new PropertyModificationOperation<>(attributeDelta);
                    attributeModification.setMatchingRuleQName(associationDef.getMatchingRule());
                    operations.add(attributeModification);
                }
                attributeDelta.addValuesToDelete(valueAttr.getClonedValues());
                LOGGER.trace("Association in deleted shadow delta:\n{}", attributeDelta.debugDumpLazily());
                return true;
            };
            try {
                LOGGER.trace("Searching for associations in deleted shadow, query: {}", query);
                ConnectorInstance connector = subjectCtx.getConnector(ReadCapabilityType.class, result);
                connector.search(entitlementDef, query, handler, attributesToReturn, null, searchHierarchyConstraints, UcfFetchErrorReportingMethod.EXCEPTION, subjectCtx.getUcfExecutionContext(), result);
            } catch (TunnelException e) {
                throw (SchemaException) e.getCause();
            } catch (GenericFrameworkException e) {
                throw new GenericConnectorException(e.getMessage(), e);
            }
        }
    }
}
Also used : ResourceObjectOperations(com.evolveum.midpoint.provisioning.impl.ResourceObjectOperations) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) MiscUtil.emptyIfNull(com.evolveum.midpoint.util.MiscUtil.emptyIfNull) HashMap(java.util.HashMap) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ResourceObjectDiscriminator(com.evolveum.midpoint.provisioning.impl.ResourceObjectDiscriminator) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) Map(java.util.Map) MiscUtil.schemaCheck(com.evolveum.midpoint.util.MiscUtil.schemaCheck) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ObjectFactory(com.evolveum.midpoint.schema.processor.ObjectFactory) Collection(java.util.Collection) PrismUtil(com.evolveum.midpoint.prism.util.PrismUtil) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Nullable(org.jetbrains.annotations.Nullable) Component(org.springframework.stereotype.Component) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ItemName(com.evolveum.midpoint.prism.path.ItemName) com.evolveum.midpoint.provisioning.ucf.api(com.evolveum.midpoint.provisioning.ucf.api) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) ProvisioningUtil(com.evolveum.midpoint.provisioning.util.ProvisioningUtil) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ResourceObjectDiscriminator(com.evolveum.midpoint.provisioning.impl.ResourceObjectDiscriminator) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ResourceObjectOperations(com.evolveum.midpoint.provisioning.impl.ResourceObjectOperations) Collection(java.util.Collection)

Example 40 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method selectMatchingShadows.

private void selectMatchingShadows(List<String> candidateShadowsOidList, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, ExpressionEvaluationContext context, OperationResult result) {
    S_AtomicFilterExit filter = prismContext.queryFor(ShadowType.class).id(candidateShadowsOidList.toArray(new String[0])).and().item(ShadowType.F_RESOURCE_REF).ref(resourceOid).and().item(ShadowType.F_KIND).eq(kind);
    if (intent != null) {
        filter = filter.and().item(ShadowType.F_INTENT).eq(intent);
    }
    ObjectQuery query = filter.build();
    try {
        List<PrismObject<ShadowType>> objects = objectResolver.searchObjects(ShadowType.class, query, createNoFetchReadOnlyCollection(), context.getTask(), result);
        for (PrismObject<ShadowType> object : objects) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            toAssociation(object, shadowAssociationType);
        }
    } catch (CommonException e) {
        throw new SystemException("Couldn't search for relevant shadows: " + e.getMessage(), e);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) S_AtomicFilterExit(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Aggregations

ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)33 QName (javax.xml.namespace.QName)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 ArrayList (java.util.ArrayList)7 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 List (java.util.List)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 NotNull (org.jetbrains.annotations.NotNull)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3