Search in sources :

Example 41 with PolicyViolationException

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

the class TestModelServiceContract method test180ModifyUserAddAccountFullEnforcement.

@Test
public void test180ModifyUserAddAccountFullEnforcement() throws Exception {
    final String TEST_NAME = "test180ModifyUserAddAccountFullEnforcement";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.FULL);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    try {
        // WHEN
        modelService.executeChanges(deltas, null, task, result);
        AssertJUnit.fail("Unexpected executeChanges success");
    } catch (PolicyViolationException e) {
        // This is expected
        display("Expected exception", e);
    }
    // THEN
    result.computeStatus();
    TestUtil.assertFailure("executeChanges result", result);
    assertShadowFetchOperationCountIncrement(0);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertUserJack(userJack, "Jack Sparrow", "Jack", "Sparrow");
    // Check accountRef
    assertUserNoAccountRefs(userJack);
    // Check that shadow was not created
    assertNoShadow(accountJackOid);
    // Check that dummy resource account was not created
    assertNoDummyAccount("jack");
    assertNoProvisioningScripts();
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(0, 0);
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
    dummyAuditService.assertTarget(USER_JACK_OID);
    assertScriptCompileIncrement(0);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 42 with PolicyViolationException

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

the class TestMultiResource method test121JackTryDeleteAccount.

/**
	 * Try to delete Jack's default dummy account. As other provisioned accounts depends on it the
	 * operation should fail.
	 */
@Test
public void test121JackTryDeleteAccount() throws Exception {
    final String TEST_NAME = "test121JackTryDeleteAccount";
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    getDummyResource().resetBreakMode();
    // Clean up user
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    String accountJackDummyOid = getLinkRefOid(userJack, RESOURCE_DUMMY_OID);
    ObjectDelta<ShadowType> accountDelta = ObjectDelta.createDeleteDelta(ShadowType.class, accountJackDummyOid, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
    try {
        // WHEN
        modelService.executeChanges(deltas, null, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (PolicyViolationException e) {
        // This is expected
        display("Expected exception", e);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) 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 43 with PolicyViolationException

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

the class TestMultiResource method test372UnlinkAccountDummy.

/**
     * The account cannot be unlinked because there is strict dependency on it (from lavender resource).
     */
@Test
public void test372UnlinkAccountDummy() throws Exception {
    final String TEST_NAME = "test372UnlinkAccountDummy";
    TestUtil.displayTestTile(TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectDelta<UserType> userDelta = createModifyUserUnlinkAccount(USER_JACK_OID, getDummyResourceObject());
    // WHEN
    try {
        TestUtil.displayWhen(TEST_NAME);
        modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, 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);
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    assertAccount(user, RESOURCE_DUMMY_OID);
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) 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 44 with PolicyViolationException

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

the class TestMultiResource method test370DeleteAccountDummy.

/**
     * The account cannot be deleted because there is strict dependency on it (from lavender resource).
     */
@Test
public void test370DeleteAccountDummy() throws Exception {
    final String TEST_NAME = "test370DeleteAccountDummy";
    TestUtil.displayTestTile(TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectDelta<UserType> userDelta = createModifyUserDeleteAccount(USER_JACK_OID, getDummyResourceObject());
    // WHEN
    try {
        TestUtil.displayWhen(TEST_NAME);
        modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, 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);
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    assertAccount(user, RESOURCE_DUMMY_OID);
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) 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 45 with PolicyViolationException

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

the class TestMultiResource method test250JackAssignDummyLavender.

/**
	 * Lavender resource has a strict dependency. The provisioning should fail.
	 */
@Test
public void test250JackAssignDummyLavender() throws Exception {
    final String TEST_NAME = "test250JackAssignDummyLavender";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    // Clean up user
    modifyUserReplace(USER_JACK_OID, UserType.F_ORGANIZATIONAL_UNIT, task, result);
    try {
        // WHEN
        assignAccount(USER_JACK_OID, RESOURCE_DUMMY_LAVENDER_OID, null, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (PolicyViolationException e) {
    // this is expected
    }
    // THEN
    result.computeStatus();
    TestUtil.assertFailure(result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertLinks(userJack, 0);
    assertAssignments(userJack, 0);
    assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
    assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractPasswordTest(com.evolveum.midpoint.model.intest.password.AbstractPasswordTest)

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