use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestAssignmentErrors method test210UserSharptoothAssignAccountBrokenGeneric.
// PARTIAL_ERROR: Unable to get object from the resource. Probably it has not been created yet because of previous unavailability of the resource.
// TODO: timeout or explicit retry
// @Test
// public void test205UserLemonheadRecovery() throws Exception {
// // GIVEN
// Task task = getTestTask();
// OperationResult result = task.getResult();
// assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
//
// dummyResource.setBreakMode(BreakMode.NONE);
// dummyAuditService.clear();
//
// // WHEN
// //not expected that it fails, instead the error in the result is expected
// modelService.recompute(UserType.class, userLemonheadOid, task, result);
//
// result.computeStatus();
//
// display(result);
// // This has to be a partial error as some changes were executed (user) and others were not (account)
// TestUtil.assertSuccess(result);
//
// // Check audit
// display("Audit", dummyAuditService);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertRecords(2);
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertTarget(userLemonheadOid);
// dummyAuditService.assertExecutionOutcome(OperationResultStatus.HANDLED_ERROR);
// dummyAuditService.assertExecutionMessage();
//
// }
@Test
public void test210UserSharptoothAssignAccountBrokenGeneric() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
PrismObject<UserType> user = createUser(USER_SHARPTOOTH_NAME, USER_SHARPTOOTH_FULLNAME);
CredentialsType credentialsType = new CredentialsType();
PasswordType passwordType = new PasswordType();
ProtectedStringType passwordPs = new ProtectedStringType();
passwordPs.setClearValue(USER_SHARPTOOTH_PASSWORD_1_CLEAR);
passwordType.setValue(passwordPs);
credentialsType.setPassword(passwordType);
user.asObjectable().setCredentials(credentialsType);
addObject(user);
userSharptoothOid = user.getOid();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(user.getOid(), RESOURCE_DUMMY_OID, null, true);
deltas.add(accountAssignmentUserDelta);
getDummyResource().setBreakMode(BreakMode.GENERIC);
dummyAuditService.clear();
try {
// WHEN
when();
// not expected that it fails, instead the error in the result is expected
modelService.executeChanges(deltas, null, task, result);
assertNotReached();
} catch (GenericConnectorException e) {
then();
displayExpectedException(e);
}
assertFailure(result);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertRecords(2);
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class, OperationResultStatus.FATAL_ERROR);
dummyAuditService.assertTarget(user.getOid());
dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
dummyAuditService.assertExecutionMessage();
// noinspection unchecked
LensContext<UserType> lastLensContext = (LensContext) profilingModelInspectorManager.getLastLensContext();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = lastLensContext.getExecutedDeltas();
display("Executed deltas", executedDeltas);
assertEquals("Unexpected number of execution deltas in context", 2, executedDeltas.size());
Iterator<ObjectDeltaOperation<? extends ObjectType>> i = executedDeltas.iterator();
ObjectDeltaOperation<? extends ObjectType> deltaop1 = i.next();
assertEquals("Unexpected result of first executed deltas", OperationResultStatus.SUCCESS, deltaop1.getExecutionResult().getStatus());
ObjectDeltaOperation<? extends ObjectType> deltaop2 = i.next();
assertEquals("Unexpected result of second executed deltas", OperationResultStatus.FATAL_ERROR, deltaop2.getExecutionResult().getStatus());
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ClockworkAuditHelper method auditEvent.
// "overallResult" covers the whole clockwork run
// while "result" is - most of the time - related to the current clockwork click
//
// We provide "result" here just for completeness - if any of the called methods would like to record to it.
<F extends ObjectType> void auditEvent(LensContext<F> context, AuditEventStage stage, XMLGregorianCalendar timestamp, boolean alwaysAudit, Task task, OperationResult result, OperationResult overallResult) {
PrismObject<? extends ObjectType> primaryObject;
ObjectDelta<? extends ObjectType> primaryDelta;
if (context.getFocusContext() != null) {
if (context.getFocusContext().getObjectOld() != null) {
primaryObject = context.getFocusContext().getObjectOld();
} else {
primaryObject = context.getFocusContext().getObjectNew();
}
primaryDelta = context.getFocusContext().getSummaryDelta();
} else {
Collection<LensProjectionContext> projectionContexts = context.getProjectionContexts();
if (projectionContexts.isEmpty()) {
throw new IllegalStateException("No focus and no projections in " + context);
}
if (projectionContexts.size() > 1) {
throw new IllegalStateException("No focus and more than one projection in " + context);
}
LensProjectionContext projection = projectionContexts.iterator().next();
if (projection.getObjectOld() != null) {
primaryObject = projection.getObjectOld();
} else {
primaryObject = projection.getObjectNew();
}
// TODO couldn't we determine primary object from object ADD delta? See e.g. TestModelServiceContract.test120.
primaryDelta = projection.getCurrentDelta();
}
AuditEventType eventType = determineEventType(primaryDelta);
AuditEventRecord auditRecord = new AuditEventRecord(eventType, stage);
auditRecord.setRequestIdentifier(context.getRequestIdentifier());
boolean recordResourceOids;
List<SystemConfigurationAuditEventRecordingPropertyType> propertiesToRecord;
ExpressionType eventRecordingExpression = null;
SystemConfigurationType config = context.getSystemConfigurationBean();
if (config != null && config.getAudit() != null && config.getAudit().getEventRecording() != null) {
SystemConfigurationAuditEventRecordingType eventRecording = config.getAudit().getEventRecording();
recordResourceOids = Boolean.TRUE.equals(eventRecording.isRecordResourceOids());
propertiesToRecord = eventRecording.getProperty();
eventRecordingExpression = eventRecording.getExpression();
} else {
recordResourceOids = false;
propertiesToRecord = emptyList();
}
if (primaryObject != null) {
auditRecord.setTarget(primaryObject);
if (recordResourceOids) {
if (primaryObject.getRealValue() instanceof FocusType) {
FocusType focus = (FocusType) primaryObject.getRealValue();
for (ObjectReferenceType shadowRef : focus.getLinkRef()) {
LensProjectionContext projectionContext = context.findProjectionContextByOid(shadowRef.getOid());
if (projectionContext != null && StringUtils.isNotBlank(projectionContext.getResourceOid())) {
auditRecord.addResourceOid(projectionContext.getResourceOid());
}
}
} else if (primaryObject.getRealValue() instanceof ShadowType) {
ObjectReferenceType resource = ((ShadowType) primaryObject.getRealValue()).getResourceRef();
if (resource != null && resource.getOid() != null) {
auditRecord.addResourceOid(resource.getOid());
}
}
}
}
auditRecord.setChannel(context.getChannel());
// This is a brutal hack -- FIXME: create some "compute in-depth preview" method on operation result
OperationResult clone = overallResult.clone(2, false);
for (OperationResult subresult : clone.getSubresults()) {
subresult.computeStatusIfUnknown();
}
clone.computeStatus();
if (stage == AuditEventStage.REQUEST) {
Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneDeltaCollection(context.getPrimaryChanges());
checkNamesArePresent(clonedDeltas, primaryObject);
auditRecord.addDeltas(clonedDeltas);
if (auditRecord.getTargetRef() == null) {
auditRecord.setTargetRef(ModelImplUtils.determineAuditTargetDeltaOps(clonedDeltas));
}
} else if (stage == AuditEventStage.EXECUTION) {
auditRecord.setOutcome(clone.getStatus());
Collection<ObjectDeltaOperation<? extends ObjectType>> unauditedExecutedDeltas = context.getUnauditedExecutedDeltas();
if (!alwaysAudit && unauditedExecutedDeltas.isEmpty()) {
// No deltas, nothing to audit in this wave
return;
}
Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneCollection(unauditedExecutedDeltas);
checkNamesArePresent(clonedDeltas, primaryObject);
auditRecord.addDeltas(clonedDeltas);
} else {
throw new IllegalStateException("Unknown audit stage " + stage);
}
if (timestamp != null) {
auditRecord.setTimestamp(XmlTypeConverter.toMillis(timestamp));
}
addRecordMessage(auditRecord, clone.getMessage());
for (SystemConfigurationAuditEventRecordingPropertyType property : propertiesToRecord) {
evaluateAuditRecordProperty(property, auditRecord, primaryObject, context, task, result);
}
if (eventRecordingExpression != null) {
// MID-6839
auditRecord = auditHelper.evaluateRecordingExpression(eventRecordingExpression, auditRecord, primaryObject, context, task, result);
}
if (auditRecord != null) {
auditHelper.audit(auditRecord, context.getNameResolver(), task, result);
}
if (stage == AuditEventStage.EXECUTION) {
// We need to clean up so these deltas will not be audited again in next wave
context.markExecutedDeltasAudited();
context.setExecutionAudited(true);
} else {
assert stage == AuditEventStage.REQUEST;
context.setRequestAudited(true);
}
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ObjectImporter method addObject.
private <T extends ObjectType> void addObject(PrismObject<T> object, boolean overwrite, ImportOptionsType importOptions, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
ObjectDelta<T> delta = DeltaFactory.Object.createAddDelta(object);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
ModelExecuteOptions modelOptions;
if (importOptions.getModelExecutionOptions() != null) {
modelOptions = ModelExecuteOptions.fromModelExecutionOptionsType(importOptions.getModelExecutionOptions());
} else {
modelOptions = ModelExecuteOptions.create(prismContext);
}
if (modelOptions.getRaw() == null) {
modelOptions.raw(true);
}
if (modelOptions.getOverwrite() == null) {
modelOptions.overwrite(overwrite);
}
if (isFalse(importOptions.isEncryptProtectedValues()) && modelOptions.getNoCrypt() == null) {
modelOptions.noCrypt(true);
}
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = modelService.executeChanges(deltas, modelOptions, task, parentResult);
String oidOfAddedObject = ObjectDeltaOperation.findFocusDeltaOidInCollection(executedDeltas);
if (oidOfAddedObject == null) {
LOGGER.warn("No OID of added object. Executed deltas:\n{}", DebugUtil.debugDump(executedDeltas));
} else {
if (object.canRepresent(ResourceType.COMPLEX_TYPE) && isTrue(importOptions.isFetchResourceSchema())) {
modelService.testResource(oidOfAddedObject, task);
}
}
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestModelServiceContract method test120AddAccount.
@Test
public void test120AddAccount() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<ShadowType> accountDelta = DeltaFactory.Object.createAddDelta(account);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
when();
Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges = executeChanges(accountDelta, null, task, result);
then();
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
accountJackOid = ObjectDeltaOperation.findProjectionDeltaOidInCollection(executeChanges);
assertNotNull("No account OID in executed deltas", accountJackOid);
// Check accountRef (should be none)
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 shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), 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);
// The user is not associated with the account
assertDummyScriptsAdd(null, accountModel, getDummyResourceType());
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(1);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
// We cannot have OID in the request. The OID is not assigned yet at that stage.
dummyAuditService.assertTarget(accountShadow.getOid(), AuditEventStage.EXECUTION);
dummyAuditService.assertExecutionSuccess();
// Check notifications
notificationManager.setDisabled(true);
// there's no password for that account
checkDummyTransportMessages(NOTIFIER_ACCOUNT_PASSWORD_NAME, 0);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
// account has no owner
checkDummyTransportMessages("simpleUserNotifier", 0);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
assertSteadyResources();
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestStrangeCases method test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict.
/**
* Attempt to add account (red) that already exists, but it is not linked.
* Account is added using linkRef with account object.
*/
@Test
public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() throws Exception {
given();
Task task = getTestTask();
OperationResult result = getTestOperationResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_RED_FILE);
// Remove the attributes. This will allow outbound mapping to take place instead.
account.removeContainer(ShadowType.F_ATTRIBUTES);
display("New account", account);
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID);
PrismReferenceValue accountRefVal = itemFactory().createReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = prismContext.deltaFactory().reference().createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(userDelta);
dummyAuditService.clear();
try {
when();
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);
AssertJUnit.fail("Unexpected executeChanges success");
} catch (ObjectAlreadyExistsException e) {
displayExpectedException(e);
}
// TODO: this is not yet expected.. there is a checking code in the ProjectionValueProcessor..
// the situation is that the account which should be created has the same ICFS_NAME as the on already existing in resource
// as the resource-dummy-red doesn't contain synchronization configuration part, we don't know the rule according to
// which to try to match newly created account and the old one, therefore it will now ended in this ProjectionValuesProcessor with the error
// this is not a trivial fix, so it has to be designed first.. (the same problem in TestAssignmentError.test222UserAssignAccountDeletedShadowRecomputeNoSync()
// //WHEN
// displayWhen();
// modelService.executeChanges(MiscUtil.createCollection(userDelta), null, task, getCheckingProgressListenerCollection(), result);
//
// // THEN
// displayThen();
// assertPartialError(result);
// end of TODO:
// Check accountRef
PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result);
display("User after", userAfter);
UserType userGuybrushType = userAfter.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userGuybrushType.getLinkRef().size());
ObjectReferenceType accountRefType = userGuybrushType.getLinkRef().get(0);
String accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood");
// Check account in dummy resource
assertDefaultDummyAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertFailure("executeChanges result", result);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecution0Deltas = dummyAuditService.getExecutionDeltas(0);
assertEquals("Wrong number of execution deltas", 0, auditExecution0Deltas.size());
dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
// TODO: enable after fixing the above mentioned problem in ProjectionValueProcessor
// // Strictly speaking, there should be just 2 records, not 3.
// // But this is a strange case, not a common one. Midpoint does two attempts.
// // We do not really mind about extra provisioning attempts.
// assertEquals("Wrong number of execution deltas", 3, auditExecution0Deltas.size());
// // SUCCESS because there is a handled error. Real error is in next audit record.
// dummyAuditService.assertExecutionOutcome(0, OperationResultStatus.SUCCESS);
//
// auditExecution0Deltas = dummyAuditService.getExecutionDeltas(1);
// assertEquals("Wrong number of execution deltas", 2, auditExecution0Deltas.size());
// dummyAuditService.assertExecutionOutcome(1, OperationResultStatus.PARTIAL_ERROR);
}
Aggregations