Search in sources :

Example 76 with ObjectReferenceType

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

the class AssignExecutor method resolve.

private Collection<ObjectReferenceType> resolve(ObjectReferenceType ref, QName relationOverride, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    if (ref.getFilter() != null) {
        Class<? extends ObjectType> clazz = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType());
        if (clazz == null) {
            throw new SchemaException("No compile time class for " + ref.getType() + " in " + ref);
        }
        ObjectQuery query = prismContext.getQueryConverter().createObjectQuery(clazz, ref.getFilter());
        QName effectiveRelation = getEffectiveRelation(ref, relationOverride);
        return modelService.searchObjects(clazz, query, createReadOnlyCollection(), task, result).stream().map(object -> ObjectTypeUtil.createObjectRef(object, effectiveRelation)).collect(Collectors.toList());
    } else if (relationOverride != null) {
        return singletonList(ref.clone().relation(relationOverride));
    } else {
        return singletonList(ref);
    }
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) 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) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) AssignExecutor(com.evolveum.midpoint.model.impl.scripting.actions.AssignExecutor) AssignActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.AssignActionExpressionType) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) List(java.util.List) Component(org.springframework.stereotype.Component) PrismConstants(com.evolveum.midpoint.prism.PrismConstants) PostConstruct(javax.annotation.PostConstruct) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 77 with ObjectReferenceType

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

the class AssignExecutor method parseParameters.

@Override
AssignParameters parseParameters(ActionExpressionType action, PipelineData input, ExecutionContext context, OperationResult result) throws SchemaException, ScriptExecutionException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    AssignParameters parameters = new AssignParameters();
    // Dynamic parameters
    Collection<ObjectReferenceType> dynamicRoleRefs = getRolesParameter(action, input, context, result);
    Collection<ObjectReferenceType> dynamicResourceRefs = getResourcesParameter(action, input, context, result);
    Collection<QName> relationSpecifications = getRelationsParameter(action, input, context, result);
    QName relationSpecification = MiscUtil.extractSingleton(relationSpecifications, () -> new IllegalArgumentException("Using 'relation' as a multivalued parameter is not allowed"));
    if (PrismConstants.Q_ANY.matches(relationSpecification)) {
        throw new IllegalArgumentException("Using 'q:any' as relation specification is not allowed");
    }
    QName relationOverride;
    if (relationSpecification != null) {
        List<RelationDefinitionType> relationDefinitions = relationRegistry.getRelationDefinitions();
        relationOverride = relationDefinitions.stream().filter(definition -> prismContext.relationMatches(relationSpecification, definition.getRef())).findFirst().orElseThrow(() -> new IllegalArgumentException("Relation matching '" + relationSpecification + "' not found")).getRef();
    } else {
        relationOverride = null;
    }
    // Static parameters
    Collection<ObjectReferenceType> staticTargetRefs;
    Collection<ObjectReferenceType> staticResourceRefs;
    Collection<ConstructionType> staticConstructions;
    if (action instanceof AssignActionExpressionType) {
        staticTargetRefs = ((AssignActionExpressionType) action).getTargetRef();
        staticResourceRefs = ((AssignActionExpressionType) action).getResourceRef();
        staticConstructions = ((AssignActionExpressionType) action).getConstruction();
    } else {
        staticTargetRefs = emptyList();
        staticResourceRefs = emptyList();
        staticConstructions = emptyList();
    }
    // Consolidation
    Task task = context.getTask();
    parameters.targetRefs.addAll(resolve(staticTargetRefs, relationOverride, task, result));
    parameters.targetRefs.addAll(resolve(dynamicRoleRefs, relationOverride, task, result));
    QName defaultRelation = relationRegistry.getDefaultRelation();
    parameters.constructions.addAll(staticConstructions);
    parameters.constructions.addAll(resourceRefsToConstructions(resolve(staticResourceRefs, defaultRelation, task, result)));
    parameters.constructions.addAll(resourceRefsToConstructions(resolve(dynamicResourceRefs, defaultRelation, task, result)));
    return parameters;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) AssignActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.AssignActionExpressionType)

Example 78 with ObjectReferenceType

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

the class PipelineData method getDataAsReferences.

/**
 * Returns the pipeline content as a list of references. Objects, PRVs, OIDs are converted directly
 * to references. Search filters and queries are evaluated first.
 *
 * This is a legacy method and its use should be avoided.
 */
