use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method unassignAllRoles.
protected void unassignAllRoles(String userOid, boolean useRawPlusRecompute) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class + ".unassignAllRoles");
OperationResult result = task.getResult();
PrismObject<UserType> user = modelService.getObject(UserType.class, userOid, null, task, result);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
for (AssignmentType assignment : user.asObjectable().getAssignment()) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef != null) {
if (targetRef.getType().equals(RoleType.COMPLEX_TYPE)) {
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<>(prismContext);
cval.setId(assignment.getId());
assignmentDelta.addValueToDelete(cval);
modifications.add(assignmentDelta);
}
}
}
if (modifications.isEmpty()) {
return;
}
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
modelService.executeChanges(deltas, useRawPlusRecompute ? ModelExecuteOptions.createRaw() : null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
if (useRawPlusRecompute) {
recomputeUser(userOid, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.
the class TestModelServiceContract method test200AddUserBlackbeardWithAccount.
@Test
public void test200AddUserBlackbeardWithAccount() throws Exception {
final String TEST_NAME = "test200AddUserBlackbeardWithAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
// Use custom channel to trigger a special outbound mapping
task.setChannel("http://pirates.net/avast");
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_DIR, "user-blackbeard-account-dummy.xml"));
ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(0);
PrismObject<UserType> userBlackbeard = modelService.getObject(UserType.class, USER_BLACKBEARD_OID, null, task, result);
UserType userBlackbeardType = userBlackbeard.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userBlackbeardType.getLinkRef().size());
ObjectReferenceType accountRefType = userBlackbeardType.getLinkRef().get(0);
String accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
assertEncryptedUserPassword(userBlackbeard, "QueenAnne");
assertPasswordMetadata(userBlackbeard, true, startTime, endTime, USER_ADMINISTRATOR_OID, "http://pirates.net/avast");
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, "blackbeard");
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountOid, "blackbeard", "Edward Teach");
assertEnableTimestampShadow(accountModel, startTime, endTime);
// Check account in dummy resource
assertDefaultDummyAccount("blackbeard", "Edward Teach", true);
DummyAccount dummyAccount = getDummyAccount(null, "blackbeard");
assertEquals("Wrong loot", (Integer) 10000, dummyAccount.getAttributeValue("loot", Integer.class));
assertDummyScriptsAdd(userBlackbeard, accountModel, getDummyResourceType());
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertRecords(2);
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(0, 3);
dummyAuditService.assertHasDelta(0, ChangeType.ADD, UserType.class);
dummyAuditService.assertHasDelta(0, ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(0, ChangeType.ADD, ShadowType.class);
// this one was redundant
// dummyAuditService.assertExecutionDeltas(1, 1);
// dummyAuditService.assertHasDelta(1, ChangeType.MODIFY, UserType.class);
// raw operation, no target
// dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
// Check notifications
notificationManager.setDisabled(true);
checkDummyTransportMessages("accountPasswordNotifier", 1);
checkDummyTransportMessages("userPasswordNotifier", 1);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 0);
checkDummyTransportMessages("simpleUserNotifier", 1);
checkDummyTransportMessages("simpleUserNotifier-ADD", 1);
checkDummyTransportMessages("simpleUserNotifier-DELETE", 0);
assertSteadyResources();
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.
the class TestModelServiceContract method test190ModifyUserJackAssignAccountAndModify.
/**
* We try to both assign an account and modify that account in one operation.
* Some changes should be reflected to account (e.g. weapon) as the mapping is weak, other should be
* overridded (e.g. fullname) as the mapping is strong.
*/
@Test
public void test190ModifyUserJackAssignAccountAndModify() throws Exception {
TestUtil.displayTestTile(this, "test190ModifyUserJackAssignAccountAndModify");
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test190ModifyUserJackAssignAccountAndModify");
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
ShadowDiscriminatorObjectDelta<ShadowType> accountDelta = ShadowDiscriminatorObjectDelta.createModificationReplaceProperty(ShadowType.class, RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null, dummyResourceCtl.getAttributeFullnamePath(), prismContext, "Cpt. Jack Sparrow");
accountDelta.addModificationAddProperty(dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "smell");
deltas.add(accountDelta);
deltas.add(accountAssignmentUserDelta);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(0);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
accountJackOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
assertEnableTimestampShadow(accountModel, startTime, endTime);
// Check account in dummy resource
assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "smell");
assertNull("Unexpected loot", dummyAccount.getAttributeValue("loot", Integer.class));
assertDummyScriptsAdd(userJack, accountModel, getDummyResourceType());
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
// Check notifications
notificationManager.setDisabled(true);
checkDummyTransportMessages("accountPasswordNotifier", 1);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 0);
checkDummyTransportMessages("simpleUserNotifier", 1);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
assertScriptCompileIncrement(0);
assertSteadyResources();
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.
the class TestModelServiceContract method test182ModifyUserAddAndAssignAccountPositiveEnforcement.
@Test
public void test182ModifyUserAddAndAssignAccountPositiveEnforcement() throws Exception {
final String TEST_NAME = "test182ModifyUserAddAndAssignAccountPositiveEnforcement";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<UserType> userDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
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);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(0);
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountJackOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountJackOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountJackOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
assertEnableTimestampShadow(accountModel, startTime, endTime);
// Check account in dummy resource
assertDefaultDummyAccount("jack", "Jack Sparrow", true);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
assertDummyScriptsAdd(userJack, accountModel, getDummyResourceType());
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
assertScriptCompileIncrement(0);
assertSteadyResources();
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.
the class TestModelServiceContract method test210AddUserMorganWithAssignment.
@Test
public void test210AddUserMorganWithAssignment() throws Exception {
final String TEST_NAME = "test210AddUserMorganWithAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_DIR, "user-morgan-assignment-dummy.xml"));
ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(0);
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
AssignmentType assignmentType = assertAssignedAccount(userMorgan, RESOURCE_DUMMY_OID);
assertLinks(userMorgan, 1);
ObjectReferenceType accountRefType = userMorganType.getLinkRef().get(0);
String accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
assertCreateMetadata(userMorgan, startTime, endTime);
assertCreateMetadata(assignmentType, startTime, endTime);
assertEncryptedUserPassword(userMorgan, "rum");
assertPasswordMetadata(userMorgan, true, startTime, endTime);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, "morgan");
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountOid, "morgan", "Sir Henry Morgan");
assertEnableTimestampShadow(accountModel, startTime, endTime);
// Check account in dummy resource
assertDefaultDummyAccount("morgan", "Sir Henry Morgan", true);
assertDummyScriptsAdd(userMorgan, accountModel, getDummyResourceType());
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.ADD, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_MORGAN_OID);
dummyAuditService.assertExecutionSuccess();
// Check notifications
notificationManager.setDisabled(true);
checkDummyTransportMessages("accountPasswordNotifier", 1);
checkDummyTransportMessages("userPasswordNotifier", 1);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 0);
checkDummyTransportMessages("simpleUserNotifier", 1);
checkDummyTransportMessages("simpleUserNotifier-ADD", 1);
checkDummyTransportMessages("simpleUserNotifier-DELETE", 0);
assertSteadyResources();
}
Aggregations