Search in sources :

Example 16 with AssignmentType

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

the class PageRegistrationConfirmation method assignAdditionalRoleIfPresent.

private OperationResult assignAdditionalRoleIfPresent(String userOid, NonceType nonceType, OperationResult result) {
    //		SecurityContextHolder.getContext().setAuthentication(token);
    return runPrivileged(() -> {
        List<ItemDelta> userDeltas = new ArrayList<>();
        if (nonceType.getName() != null) {
            Task task = createAnonymousTask(OPERATION_FINISH_REGISTRATION);
            ObjectDelta<UserType> assignRoleDelta = null;
            try {
                AssignmentType assignment = new AssignmentType();
                assignment.setTargetRef(ObjectTypeUtil.createObjectRef(nonceType.getName(), ObjectTypes.ABSTRACT_ROLE));
                getPrismContext().adopt(assignment);
                userDeltas.add((ItemDelta) ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
                assignRoleDelta = ObjectDelta.createModifyDelta(userOid, userDeltas, UserType.class, getPrismContext());
                assignRoleDelta.setPrismContext(getPrismContext());
            } catch (SchemaException e) {
                result.recordFatalError("Could not create delta");
                return result;
            }
            WebModelServiceUtils.save(assignRoleDelta, result, task, PageRegistrationConfirmation.this);
            result.computeStatusIfUnknown();
        }
        return result;
    });
//		SecurityContextHolder.getContext().setAuthentication(null);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 17 with AssignmentType

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

the class PageRegistrationConfirmation method assignDefaultRoles.

private OperationResult assignDefaultRoles(final String userOid) {
    List<ContainerDelta<AssignmentType>> assignments = new ArrayList<>();
    for (ObjectReferenceType defaultRole : getSelfRegistrationConfiguration().getDefaultRoles()) {
        AssignmentType assignment = new AssignmentType();
        assignment.setTargetRef(defaultRole);
        try {
            getPrismContext().adopt(assignment);
            assignments.add(ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
        } catch (SchemaException e) {
        //nothing to do
        }
    }
    final ObjectDelta<UserType> delta = ObjectDelta.createModifyDelta(userOid, assignments, UserType.class, getPrismContext());
    return runPrivileged(new Producer<OperationResult>() {

        @Override
        public OperationResult run() {
            OperationResult result = new OperationResult(OPERATION_ASSIGN_DEFAULT_ROLES);
            Task task = createAnonymousTask(OPERATION_ASSIGN_DEFAULT_ROLES);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
            result.computeStatusIfUnknown();
            return result;
        }
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) Task(com.evolveum.midpoint.task.api.Task) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 18 with AssignmentType

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

the class MidPointAsserts method assertAssignments.

public static <F extends FocusType> void assertAssignments(PrismObject<F> user, Class expectedType, int expectedNumber) {
    F userType = user.asObjectable();
    int actualAssignments = 0;
    List<AssignmentType> assignments = userType.getAssignment();
    for (AssignmentType assignment : assignments) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null) {
            QName type = targetRef.getType();
            if (type != null) {
                Class<? extends ObjectType> assignmentTargetClass = ObjectTypes.getObjectTypeFromTypeQName(type).getClassDefinition();
                if (expectedType.isAssignableFrom(assignmentTargetClass)) {
                    actualAssignments++;
                }
            }
        }
    }
    assertEquals("Unexepected number of assignments of type " + expectedType + " in " + user + ": " + userType.getAssignment(), expectedNumber, actualAssignments);
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 19 with AssignmentType

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

the class MidPointAsserts method assertAssignedResource.

public static <F extends FocusType> void assertAssignedResource(PrismObject<F> user, String resourceOid) {
    F userType = user.asObjectable();
    for (AssignmentType assignmentType : userType.getAssignment()) {
        if (assignmentType.getConstruction() == null) {
            continue;
        }
        ObjectReferenceType targetRef = assignmentType.getConstruction().getResourceRef();
        if (targetRef != null) {
            if (resourceOid.equals(targetRef.getOid())) {
                return;
            }
        }
    }
    AssertJUnit.fail(user + " does NOT have assigned resource " + resourceOid + " while expecting it");
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 20 with AssignmentType

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

the class MidPointAsserts method assertAssigned.

public static <F extends FocusType> AssignmentType assertAssigned(PrismObject<F> user, String targetOid, QName refType) {
    F userType = user.asObjectable();
    for (AssignmentType assignmentType : userType.getAssignment()) {
        ObjectReferenceType targetRef = assignmentType.getTargetRef();
        if (targetRef != null) {
            if (refType.equals(targetRef.getType())) {
                if (targetOid.equals(targetRef.getOid())) {
                    return assignmentType;
                }
            }
        }
    }
    AssertJUnit.fail(user + " does not have assigned " + refType.getLocalPart() + " " + targetOid);
    // not reachable
    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)

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