protected <F extends FocusType> ContainerDelta<AssignmentType> createAssignmentEmptyDeleteModification(PrismObject<F> existingFocus, String roleOid, QName relation) throws SchemaException { AssignmentType existingAssignment = findAssignment(existingFocus, roleOid, relation); return createAssignmentModification(existingAssignment.getId(), false); }
/** * Creates unassign delta by removing each assignment individually by id. */ protected <F extends FocusType> ObjectDelta<F> createUnassignAllDelta(PrismObject<F> focusBefore) throws SchemaException { Collection<ItemDelta<?,?>> modifications = new ArrayList<>(); for (AssignmentType assignmentType: focusBefore.asObjectable().getAssignment()) { modifications.add((createAssignmentModification(assignmentType.getId(), false))); } return prismContext.deltaFactory().object() .createModifyDelta(focusBefore.getOid(), modifications, focusBefore.getCompileTimeClass() ); }
private AssignmentType toDelete(AssignmentType assignment, boolean byId) { if (assignment == null) { return null; } if (!byId) { return assignment.clone(); } else { AssignmentType rv = new AssignmentType(prismContext); rv.setId(assignment.getId()); return rv; } }
private Long findAssignmentIdForTarget(PrismObject<UserType> user, String targetOid) { for (AssignmentType assignmentType : user.asObjectable().getAssignment()) { if (assignmentType.getTargetRef() != null && targetOid.equals(assignmentType.getTargetRef().getOid())) { return assignmentType.getId(); } } throw new IllegalStateException("No assignment pointing to " + targetOid + " found"); }
protected AccessCertificationCaseType checkCaseAssignmentSanity(AccessCertificationCaseType aCase, FocusType focus) { assertEquals("Wrong class for case", AccessCertificationAssignmentCaseType.class, aCase.getClass()); AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) aCase; long id = assignmentCase.getAssignment().getId(); List<AssignmentType> assignmentList; if (Boolean.TRUE.equals(assignmentCase.isIsInducement())) { assignmentList = ((AbstractRoleType) focus).getInducement(); } else { assignmentList = focus.getAssignment(); } for (AssignmentType assignment : assignmentList) { if (id == assignment.getId()) { assertEquals("Wrong assignment in certification case", assignment, assignmentCase.getAssignment()); return aCase; } } throw new AssertionError("Assignment with ID " + id + " not found among assignments of " + focus); }
@NotNull @Override public AssignmentPathSegmentType toAssignmentPathSegmentType(boolean includeAssignmentsContent) { AssignmentPathSegmentType rv = new AssignmentPathSegmentType(); AssignmentType assignment = getAssignment(evaluatedForOld); // a bit of hack, but probably ok for now if (assignment != null) { if (includeAssignmentsContent) { rv.setAssignment(assignment.clone()); } rv.setAssignmentId(assignment.getId()); } if (source != null) { rv.setSourceRef(ObjectTypeUtil.createObjectRef(source, prismContext)); rv.setSourceDisplayName(ObjectTypeUtil.getDisplayName(source)); } if (target != null) { rv.setTargetRef(ObjectTypeUtil.createObjectRef(target, prismContext)); rv.setTargetDisplayName(ObjectTypeUtil.getDisplayName(target)); } rv.setMatchingOrder(isMatchingOrder()); rv.setIsAssignment(isAssignment); return rv; }
private void assertMetaroleJaxb(RoleType roleType, boolean isObject) throws SchemaException { assertEquals("Wrong name", PrismTestUtil.createPolyStringType("Generic Metarole"), roleType.getName()); boolean found = false; for (AssignmentType inducement : roleType.getInducement()) { if (inducement.getId() == 2L) { found = true; PolicyRuleType rule = inducement.getPolicyRule(); assertNotNull("No constraints", rule.getPolicyConstraints()); assertEquals("Wrong # of assignment constraints", 1, rule.getPolicyConstraints().getAssignment().size()); assertTrue("Wrong (not empty) assignment constraints", rule.getPolicyConstraints().getAssignment().get(0).asPrismContainerValue().isEmpty()); break; } } assertTrue("Assignment number 2 was not found", found); }
@Test public void test123JackDisableAssignmentJudge() throws Exception { final String TEST_NAME = "test123JackDisableAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyAssignmentAdministrativeStatus(USER_JACK_OID, judgeAssignment.getId(), ActivationStatusType.DISABLED, task, result); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertNoDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
@Test public void test124JackEnableAssignmentJudge() throws Exception { final String TEST_NAME = "test124JackEnableAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertNoDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyAssignmentAdministrativeStatus(USER_JACK_OID, judgeAssignment.getId(), ActivationStatusType.ENABLED, task, result); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
@Test public void test122JackReplaceNullAdministrativeStatusAssignmentJudge() throws Exception { final String TEST_NAME = "test122JackReplaceNullAdministrativeStatusAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertNoDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyAssignmentAdministrativeStatus(USER_JACK_OID, judgeAssignment.getId(), null, task, result); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
@Test public void test126JackAddAdministrativeStatusAssignmentJudge() throws Exception { final String TEST_NAME = "test126JackAddAdministrativeStatusAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyObjectAddProperty(UserType.class, USER_JACK_OID, ItemPath.create(UserType.F_ASSIGNMENT, judgeAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), task, result, ActivationStatusType.ENABLED); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
@Test public void test125JackDeleteAdministrativeStatusAssignmentJudge() throws Exception { final String TEST_NAME = "test125JackDeleteAdministrativeStatusAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyObjectDeleteProperty(UserType.class, USER_JACK_OID, ItemPath.create(UserType.F_ASSIGNMENT, judgeAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), task, result, ActivationStatusType.ENABLED); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
/** * Re-enable assignment of Blue Titanic role. * MID-4236 */ @Test public void test115EnableBlueTitanicAssignment() throws Exception { final String TEST_NAME = "test115EnableBlueTitanicAssignment"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<UserType> userBefore = getUser(USER_JACK_OID); display("User before", userBefore); AssignmentType titanicAssignment = getAssignment(userBefore, ROLE_BLUE_TITANIC_OID); ItemPath assignmentStatusPath = ItemPath.create(FocusType.F_ASSIGNMENT, titanicAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS); // WHEN modifyUserReplace(USER_JACK_OID, assignmentStatusPath, task, result, ActivationStatusType.ENABLED); // THEN assertSuccess(result); PrismObject<UserType> userAfter = getUser(USER_JACK_OID); display("User after", userAfter); assertUserJack(userAfter, CAPTAIN_JACK_FULL_NAME, "Jack", "Sparrow"); assertAccountShip(userAfter, USER_JACK_FULL_NAME, ROLE_TITANIC_SHIP_VALUE, RESOURCE_DUMMY_BLUE_NAME, task); }
/** * MID-4236 */ @Test public void test152DisableCobalNeverlandAssignment() throws Exception { final String TEST_NAME = "test152DisableCobalNeverlandAssignment"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<UserType> userBefore = getUser(USER_JACK_OID); display("User before", userBefore); AssignmentType roleAssignment = getAssignment(userBefore, ROLE_COBALT_NEVERLAND_OID); ItemPath assignmentStatusPath = ItemPath.create(FocusType.F_ASSIGNMENT, roleAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS); // WHEN modifyUserReplace(USER_JACK_OID, assignmentStatusPath, task, result, ActivationStatusType.DISABLED); // THEN assertSuccess(result); PrismObject<UserType> userAfter = getUser(USER_JACK_OID); display("User after", userAfter); assertUserJack(userAfter); assertDummyAccountAttribute(RESOURCE_DUMMY_COBALT_NAME, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, USER_JACK_LOCALITY); }
/** * Disable assignment of Blue Titanic role. * The weak mapping should kick in and return black pearl back. * MID-4236 */ @Test public void test112DisableBlueTitanicAssignment() throws Exception { final String TEST_NAME = "test112DisableBlueTitanicAssignment"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<UserType> userBefore = getUser(USER_JACK_OID); display("User before", userBefore); AssignmentType titanicAssignment = getAssignment(userBefore, ROLE_BLUE_TITANIC_OID); ItemPath assignmentStatusPath = ItemPath.create(FocusType.F_ASSIGNMENT, titanicAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS); // WHEN modifyUserReplace(USER_JACK_OID, assignmentStatusPath, task, result, ActivationStatusType.DISABLED); // THEN assertSuccess(result); PrismObject<UserType> userAfter = getUser(USER_JACK_OID); display("User after", userAfter); assertUserJack(userAfter, CAPTAIN_JACK_FULL_NAME, "Jack", "Sparrow"); assertAccountShip(userAfter, USER_JACK_FULL_NAME, SHIP_BLACK_PEARL, RESOURCE_DUMMY_BLUE_NAME, task); }
@Test public void test127JackDeleteActivationAssignmentJudge() throws Exception { final String TEST_NAME = "test127JackDeleteActivationAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); ActivationType activationType = new ActivationType(); activationType.setAdministrativeStatus(ActivationStatusType.ENABLED); // WHEN TestUtil.displayWhen(TEST_NAME); modifyObjectDeleteContainer(UserType.class, USER_JACK_OID, ItemPath.create(UserType.F_ASSIGNMENT, judgeAssignment.getId(), AssignmentType.F_ACTIVATION), task, result, activationType); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); }
@Test public void test120JackDisableAssignmentJudge() throws Exception { final String TEST_NAME = "test120JackDisableAssignmentJudge"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ActivationType activationType = new ActivationType(); activationType.setAdministrativeStatus(ActivationStatusType.ENABLED); assignRole(USER_JACK_OID, ROLE_BIG_JUDGE_OID, activationType, task, result); assertDummyAccount(null, USER_JACK_USERNAME); assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); // WHEN TestUtil.displayWhen(TEST_NAME); modifyAssignmentAdministrativeStatus(USER_JACK_OID, judgeAssignment.getId(), ActivationStatusType.DISABLED, task, result); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertNoDummyAccount(null, USER_JACK_USERNAME); assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_JACK_USERNAME, USER_JACK_FULL_NAME, false); assert11xUserOk(user); }
@Test public void test810ModifyAssignmentOfRole27() throws Exception { final String TEST_NAME = "test810ModifyAssignmentOfRole27"; TestUtil.displayTestTitle(this, TEST_NAME); login(userAdministrator); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); // WHEN displayWhen(TEST_NAME); PrismObject<UserType> jackBefore = getUser(userJackOid); AssignmentType assignmentBefore = findAssignmentByTargetRequired(jackBefore, roleRole27Oid); ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class) .item(UserType.F_ASSIGNMENT, assignmentBefore.getId(), AssignmentType.F_DESCRIPTION) .replace("new description") .asObjectDeltaCast(userJackOid); executeChanges(delta, null, task, result); // should proceed without approvals (only 1 of the items is present) // THEN displayThen(TEST_NAME); PrismObject<UserType> jack = getUser(userJackOid); display("jack", jack); AssignmentType assignment = findAssignmentByTargetRequired(jack, roleRole27Oid); assertEquals("Wrong description", "new description", assignment.getDescription()); }
@Test public void test129JackAssignmentJudgeValidToSetValid() throws Exception { final String TEST_NAME = "test129JackAssignmentJudgeValidToSetValid"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assertNoDummyAccount(null, USER_JACK_USERNAME); AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID); XMLGregorianCalendar validTo = clock.currentTimeXMLGregorianCalendar(); validTo.add(XmlTypeConverter.createDuration(60*60*1000)); // one hour ahead // WHEN TestUtil.displayWhen(TEST_NAME); modifyObjectReplaceProperty(UserType.class, USER_JACK_OID, ItemPath.create(UserType.F_ASSIGNMENT, judgeAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO), task, result, validTo); // THEN TestUtil.displayThen(TEST_NAME); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User after", user); assertDummyAccount(null, USER_JACK_USERNAME); assert11xUserOk(user); // CLEANUP unassignAllRoles(USER_JACK_OID); assertNoDummyAccount(null, USER_JACK_USERNAME); }
private void assertJaxb(AccessCertificationCaseType aCase) throws SchemaException { PrismAsserts.assertRefEquivalent("Wrong objectRef", getPrismContext().itemFactory().createReferenceValue("ee53eba7-5c16-4c16-ad15-dd6a2360ab1a", UserType.COMPLEX_TYPE), aCase.getObjectRef().asReferenceValue()); PrismAsserts.assertRefEquivalent("Wrong targetRef", getPrismContext().itemFactory().createReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE), aCase.getTargetRef().asReferenceValue()); assertTrue(aCase instanceof AccessCertificationAssignmentCaseType); AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) aCase; assertNotNull("no assignment", assignmentCase.getAssignment()); assertEquals((Long) 1L, assignmentCase.getAssignment().getId()); PrismAsserts.assertRefEquivalent("Wrong resourceRef in assignment", getPrismContext().itemFactory().createReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE), assignmentCase.getAssignment().getConstruction().getResourceRef().asReferenceValue()); assertEquals("wrong isInducement", Boolean.FALSE, assignmentCase.isIsInducement()); }