@NotNull
public List<ObjectReferenceType> getDataAsReferences(QName defaultTargetType, Class<? extends ObjectType> typeForQuery, ExecutionContext context, OperationResult result) throws ScriptExecutionException, CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    List<ObjectReferenceType> retval = new ArrayList<>(data.size());
    for (PipelineItem item : data) {
        PrismValue value = item.getValue();
        if (value instanceof PrismObjectValue) {
            PrismObjectValue<?> objectValue = (PrismObjectValue<?>) value;
            ObjectReferenceType ref = new ObjectReferenceType();
            ref.setType(objectValue.asPrismObject().getDefinition().getTypeName());
            ref.setOid(objectValue.getOid());
            retval.add(ref);
        } else if (value instanceof PrismPropertyValue) {
            Object realValue = value.getRealValue();
            if (realValue instanceof SearchFilterType) {
                retval.addAll(resolveQuery(typeForQuery, new QueryType().filter((SearchFilterType) realValue), context, result));
            } else if (realValue instanceof QueryType) {
                retval.addAll(resolveQuery(typeForQuery, (QueryType) realValue, context, result));
            } else if (realValue instanceof String) {
                ObjectReferenceType ref = new ObjectReferenceType();
                ref.setType(defaultTargetType);
                ref.setOid((String) realValue);
                retval.add(ref);
            } else if (realValue instanceof ObjectReferenceType) {
                retval.add((ObjectReferenceType) realValue);
            } else {
                throw new ScriptExecutionException("Unsupported reference type: " + value.getClass());
            }
        } else if (value instanceof PrismReferenceValue) {
            PrismReferenceValue referenceValue = (PrismReferenceValue) value;
            ObjectReferenceType ref = new ObjectReferenceType();
            ref.setupReferenceValue(referenceValue);
            retval.add(ref);
        }
    }
    return retval;
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with ObjectReferenceType

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

the class PipelineData method prepareXmlData.

public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) {
    boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults());
    PipelineDataType rv = new PipelineDataType();
    if (output != null) {
        for (PipelineItem item : output) {
            PipelineItemType itemType = new PipelineItemType();
            PrismValue value = item.getValue();
            if (value instanceof PrismReferenceValue) {
                // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName)
                ObjectReferenceType ort = new ObjectReferenceType();
                ort.setupReferenceValue((PrismReferenceValue) value);
                itemType.setValue(ort);
            } else {
                itemType.setValue(value.getRealValue());
            }
            if (!hideResults) {
                itemType.setResult(item.getResult().createOperationResultType());
            }
            rv.getItem().add(itemType);
        }
    }
    return rv;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)

Example 80 with ObjectReferenceType

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

the class ModelInteractionServiceImpl method getDeputyAssignees.

