Search in sources :

Example 81 with ObjectReferenceType

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

the class LinkedObjectsFunctions method findLinkedTargets.

// Should be used after assignment evaluation!
@Experimental
@NotNull
<T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult currentResult = midpointFunctions.getCurrentResult();
    LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
    if (focusContext == null) {
        throw new IllegalStateException("No focus context");
    }
    LinkTypeDefinitionType definition = focusContext.getTargetLinkTypeDefinition(linkTypeName, linkManager, currentResult);
    if (definition == null) {
        throw new IllegalStateException("No definition for target link type " + linkTypeName + " for " + focusContext);
    }
    Class<?> expectedClasses = getExpectedClass(definition.getSelector());
    Set<PrismReferenceValue> membership = getMembership();
    List<PrismReferenceValue> assignedWithMatchingRelation = membership.stream().filter(ref -> relationMatches(ref, definition.getSelector()) && objectTypeMatches(ref, expectedClasses)).collect(Collectors.toList());
    // TODO deduplicate w.r.t. member/manager
    // TODO optimize matching
    List<T> objects = new ArrayList<>(assignedWithMatchingRelation.size());
    for (PrismReferenceValue reference : assignedWithMatchingRelation) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue(reference);
        T object = midpointFunctions.resolveReferenceInternal(ort, true);
        if (objectMatches(object, definition.getSelector())) {
            objects.add(object);
        }
    }
    return objects;
}
Also used : java.util(java.util) 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) Trace(com.evolveum.midpoint.util.logging.Trace) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) LinkedSelectorToFilterTranslator(com.evolveum.midpoint.repo.common.query.LinkedSelectorToFilterTranslator) Experimental(com.evolveum.midpoint.util.annotation.Experimental) Collections.emptySet(java.util.Collections.emptySet) Objectable(com.evolveum.midpoint.prism.Objectable) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) Modifier(java.lang.reflect.Modifier) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) LinkManager(com.evolveum.midpoint.model.common.LinkManager) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Experimental(com.evolveum.midpoint.util.annotation.Experimental) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with ObjectReferenceType

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

the class OrgStructFunctionsImpl method getParentOrgs.

@Override
public Collection<OrgType> getParentOrgs(ObjectType object, QName relation, @NotNull Predicate<OrgType> predicate, boolean preAuthorized) throws SchemaException, SecurityViolationException {
    List<ObjectReferenceType> parentOrgRefs = object.getParentOrgRef();
    List<OrgType> parentOrgs = new ArrayList<>(parentOrgRefs.size());
    for (ObjectReferenceType parentOrgRef : parentOrgRefs) {
        if (!prismContext.relationMatches(relation, parentOrgRef.getRelation())) {
            continue;
        }
        OrgType parentOrg;
        try {
            parentOrg = getObject(OrgType.class, parentOrgRef.getOid(), preAuthorized);
        } catch (ObjectNotFoundException e) {
            LOGGER.warn("Org " + parentOrgRef.getOid() + " specified in parentOrgRef in " + object + " was not found: " + e.getMessage(), e);
            // but do not rethrow, just skip this
            continue;
        } catch (CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
            // This should not happen.
            throw new SystemException(e.getMessage(), e);
        }
        if (predicate.test(parentOrg)) {
            parentOrgs.add(parentOrg);
        }
    }
    return parentOrgs;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)

Example 83 with ObjectReferenceType

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

the class ClockworkAuthorizationHelper method authorizeAssignmentRequest.

