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();
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations