use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestOrgStruct method test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment.
// this test should generate a SchemaException (modifying targetRef in assignment should be prohibited)
@Test
public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment() throws Exception {
final String TEST_NAME = "test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> jack = getUser(USER_JACK_OID);
Long id = findAssignmentIdForTarget(jack, ORG_MINISTRY_OF_OFFENSE_OID);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
PrismReferenceDefinition referenceDefinition = getUserDefinition().findItemDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
ReferenceDelta referenceDelta = new ReferenceDelta(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_TARGET_REF)), referenceDefinition, prismContext);
PrismReferenceValue oldValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
PrismReferenceValue newValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
newValue.setRelation(SchemaConstants.ORG_MANAGER);
referenceDelta.addValueToDelete(oldValue);
referenceDelta.addValueToAdd(newValue);
modifications.add(referenceDelta);
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
try {
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("executeChanges should fail but it did not.");
} catch (SchemaException e) {
// ok!
} catch (Exception e) {
AssertJUnit.fail("executeChanges failed in the wrong way (expected SchemaException): " + e);
}
}
use of com.evolveum.midpoint.prism.delta.ItemDelta 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.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestSegregationOfDuties method test130SimpleExclusionBoth1.
@Test
public void test130SimpleExclusionBoth1() throws Exception {
final String TEST_NAME = "test130SimpleExclusionBoth1";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestSegregationOfDuties.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ROLE_JUDGE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
modifications.add((createAssignmentModification(ROLE_PIRATE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, task, result);
AssertJUnit.fail("Expected policy violation, but it went well");
} catch (PolicyViolationException e) {
// This is expected
}
assertAssignedNoRole(USER_JACK_OID, task, result);
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestSegregationOfDuties method test160SimpleExclusionBothBidirectional2.
@Test
public void test160SimpleExclusionBothBidirectional2() throws Exception {
final String TEST_NAME = "test160SimpleExclusionBothBidirectional2";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestSegregationOfDuties.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ROLE_JUDGE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
modifications.add((createAssignmentModification(ROLE_THIEF_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(userDelta), null, task, result);
AssertJUnit.fail("Expected policy violation, but it went well");
} catch (PolicyViolationException e) {
// This is expected
}
assertAssignedNoRole(USER_JACK_OID, task, result);
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ConfigurationExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof ConfigurationException) {
throw (ConfigurationException) ex;
} else {
throw new ConfigurationException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
case GET:
OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ConfigurationExceptionHandler.handleError." + op.name());
operationResult.addParam("shadow", shadow);
operationResult.addParam("currentOperation", op);
operationResult.addParam("exception", ex.getMessage());
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because of configuration error. Returning shadow from the repository");
shadow.setFetchResult(operationResult.createOperationResultType());
return shadow;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
LOGGER.error("Unexpected error while modifying shadow {}: {}", shadow, e.getMessage(), e);
if (ex instanceof SchemaException) {
throw ((SchemaException) ex);
} else if (ex instanceof GenericFrameworkException) {
throw ((GenericFrameworkException) ex);
} else if (ex instanceof CommunicationException) {
throw ((CommunicationException) ex);
} else if (ex instanceof ObjectNotFoundException) {
throw ((ObjectNotFoundException) ex);
} else if (ex instanceof ObjectAlreadyExistsException) {
throw ((ObjectAlreadyExistsException) ex);
} else if (ex instanceof ConfigurationException) {
throw ((ConfigurationException) ex);
}
}
parentResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Aggregations