private <F extends ObjectType, O extends ObjectType> void authorizeAssignmentRequest(LensContext<F> context, String operationUrl, String assignActionUrl, ItemName assignmentElementQName, PrismObject<O> object, OwnerResolver ownerResolver, ObjectSecurityConstraints securityConstraints, PlusMinusZero plusMinusZero, boolean prohibitPolicies, Task task, OperationResult result) throws SecurityViolationException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException {
    // This is *request* authorization. Therefore we care only about primary delta.
    ObjectDelta<F> focusPrimaryDelta = context.getFocusContext().getPrimaryDelta();
    if (focusPrimaryDelta == null) {
        return;
    }
    ContainerDelta<AssignmentType> focusAssignmentDelta = focusPrimaryDelta.findContainerDelta(assignmentElementQName);
    if (focusAssignmentDelta == null) {
        return;
    }
    String operationDesc = assignActionUrl.substring(assignActionUrl.lastIndexOf('#') + 1);
    Collection<PrismContainerValue<AssignmentType>> changedAssignmentValues = determineChangedAssignmentValues(context.getFocusContext(), assignmentElementQName, focusAssignmentDelta, plusMinusZero);
    for (PrismContainerValue<AssignmentType> changedAssignmentValue : changedAssignmentValues) {
        AssignmentType changedAssignment = changedAssignmentValue.getRealValue();
        ObjectReferenceType targetRef = changedAssignment.getTargetRef();
        if (targetRef == null || targetRef.getOid() == null) {
            // This may still be allowed by #add and #modify authorizations. We have already checked these, but there may be combinations of
            // assignments, one of the assignments allowed by #assign, other allowed by #modify (e.g. MID-4517).
            // Therefore check the items again. This is not very efficient to check it twice. But this is not a common case
            // so there should not be any big harm in suffering this inefficiency.
            AccessDecision subitemDecision = securityEnforcer.determineSubitemDecision(securityConstraints, changedAssignmentValue, operationUrl, getRequestAuthorizationPhase(context), null, plusMinusZero, operationDesc);
            if (subitemDecision == AccessDecision.ALLOW) {
                LOGGER.debug("{} of policy {} to {} allowed with {} authorization", operationDesc, assignmentElementQName.getLocalPart(), object, operationUrl);
                continue;
            } else {
                LOGGER.debug("{} of non-target {} not allowed", operationDesc, assignmentElementQName.getLocalPart());
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Denied request for object {}: {} of non-target {} not allowed", object, operationDesc, assignmentElementQName.getLocalPart());
                }
                securityEnforcer.failAuthorization(operationDesc, getRequestAuthorizationPhase(context), AuthorizationParameters.Builder.buildObject(object), result);
            }
        }
        PrismObject<ObjectType> target;
        try {
            // We do not worry about performance here too much. The target was already evaluated. This will be retrieved from repo cache anyway.
            target = objectResolver.resolve(targetRef.asReferenceValue(), "resolving " + assignmentElementQName.getLocalPart() + " target", task, result);
        } catch (ObjectNotFoundException e) {
            LOGGER.warn("Object {} referenced as {} target in {} was not found", targetRef.asReferenceValue().getOid(), assignmentElementQName.getLocalPart(), object);
            target = null;
        }
        ObjectDelta<O> assignmentObjectDelta = object.createModifyDelta();
        ContainerDelta<AssignmentType> assignmentDelta = assignmentObjectDelta.createContainerModification(assignmentElementQName);
        // We do not care if this is add or delete. All that matters for authorization is that it is in a delta.
        assignmentDelta.addValuesToAdd(changedAssignment.asPrismContainerValue().clone());
        QName relation = targetRef.getRelation();
        if (relation == null) {
            relation = prismContext.getDefaultRelation();
        }
        List<OrderConstraintsType> orderConstraints = determineOrderConstraints(assignmentElementQName, changedAssignment);
        AuthorizationParameters<O, ObjectType> autzParams = new AuthorizationParameters.Builder<O, ObjectType>().oldObject(object).delta(assignmentObjectDelta).target(target).relation(relation).orderConstraints(orderConstraints).build();
        if (prohibitPolicies) {
            if (changedAssignment.getPolicyRule() != null || !changedAssignment.getPolicyException().isEmpty() || !changedAssignment.getPolicySituation().isEmpty() || !changedAssignment.getTriggeredPolicyRule().isEmpty()) {
                // This may still be allowed by #add and #modify authorizations. We have already checked these, but there may be combinations of
                // assignments, one of the assignments allowed by #assign, other allowed by #modify (e.g. MID-4517).
                // Therefore check the items again. This is not very efficient to check it twice. But this is not a common case
                // so there should not be any big harm in suffering this inefficiency.
                AccessDecision subitemDecision = securityEnforcer.determineSubitemDecision(securityConstraints, changedAssignmentValue, operationUrl, getRequestAuthorizationPhase(context), null, plusMinusZero, operationDesc);
                if (subitemDecision == AccessDecision.ALLOW) {
                    LOGGER.debug("{} of policy assignment to {} allowed with {} authorization", operationDesc, object, operationUrl);
                    continue;
                } else {
                    securityEnforcer.failAuthorization("with assignment because of policies in the assignment", getRequestAuthorizationPhase(context), autzParams, result);
                }
            }
        }
        if (securityEnforcer.isAuthorized(assignActionUrl, getRequestAuthorizationPhase(context), autzParams, ownerResolver, task, result)) {
            LOGGER.debug("{} of target {} to {} allowed with {} authorization", operationDesc, target, object, assignActionUrl);
            continue;
        }
        if (relationRegistry.isDelegation(relation)) {
            if (securityEnforcer.isAuthorized(ModelAuthorizationAction.DELEGATE.getUrl(), getRequestAuthorizationPhase(context), autzParams, ownerResolver, task, result)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("{} of target {} to {} allowed with {} authorization", operationDesc, target, object, ModelAuthorizationAction.DELEGATE.getUrl());
                }
                continue;
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("{} of target {} to {} denied", operationDesc, target, object);
        }
        securityEnforcer.failAuthorization("with " + assignmentElementQName.getLocalPart(), getRequestAuthorizationPhase(context), autzParams, result);
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) QName(javax.xml.namespace.QName) OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) AccessDecision(com.evolveum.midpoint.schema.AccessDecision) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 84 with ObjectReferenceType

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

