Search in sources :

Example 6 with ObjectReferenceType

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

the class PageTaskAdd method createTask.

private TaskType createTask(TaskAddDto dto) throws SchemaException {
    TaskType task = new TaskType();
    MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
    ObjectReferenceType ownerRef = new ObjectReferenceType();
    ownerRef.setOid(owner.getOid());
    ownerRef.setType(owner.getUser().COMPLEX_TYPE);
    task.setOwnerRef(ownerRef);
    task.setCategory(dto.getCategory());
    String handlerUri = getTaskManager().getHandlerUriForCategory(dto.getCategory());
    if (handlerUri == null) {
        throw new SystemException("Cannot determine task handler URI for category " + dto.getCategory());
    }
    task.setHandlerUri(handlerUri);
    ObjectReferenceType objectRef;
    if (dto.getResource() != null) {
        objectRef = new ObjectReferenceType();
        objectRef.setOid(dto.getResource().getOid());
        objectRef.setType(ResourceType.COMPLEX_TYPE);
        task.setObjectRef(objectRef);
    }
    task.setName(WebComponentUtil.createPolyFromOrigString(dto.getName()));
    task.setRecurrence(dto.getReccuring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
    task.setBinding(dto.getBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
    ScheduleType schedule = new ScheduleType();
    schedule.setInterval(dto.getInterval());
    schedule.setCronLikePattern(dto.getCron());
    schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
    schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
    schedule.setMisfireAction(dto.getMisfireAction());
    task.setSchedule(schedule);
    if (dto.getSuspendedState()) {
        task.setExecutionStatus(TaskExecutionStatusType.SUSPENDED);
    } else {
        task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
    }
    if (dto.getThreadStop() != null) {
        task.setThreadStopAction(dto.getThreadStop());
    } else {
        // fill-in default
        if (dto.getRunUntilNodeDown() == true) {
            task.setThreadStopAction(ThreadStopActionType.CLOSE);
        } else {
            task.setThreadStopAction(ThreadStopActionType.RESTART);
        }
    }
    if (dto.isDryRun()) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        PrismProperty dryRun = prismTask.findOrCreateProperty(path);
        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        dryRun.setDefinition(def);
        dryRun.setRealValue(true);
    }
    if (dto.getFocusType() != null) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
        PrismProperty focusType = prismTask.findOrCreateProperty(path);
        focusType.setRealValue(dto.getFocusType());
    }
    if (dto.getKind() != null) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
        PrismProperty kind = prismTask.findOrCreateProperty(path);
        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
        kind.setDefinition(def);
        kind.setRealValue(dto.getKind());
    }
    if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT);
        PrismProperty intent = prismTask.findOrCreateProperty(path);
        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
        intent.setDefinition(def);
        intent.setRealValue(dto.getIntent());
    }
    if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);
        QName objectClass = null;
        for (QName q : model.getObject().getObjectClassList()) {
            if (q.getLocalPart().equals(dto.getObjectClass())) {
                objectClass = q;
            }
        }
        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        objectClassProperty.setDefinition(def);
        objectClassProperty.setRealValue(objectClass);
    }
    return task;
}
Also used : ScheduleType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScheduleType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with ObjectReferenceType

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

