Search in sources :

Example 36 with AssignmentType

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

the class AbstractModelIntegrationTest method unassignAllRoles.

protected void unassignAllRoles(String userOid, boolean useRawPlusRecompute) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class + ".unassignAllRoles");
    OperationResult result = task.getResult();
    PrismObject<UserType> user = modelService.getObject(UserType.class, userOid, null, task, result);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    for (AssignmentType assignment : user.asObjectable().getAssignment()) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null) {
            if (targetRef.getType().equals(RoleType.COMPLEX_TYPE)) {
                ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
                PrismContainerValue<AssignmentType> cval = new PrismContainerValue<>(prismContext);
                cval.setId(assignment.getId());
                assignmentDelta.addValueToDelete(cval);
                modifications.add(assignmentDelta);
            }
        }
    }
    if (modifications.isEmpty()) {
        return;
    }
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, useRawPlusRecompute ? ModelExecuteOptions.createRaw() : null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (useRawPlusRecompute) {
        recomputeUser(userOid, task, result);
        result.computeStatus();
        TestUtil.assertSuccess(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) 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) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 37 with AssignmentType

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

the class AbstractModelIntegrationTest method createAssignmentModification.

protected ContainerDelta<AssignmentType> createAssignmentModification(String roleOid, QName refType, QName relation, Consumer<AssignmentType> modificationBlock, boolean add) throws SchemaException {
    ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
    PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
    if (add) {
        assignmentDelta.addValueToAdd(cval);
    } else {
        assignmentDelta.addValueToDelete(cval);
    }
    PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
    targetRef.getValue().setOid(roleOid);
    targetRef.getValue().setTargetType(refType);
    targetRef.getValue().setRelation(relation);
    if (modificationBlock != null) {
        modificationBlock.accept(cval.asContainerable());
    }
    return assignmentDelta;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 38 with AssignmentType

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

the class AbstractModelIntegrationTest method assertAssignedAccount.

protected AssignmentType assertAssignedAccount(PrismObject<UserType> user, String resourceOid) throws ObjectNotFoundException, SchemaException {
    UserType userType = user.asObjectable();
    for (AssignmentType assignmentType : userType.getAssignment()) {
        ConstructionType construction = assignmentType.getConstruction();
        if (construction != null) {
            if (construction.getKind() != null && construction.getKind() != ShadowKindType.ACCOUNT) {
                continue;
            }
            if (resourceOid.equals(construction.getResourceRef().getOid())) {
                return assignmentType;
            }
        }
    }
    AssertJUnit.fail(user.toString() + " does not have account assignment for resource " + resourceOid);
    // not reached
    return null;
}
Also used : ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 39 with AssignmentType

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

the class AbstractModelIntegrationTest method getUserAssignment.

protected AssignmentType getUserAssignment(String userOid, String roleOid, QName relation) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<UserType> user = getUser(userOid);
    List<AssignmentType> assignments = user.asObjectable().getAssignment();
    for (AssignmentType assignment : assignments) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null && roleOid.equals(targetRef.getOid()) && ObjectTypeUtil.relationMatches(relation, targetRef.getRelation())) {
            return assignment;
        }
    }
    return null;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 40 with AssignmentType

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

the class AbstractModelIntegrationTest method modifyRoleDeleteInducement.

protected void modifyRoleDeleteInducement(String roleOid, long inducementId, boolean reconcileAffected, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    if (task == null) {
        task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleDeleteInducement");
    }
    OperationResult result = task.getResult();
    AssignmentType inducement = new AssignmentType();
    inducement.setId(inducementId);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, roleOid, RoleType.F_INDUCEMENT, prismContext, inducement);
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setReconcileAffected(reconcileAffected);
    modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), options, task, result);
    result.computeStatus();
    if (reconcileAffected) {
        TestUtil.assertInProgressOrSuccess(result);
    } else {
        TestUtil.assertSuccess(result);
    }
}
Also used : AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)115 Test (org.testng.annotations.Test)55 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)53 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)47 Task (com.evolveum.midpoint.task.api.Task)44 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)41 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)23 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)16 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)16 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)14 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 ArrayList (java.util.ArrayList)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)12 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)10