private void getDeputyAssignees(List<ObjectReferenceType> deputies, AbstractWorkItemType workItem, Set<String> oidsToSkip, Task task, OperationResult result) throws SchemaException {
    List<PrismReferenceValue> assigneeReferencesToQuery = workItem.getAssigneeRef().stream().map(assigneeRef -> assigneeRef.clone().relation(PrismConstants.Q_ANY).asReferenceValue()).collect(Collectors.toList());
    ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_DELEGATED_REF).ref(assigneeReferencesToQuery).build();
    SearchResultList<PrismObject<UserType>> potentialDeputies = cacheRepositoryService.searchObjects(UserType.class, query, null, // TODO consider read-only here
    result);
    for (PrismObject<UserType> potentialDeputy : potentialDeputies) {
        if (oidsToSkip.contains(potentialDeputy.getOid())) {
            continue;
        }
        if (determineDeputyValidity(potentialDeputy, workItem.getAssigneeRef(), workItem, OtherPrivilegesLimitationType.F_APPROVAL_WORK_ITEMS, task, result)) {
            deputies.add(ObjectTypeUtil.createObjectRefWithFullObject(potentialDeputy, prismContext));
            oidsToSkip.add(potentialDeputy.getOid());
        }
    }
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) AssignmentOrigin(com.evolveum.midpoint.model.impl.lens.projector.AssignmentOrigin) com.evolveum.midpoint.model.api.authentication(com.evolveum.midpoint.model.api.authentication) ObjectTypeUtil.createObjectRef(com.evolveum.midpoint.schema.util.ObjectTypeUtil.createObjectRef) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) StringUtils(org.apache.commons.lang3.StringUtils) BooleanUtils(org.apache.commons.lang.BooleanUtils) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) Scene(com.evolveum.midpoint.model.api.visualizer.Scene) GetOperationOptions.createExecutionPhase(com.evolveum.midpoint.schema.GetOperationOptions.createExecutionPhase) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) MetadataItemProcessingSpecImpl(com.evolveum.midpoint.model.common.mapping.metadata.MetadataItemProcessingSpecImpl) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectSecurityConstraints(com.evolveum.midpoint.security.enforcer.api.ObjectSecurityConstraints) Task(com.evolveum.midpoint.task.api.Task) DeputyUtils(com.evolveum.midpoint.model.api.util.DeputyUtils) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) Validate(org.apache.commons.lang.Validate) Clock(com.evolveum.midpoint.common.Clock) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) java.util(java.util) DeltaFactory(com.evolveum.midpoint.prism.delta.DeltaFactory) SelectorOptions.createCollection(com.evolveum.midpoint.schema.SelectorOptions.createCollection) com.evolveum.midpoint.util(com.evolveum.midpoint.util) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) EvaluatedAssignment(com.evolveum.midpoint.model.api.context.EvaluatedAssignment) Trace(com.evolveum.midpoint.util.logging.Trace) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) RepositoryCache(com.evolveum.midpoint.repo.cache.RepositoryCache) com.evolveum.midpoint.model.api(com.evolveum.midpoint.model.api) TransformableContainerDefinition(com.evolveum.midpoint.model.impl.schema.transform.TransformableContainerDefinition) MergeDeltas(com.evolveum.midpoint.model.api.util.MergeDeltas) ConnectorOperationalStatus(com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) RUNNABLE(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE) PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator) ReferenceResolver(com.evolveum.midpoint.model.api.util.ReferenceResolver) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemName(com.evolveum.midpoint.prism.path.ItemName) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) TransformableObjectDefinition(com.evolveum.midpoint.model.impl.schema.transform.TransformableObjectDefinition) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) com.evolveum.midpoint.schema.util(com.evolveum.midpoint.schema.util) ItemPathTypeUtil(com.evolveum.midpoint.prism.util.ItemPathTypeUtil) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager) com.evolveum.midpoint.xml.ns._public.common.api_types_3(com.evolveum.midpoint.xml.ns._public.common.api_types_3) Collections.singleton(java.util.Collections.singleton) ModelCrudService(com.evolveum.midpoint.model.impl.ModelCrudService) ItemSecurityConstraints(com.evolveum.midpoint.security.enforcer.api.ItemSecurityConstraints) com.evolveum.midpoint.model.common.stringpolicy(com.evolveum.midpoint.model.common.stringpolicy) Experimental(com.evolveum.midpoint.util.annotation.Experimental) FilterGizmo(com.evolveum.midpoint.security.enforcer.api.FilterGizmo) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ActivationComputer(com.evolveum.midpoint.common.ActivationComputer) Collectors(java.util.stream.Collectors) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) Visualizer(com.evolveum.midpoint.model.impl.visualizer.Visualizer) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) Nullable(org.jetbrains.annotations.Nullable) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) READY(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskSchedulingStateType.READY) NotNull(org.jetbrains.annotations.NotNull) Authentication(org.springframework.security.core.Authentication) ContextLoader(com.evolveum.midpoint.model.impl.lens.projector.ContextLoader) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) ArchetypeManager(com.evolveum.midpoint.model.common.ArchetypeManager) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ModelBeans(com.evolveum.midpoint.model.impl.ModelBeans) EvaluatedAssignmentTarget(com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MappingEvaluator(com.evolveum.midpoint.model.impl.lens.projector.mappings.MappingEvaluator) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) GuiProfileCompiler(com.evolveum.midpoint.model.impl.security.GuiProfileCompiler) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.model.impl.lens(com.evolveum.midpoint.model.impl.lens) SecurityEnforcer(com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) Component(org.springframework.stereotype.Component) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) Protector(com.evolveum.midpoint.prism.crypto.Protector) TerminateSessionEvent(com.evolveum.midpoint.TerminateSessionEvent) ModelObjectResolver(com.evolveum.midpoint.model.impl.ModelObjectResolver) CacheConfigurationManager(com.evolveum.midpoint.schema.cache.CacheConfigurationManager) SecurityHelper(com.evolveum.midpoint.model.impl.security.SecurityHelper) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

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