the class AssignExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean raw = getParamRaw(expression, input, context, globalResult);
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    ActionParameterValueType resourceParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_RESOURCE, false, false, NAME);
    ActionParameterValueType roleParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_ROLE, false, false, NAME);
    Collection<ObjectReferenceType> resources;
    if (resourceParameterValue != null) {
        PipelineData data = expressionHelper.evaluateParameter(resourceParameterValue, null, input, context, globalResult);
        resources = data.getDataAsReferences(ResourceType.COMPLEX_TYPE);
    } else {
        resources = null;
    }
    Collection<ObjectReferenceType> roles;
    if (roleParameterValue != null) {
        PipelineData data = expressionHelper.evaluateParameter(roleParameterValue, null, input, context, globalResult);
        roles = data.getDataAsReferences(RoleType.COMPLEX_TYPE);
    } else {
        roles = null;
    }
    if (resources == null && roles == null) {
        throw new ScriptExecutionException("Nothing to assign: neither resource nor role specified");
    }
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
            PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
            ObjectType objectType = prismObject.asObjectable();
            long started = operationsHelper.recordStart(context, objectType);
            Throwable exception = null;
            try {
                operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
                operationsHelper.recordEnd(context, objectType, started, null);
            } catch (Throwable ex) {
                operationsHelper.recordEnd(context, objectType, started, ex);
                exception = processActionException(ex, NAME, value, context);
            }
            context.println((exception != null ? "Attempted to modify " : "Modified ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject of FocusType"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    // TODO updated objects?
    return input;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActionParameterValueType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)

Example 8 with ObjectReferenceType

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

the class AssignExecutor method createDelta.

private ObjectDelta createDelta(ObjectType objectType, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles) throws ScriptExecutionException {
    List<AssignmentType> assignments = new ArrayList<>();
    if (roles != null) {
        for (ObjectReferenceType roleRef : roles) {
            AssignmentType assignmentType = new AssignmentType();
            assignmentType.setTargetRef(roleRef);
            assignments.add(assignmentType);
        }
    }
    if (resources != null) {
        for (ObjectReferenceType resourceRef : resources) {
            AssignmentType assignmentType = new AssignmentType();
            ConstructionType constructionType = new ConstructionType();
            constructionType.setResourceRef(resourceRef);
            assignmentType.setConstruction(constructionType);
            assignments.add(assignmentType);
        }
    }
    ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(objectType.getClass(), objectType.getOid(), prismContext);
    try {
        delta.addModificationAddContainer(FocusType.F_ASSIGNMENT, assignments.toArray(new AssignmentType[0]));
    } catch (SchemaException e) {
        throw new ScriptExecutionException("Couldn't prepare modification to add resource/role assignments", e);
    }
    return delta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 9 with ObjectReferenceType

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

the class SecurityHelper method resolveGlobalSecurityPolicy.

private <F extends FocusType> SecurityPolicyType resolveGlobalSecurityPolicy(PrismObject<F> user, SystemConfigurationType systemConfiguration, Task task, OperationResult result) {
    ObjectReferenceType globalSecurityPolicyRef = systemConfiguration.getGlobalSecurityPolicyRef();
    if (globalSecurityPolicyRef != null) {
        try {
            SecurityPolicyType globalSecurityPolicyType = objectResolver.resolve(globalSecurityPolicyRef, SecurityPolicyType.class, null, "global security policy reference in system configuration", task, result);
            LOGGER.trace("Using global security policy: {}", globalSecurityPolicyType);
            postProcessSecurityPolicy(globalSecurityPolicyType, task, result);
            traceSecurityPolicy(globalSecurityPolicyType, user);
            return globalSecurityPolicyType;
        } catch (ObjectNotFoundException | SchemaException e) {
            LOGGER.error(e.getMessage(), e);
            traceSecurityPolicy(null, user);
            return null;
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)

Example 10 with ObjectReferenceType

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

the class SecurityHelper method postProcessCredentialPolicy.

private ValuePolicyType postProcessCredentialPolicy(SecurityPolicyType securityPolicyType, CredentialPolicyType credPolicy, String credShortDesc, Task task, OperationResult result) {
    ObjectReferenceType valuePolicyRef = credPolicy.getValuePolicyRef();
    if (valuePolicyRef == null) {
        return null;
    }
    ValuePolicyType valuePolicyType;
    try {
        valuePolicyType = objectResolver.resolve(valuePolicyRef, ValuePolicyType.class, null, credShortDesc + " in " + securityPolicyType, task, result);
    } catch (ObjectNotFoundException | SchemaException e) {
        LOGGER.warn("{} {} referenced from {} was not found", credShortDesc, valuePolicyRef.getOid(), securityPolicyType);
        return null;
    }
    valuePolicyRef.asReferenceValue().setObject(valuePolicyType.asPrismObject());
    return valuePolicyType;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)225 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)100 Test (org.testng.annotations.Test)79 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)78 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)77 Task (com.evolveum.midpoint.task.api.Task)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)42 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)41 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)37 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)36 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)32 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)31 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 QName (javax.xml.namespace.QName)29 ArrayList (java.util.ArrayList)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)25 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)22 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17