the class MissingShadowContextRefresher method reloadFocusAndFindMatchingLink.

private boolean reloadFocusAndFindMatchingLink(OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<F> reloadedFocusObject = reloadFocus(result);
    if (reloadedFocusObject == null) {
        // reason already logged
        return false;
    }
    FocusType reloadedFocus = (FocusType) reloadedFocusObject.asObjectable();
    // TODO shouldn't we put the reloaded focus back into the focus context? Beware that it was fetched as read-only.
    LensFocusContext<F> focusContext = context.getFocusContextRequired();
    for (ObjectReferenceType linkRef : reloadedFocus.getLinkRef()) {
        if (linkRef.getOid().equals(projectionContext.getOid())) {
            if (projectionContext.isReaping()) {
                LOGGER.trace("Not deleting linkRef for {} because the shadow is being reaped", projectionContext.getOid());
            } else {
                // The deleted shadow is still in the linkRef. This should not happen, but it obviously happens sometimes.
                // Maybe some strange race condition? Anyway, we want a robust behavior and this linkRef should NOT be there.
                // So simply remove it.
                LOGGER.warn("The OID {} of deleted shadow still exists in the linkRef after discovery ({}), removing it", projectionContext.getOid(), reloadedFocusObject);
                swallowUnlinkDelta(focusContext, linkRef);
            }
            continue;
        }
        boolean found = context.getProjectionContexts().stream().anyMatch(pCtx -> linkRef.getOid().equals(pCtx.getOid()));
        if (found) {
            // Continue searching.
            continue;
        }
        // This linkRef is new, it is not in the existing lens context. Is it matching?
        PrismObject<ShadowType> newLinkRepoShadow;
        try {
            // Consider read-only option later (but now the object is inserted into projection context, so using R/W mode).
            newLinkRepoShadow = beans.cacheRepositoryService.getObject(ShadowType.class, linkRef.getOid(), null, result);
        } catch (ObjectNotFoundException e) {
            LoggingUtils.logExceptionAsWarning(LOGGER, "Couldn't resolve {}, unlinking it from the focus {}", e, linkRef.getOid(), reloadedFocus);
            swallowUnlinkDelta(focusContext, linkRef);
            continue;
        }
        if (!ShadowUtil.matches(newLinkRepoShadow, projectionContext.getResourceShadowDiscriminator())) {
            LOGGER.trace("Found new link: {}, but skipping it because it does not match the projection context", newLinkRepoShadow);
            continue;
        }
        LOGGER.trace("Found new matching link: {}, updating projection context", newLinkRepoShadow);
        // MID-3317
        LOGGER.trace("Applying definition from provisioning first.");
        beans.provisioningService.applyDefinition(newLinkRepoShadow, task, result);
        projectionContext.setCurrentObjectAndOid(newLinkRepoShadow);
        // The "exists" information in the projection context can be obsolete - reflecting the fact that
        // resource object couldn't be found.
        projectionContext.setExists(ShadowUtil.isExists(newLinkRepoShadow));
        projectionContext.recompute();
        return true;
    }
    LOGGER.trace(" -> no suitable link found");
    return false;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)

Example 85 with ObjectReferenceType

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

the class TestConsistencySimple method cleanUpBeforeTest.

private void cleanUpBeforeTest(Task task, OperationResult result) throws Exception {
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    display("Jack on start", jack);
    if (!jack.asObjectable().getAssignment().isEmpty()) {
        unassignAccountFromUser(USER_JACK_OID, RESOURCE_DUMMY_OID, SchemaConstants.INTENT_DEFAULT, task, result);
        jack = getUser(USER_JACK_OID);
        display("Jack after initial unassign", jack);
    }
    if (!jack.asObjectable().getLinkRef().isEmpty()) {
        for (ObjectReferenceType ref : jack.asObjectable().getLinkRef()) {
            deleteObject(ShadowType.class, ref.getOid());
        }
        ObjectDelta<UserType> killLinkRefDelta = deltaFor(UserType.class).item(UserType.F_LINK_REF).replace().asObjectDelta(USER_JACK_OID);
        executeChanges(killLinkRefDelta, executeOptions().raw(), task, result);
    }
    List<PrismObject<ShadowType>> jacksShadows = getJacksShadows(result);
    for (PrismObject<ShadowType> shadow : jacksShadows) {
        deleteObject(ShadowType.class, shadow.getOid());
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)278 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)104 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)61 Test (org.testng.annotations.Test)61 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)56 Task (com.evolveum.midpoint.task.api.Task)53 QName (javax.xml.namespace.QName)46 ArrayList (java.util.ArrayList)44 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)42 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)37 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)33 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)32 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)31 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)23 List (java.util.List)23