Search in sources :

Example 16 with PolicyViolationException

use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.

the class TestProjector method test260ModifyAccountBarbossaDrinkReplace.

/**
	 * The drink attribute is NOT tolerant. Therefore an attempt to manually change it using
	 * account primary delta should fail.
	 */
@Test
public void test260ModifyAccountBarbossaDrinkReplace() throws Exception {
    final String TEST_NAME = "test260ModifyAccountBarbossaDrinkReplace";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjector.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_BARBOSSA_OID, result);
    fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
    addModificationToContextReplaceAccountAttribute(context, ACCOUNT_HBARBOSSA_DUMMY_OID, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "Water");
    context.recompute();
    display("Input context", context);
    assertFocusModificationSanity(context);
    try {
        // WHEN
        projector.project(context, "test", task, result);
        AssertJUnit.fail("Unexpected success of projector");
    } catch (PolicyViolationException e) {
    // This is expected
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 17 with PolicyViolationException

use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.

the class TestSegregationOfDuties method test142SimpleExclusionBoth2Deprecated.

@Test
public void test142SimpleExclusionBoth2Deprecated() throws Exception {
    final String TEST_NAME = "test142SimpleExclusionBoth2Deprecated";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestSegregationOfDuties.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add((createAssignmentModification(ROLE_PIRATE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
    modifications.add((createAssignmentModification(ROLE_JUDGE_DEPRECATED_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    try {
        modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, task, result);
        AssertJUnit.fail("Expected policy violation, but it went well");
    } catch (PolicyViolationException e) {
    // This is expected
    }
    assertAssignedNoRole(USER_JACK_OID, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 18 with PolicyViolationException

use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.

the class TestRetirement method reconcileAllOrgs.

private void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = createTask("reconcileAllOrgs");
    OperationResult result = task.getResult();
    ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {

        @Override
        public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
            try {
                display("reconciling " + object);
                reconcileOrg(object.getOid(), task, parentResult);
            } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                throw new SystemException(e.getMessage(), e);
            }
            return true;
        }
    };
    display("Reconciling all orgs");
    modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 19 with PolicyViolationException

use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.

the class TestRbac method test613JackAssignRoleGovernorAsApprover.

/**
	 * Governor has maxAssignees=0 for 'approver'
	 */
@Test
public void test613JackAssignRoleGovernorAsApprover() throws Exception {
    if (!testMultiplicityConstraintsForNonDefaultRelations()) {
        return;
    }
    final String TEST_NAME = "test613JackAssignRoleGovernorAsApprover";
    TestUtil.displayTestTile(this, TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    try {
        // WHEN
        assignRole(USER_JACK_OID, ROLE_GOVERNOR_OID, SchemaConstants.ORG_APPROVER, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (PolicyViolationException e) {
        // this is expected
        display("Expected exception", e);
    }
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertFailure(result);
    assertNoAssignments(USER_JACK_OID);
    assertAssignees(ROLE_GOVERNOR_OID, 1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 20 with PolicyViolationException

use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.

the class TestRbac method test632RappUnassignRoleCanibalAsOwner.

/**
	 * We are going to violate minAssignees constraint in cannibal role.
	 */
@Test
public void test632RappUnassignRoleCanibalAsOwner() throws Exception {
    if (!testMultiplicityConstraintsForNonDefaultRelations()) {
        return;
    }
    final String TEST_NAME = "test632RappUnassignRoleCanibalAsOwner";
    TestUtil.displayTestTile(this, TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assertAssignees(ROLE_CANNIBAL_OID, 2);
    assertAssignees(ROLE_CANNIBAL_OID, SchemaConstants.ORG_OWNER, 1);
    try {
        // WHEN
        TestUtil.displayWhen(TEST_NAME);
        // null namespace to test no-namespace "approver" relation
        unassignRole(USER_RAPP_OID, ROLE_CANNIBAL_OID, QNameUtil.nullNamespace(SchemaConstants.ORG_OWNER), task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (PolicyViolationException e) {
        // this is expected
        display("Expected exception", e);
    }
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertFailure(result);
    assertAssignees(ROLE_CANNIBAL_OID, 2);
    assertAssignees(ROLE_CANNIBAL_OID, SchemaConstants.ORG_OWNER, 1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)85 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)72 Task (com.evolveum.midpoint.task.api.Task)65 Test (org.testng.annotations.Test)50 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)32 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)24 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)23 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)22 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)22 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)22 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)22 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 ArrayList (java.util.ArrayList)12 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)11 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8