Search in sources :

Example 86 with AssignmentType

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

the class TestDynamicSchema method testAssignmentExtensionContainerItem.

@Test
public void testAssignmentExtensionContainerItem() throws Exception {
    System.out.println("===[ testAssignmentExtensionContainerItem ]===");
    // GIVEN
    PrismContainer<AssignmentType> assignmentExtensionContainer = parseUserAssignmentContainer();
    // WHEN
    PrismProperty<String> assignmentExtensionStringProperty = assignmentExtensionContainer.findOrCreateItem(new ItemPath(EXTENSION_STRING_TYPE_ELEMENT), PrismProperty.class);
    // THEN
    assertNotNull("stringType is null", assignmentExtensionStringProperty);
    assertNotNull("stringType has no definition", assignmentExtensionStringProperty.getDefinition());
    PrismAsserts.assertDefinition(assignmentExtensionStringProperty.getDefinition(), EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1);
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 87 with AssignmentType

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

the class ModelClientUtil method createRoleAssignment.

public static AssignmentType createRoleAssignment(String roleOid) {
    AssignmentType roleAssignment = new AssignmentType();
    ObjectReferenceType roleRef = new ObjectReferenceType();
    roleRef.setOid(roleOid);
    roleRef.setType(ModelClientUtil.getTypeQName(RoleType.class));
    roleAssignment.setTargetRef(roleRef);
    return roleAssignment;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 88 with AssignmentType

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

the class TestMultiResource method test440DavidAndGoliathAssignRoleAndCreateUserInOneStep.

@Test
public void test440DavidAndGoliathAssignRoleAndCreateUserInOneStep() throws Exception {
    final String TEST_NAME = "test440DavidAndGoliathAssignRoleAndCreateUserInOneStep";
    TestUtil.displayTestTile(TEST_NAME);
    dummyResourceGoliath.setBreakMode(BreakMode.NONE);
    dummyResourceDavid.setBreakMode(BreakMode.NONE);
    try {
        Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();
        // delete user and his roles which were added before
        PrismObject<UserType> userWorld = findUserByUsername(USER_FIELD_NAME);
        AssertJUnit.assertNotNull("User must not be null.", userWorld);
        ObjectDelta<UserType> delta = ObjectDelta.createDeleteDelta(UserType.class, userWorld.getOid(), prismContext);
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        deltas.add(delta);
        modelService.executeChanges(deltas, null, task, result);
        OperationResult deleteResult = new OperationResult("Check if user was deleted properly.");
        try {
            repositoryService.getObject(UserType.class, userWorld.getOid(), null, deleteResult);
        } catch (ObjectNotFoundException ex) {
        //this is OK, we deleted user before
        }
        // GIVEN
        assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
        PrismObject<UserType> userBefore = createUser(USER_WORLD_NAME, USER_WORLD_FULL_NAME, true);
        userBefore.asObjectable().getOrganizationalUnit().add(PrismTestUtil.createPolyStringType("stone"));
        PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
        PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
        targetRef.getValue().setOid(ROLE_FIGHT_OID);
        targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
        userBefore.findOrCreateContainer(UserType.F_ASSIGNMENT).add((PrismContainerValue) cval);
        //		userBefore.asObjectable().getAssignment().add(cval.asContainerable());
        // this should add user and at the sate time assign the role fight..->
        // the result of the operation have to be the same as in test 400
        addObject(userBefore);
        dummyAuditService.clear();
        // WHEN
        TestUtil.displayWhen(TEST_NAME);
        //        assignRole(userBefore.getOid(), ROLE_FIGHT_OID, task, result);
        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        assertDavidGoliath(userBefore.getOid(), "stone", USER_WORLD_NAME, true, true, true);
        // Check audit
        display("Audit", dummyAuditService);
    //        dummyAuditService.assertRecords(4);
    //        dummyAuditService.assertSimpleRecordSanity();
    //        dummyAuditService.assertAnyRequestDeltas();
    //        dummyAuditService.assertExecutionDeltas(0,3);
    //        dummyAuditService.asserHasDelta(0,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(0,ChangeType.ADD, ShadowType.class);
    //        dummyAuditService.assertExecutionDeltas(1,3);
    //        dummyAuditService.asserHasDelta(1,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(1,ChangeType.ADD, ShadowType.class);
    //        dummyAuditService.assertExecutionDeltas(2,2);
    //        dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, ShadowType.class);
    //        dummyAuditService.assertExecutionSuccess();
    //        
    //        // Have a closer look at the last shadow modify delta. Make sure there are no phantom changes.
    //        ObjectDeltaOperation<?> executionDeltaOp = dummyAuditService.getExecutionDelta(2, ChangeType.MODIFY, ShadowType.class);
    //        ObjectDelta<?> executionDelta = executionDeltaOp.getObjectDelta();
    //        display("Last execution delta", executionDelta);
    //        PrismAsserts.assertModifications("Phantom changes in last delta:", executionDelta, 2);
    } catch (Exception ex) {
        LOGGER.info("ex: {}", ex);
        throw ex;
    }
}
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) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractPasswordTest(com.evolveum.midpoint.model.intest.password.AbstractPasswordTest)

Example 89 with AssignmentType

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

the class AbstractModelIntegrationTest method modifyRoleAddInducementTarget.

protected void modifyRoleAddInducementTarget(String roleOid, String targetOid, boolean reconcileAffected, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    if (task == null) {
        task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleAddInducementTarget");
    }
    OperationResult result = task.getResult();
    AssignmentType inducement = new AssignmentType();
    ObjectReferenceType targetRef = new ObjectReferenceType();
    targetRef.setOid(targetOid);
    inducement.setTargetRef(targetRef);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationAddContainer(RoleType.class, roleOid, new ItemPath(new NameItemPathSegment(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 : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) 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) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 90 with AssignmentType

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

the class TestAssignmentsWithDifferentMetaroles method executeUnassignRoles123ToJack.

private void executeUnassignRoles123ToJack(String TEST_NAME, boolean immediate, boolean approve, boolean byId, boolean has1and2) throws Exception {
    PrismObject<UserType> jack = getUser(userJackOid);
    AssignmentType a1 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole21Oid) : null;
    AssignmentType a2 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole22Oid) : null;
    AssignmentType a3 = findAssignmentByTargetRequired(jack, roleRole23Oid);
    AssignmentType del1 = toDelete(a1, byId);
    AssignmentType del2 = toDelete(a2, byId);
    AssignmentType del3 = toDelete(a3, byId);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole1Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del1).asObjectDelta(userJackOid) : null;
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole2Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del2).asObjectDelta(userJackOid) : null;
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole3Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del3).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace(TEST_NAME).asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta, deleteRole3Delta);
    ObjectDelta<UserType> delta0 = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta);
    String originalDescription = getUser(userJackOid).asObjectable().getDescription();
    executeTest2(TEST_NAME, new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Arrays.asList(approve);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Arrays.asList(deleteRole3Delta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return delta0.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Arrays.asList(new ExpectedTask(roleRole23Oid, "Unassigning Role23 from jack"));
        }

        // after first step
        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> tasks = getExpectedTasks();
            return Arrays.asList(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task rootTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, TEST_NAME);
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    if (yes || !has1and2) {
                        assertNotAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
                        assertNotAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
                        assertAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
                    }
                    break;
                case 1:
                    if (yes) {
                        assertNotAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Unexpected delta number: " + number);
            }
        }

        @Override
        protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
            // ignore this way of approving
            return null;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ExpectedTask> tasks = getExpectedTasks();
            List<ApprovalInstruction> instructions = new ArrayList<>();
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)), approve, userSecurityApproverOid));
            return instructions;
        }
    }, 1, immediate);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ApprovalInstruction(com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)121 Test (org.testng.annotations.Test)61 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)55 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)42 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)41 Task (com.evolveum.midpoint.task.api.Task)39 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)21 QName (javax.xml.namespace.QName)20 PrismObject (com.evolveum.midpoint.prism.PrismObject)19 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)17 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)17 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)17 ArrayList (java.util.ArrayList)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)15 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14