use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestRetirement method test300RetireUserGorc.
@Test
public void test300RetireUserGorc() throws Exception {
final String TEST_NAME = "test300RetireUserGorc";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRetirement.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add(createAssignmentModification(orgCortuvHradOid, OrgType.COMPLEX_TYPE, null, null, null, false));
modifications.add(createAssignmentModification(ORG_RETIRED_OID, OrgType.COMPLEX_TYPE, null, null, null, true));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userGorcOid, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
dumpOrgTree();
dumpLdap();
PrismObject<UserType> userAfter = getAndAssertRetiredUser(USER_GORC_USERNAME);
userGorcOid = userAfter.getOid();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestUnix method test510StanDisablePosixAssocAndReconcile.
@Test
public void test510StanDisablePosixAssocAndReconcile() throws Exception {
final String TEST_NAME = "test510StanDisablePosixAssocAndReconcile";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestUnix.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userStan = findUserByUsername(USER_STAN_USERNAME);
Long rangersAssignmentId = null;
for (AssignmentType assignment : userStan.asObjectable().getAssignment()) {
if (assignment.getTargetRef() != null && roleRangersOid.equals(assignment.getTargetRef().getOid())) {
rangersAssignmentId = assignment.getId();
}
}
assertNotNull("No 'rangers' assignment for stan", rangersAssignmentId);
final List<ItemDelta<?, ?>> itemDeltas = DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT, rangersAssignmentId, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asItemDeltas();
repositoryService.modifyObject(UserType.class, userStan.getOid(), itemDeltas, result);
// WHEN
TestUtil.displayWhen(TEST_NAME);
reconcileUser(userStan.getOid(), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = findUserByUsername(USER_STAN_USERNAME);
assertNotNull("No stan user", userAfter);
display("User after", userAfter);
assertUserStan(userAfter);
String accountOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
display("Shadow (model)", shadow);
assertBasicAccount(shadow);
assertNoGroupAssociation(shadow, groupRangersOid);
assertGroupAssociation(shadow, groupMonkeyIslandOid);
display("Rangers", getShadowModel(groupRangersOid));
/*
Actually, stan is technically still a member of Rangers.
(Although not shown to midPoint, as he is no longer "posixAccount".)
This can be avoided by setting the associations as non-tolerant.
attributes:
dn:
cn=rangers,ou=unixgroups,dc=example,dc=com
cn: [ rangers ]
gidNumber: 998
memberUid: [ stan ]
entryUUID: 8647ca7a-2b7a-4948-9e9b-a1657028fbfe
*/
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestModelCrudService method test119ModifyUserDeleteAccount.
@Test
public void test119ModifyUserDeleteAccount() throws Exception {
TestUtil.displayTestTile(this, "test119ModifyUserDeleteAccount");
// GIVEN
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test119ModifyUserDeleteAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
account.setOid(accountOid);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
modifications.add(accountDelta);
// WHEN
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
// THEN
// 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", 0, userJackType.getLinkRef().size());
// Check is shadow is gone
try {
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
AssertJUnit.fail("Shadow " + accountOid + " still exists");
} catch (ObjectNotFoundException e) {
// This is OK
}
// Check if dummy resource account is gone
assertNoDummyAccount("jack");
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestSecurityBasic method test278AutzJackAssignRequestableRolesWithOrgRefTweakedDelta.
/**
* MID-3136
*/
@Test
public void test278AutzJackAssignRequestableRolesWithOrgRefTweakedDelta() throws Exception {
final String TEST_NAME = "test278AutzJackAssignRequestableRolesWithOrgRefTweakedDelta";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_ASSIGN_REQUESTABLE_ROLES_OID);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
assertReadAllow(NUMBER_OF_ALL_USERS + 1);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
PrismObject<UserType> user = getUser(USER_JACK_OID);
assertAssignments(user, 2);
assertAssignedRole(user, ROLE_ASSIGN_REQUESTABLE_ROLES_OID);
assertAllow("assign business role to jack", (task, result) -> assignPrametricRole(USER_JACK_OID, ROLE_BUSINESS_1_OID, ORG_MINISTRY_OF_RUM_OID, null, task, result));
user = getUser(USER_JACK_OID);
assertAssignments(user, 3);
assertAssignedRole(user, ROLE_BUSINESS_1_OID);
assertDeny("assign application role to jack", (task, result) -> {
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
ContainerDelta<AssignmentType> assignmentDelta1 = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
assignmentDelta1.addValueToAdd(cval);
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(ROLE_BUSINESS_2_OID);
targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
targetRef.getValue().setRelation(null);
cval.setId(123L);
ContainerDelta<AssignmentType> assignmentDelta = assignmentDelta1;
modifications.add(assignmentDelta);
ObjectDelta<UserType> userDelta1 = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
ObjectDelta<UserType> userDelta = userDelta1;
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
modelService.executeChanges(deltas, null, task, result);
});
assertAllow("unassign business role from jack", (task, result) -> unassignPrametricRole(USER_JACK_OID, ROLE_BUSINESS_1_OID, ORG_MINISTRY_OF_RUM_OID, null, task, result));
user = getUser(USER_JACK_OID);
display("user after (expected 2 assignments)", user);
assertAssignments(user, 2);
RoleSelectionSpecification spec = getAssignableRoleSpecification(getUser(USER_JACK_OID));
assertRoleTypes(spec);
assertFilter(spec.getFilter(), TypeFilter.class);
assertGlobalStateUntouched();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestScriptingBasic method test510GeneratePasswords.
@Test
public void test510GeneratePasswords() throws Exception {
final String TEST_NAME = "test510GeneratePasswords";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
PrismProperty<ScriptingExpressionType> expression = parseAnyData(GENERATE_PASSWORDS_FILE);
addObject(PASSWORD_POLICY_GLOBAL_FILE);
List<ItemDelta<?, ?>> itemDeltas = DeltaBuilder.deltaFor(SecurityPolicyType.class, prismContext).item(SecurityPolicyType.F_CREDENTIALS, CredentialsPolicyType.F_PASSWORD, PasswordCredentialsPolicyType.F_PASSWORD_POLICY_REF).add(new PrismReferenceValue(PASSWORD_POLICY_GLOBAL_OID)).asItemDeltas();
modifySystemObjectInRepo(SecurityPolicyType.class, SECURITY_POLICY_OID, itemDeltas, result);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
TestUtil.assertSuccess(result);
PipelineData data = output.getFinalOutput();
assertEquals("Unexpected # of items in output", 5, data.getData().size());
Set<String> realOids = new HashSet<>();
for (PipelineItem item : data.getData()) {
PrismValue value = item.getValue();
UserType user = ((PrismObjectValue<UserType>) value).asObjectable();
ProtectedStringType passwordValue = user.getCredentials().getPassword().getValue();
assertNotNull("clearValue for password not set", passwordValue.getClearValue());
realOids.add(user.getOid());
}
assertEquals("Unexpected OIDs in output", Sets.newHashSet(Arrays.asList(USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids);
}
Aggregations