use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class AccCertUpdateHelper method addObject.
//endregion
//region ================================ Model and repository operations ================================
void addObject(ObjectType objectType, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createAddDelta(objectType.asPrismObject());
Collection<ObjectDeltaOperation<? extends ObjectType>> ops;
try {
ops = modelService.executeChanges(Collections.singleton(objectDelta), ModelExecuteOptions.createRaw().setPreAuthorized(), task, result);
} catch (ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
throw new SystemException("Unexpected exception when adding object: " + e.getMessage(), e);
}
ObjectDeltaOperation odo = ops.iterator().next();
objectType.setOid(odo.getObjectDelta().getOid());
/* ALTERNATIVELY, we can go directly into the repository. (No audit there.)
String oid = repositoryService.addObject(objectType.asPrismObject(), null, result);
objectType.setOid(oid);
*/
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class PrimaryChangeProcessor method prepareProcessInstanceAuditRecord.
//endregion
//region Auditing
@Override
public AuditEventRecord prepareProcessInstanceAuditRecord(WfTask wfTask, AuditEventStage stage, Map<String, Object> variables, OperationResult result) {
AuditEventRecord auditEventRecord = baseAuditHelper.prepareProcessInstanceAuditRecord(wfTask, stage, result);
ObjectTreeDeltas<?> deltas;
try {
if (stage == REQUEST) {
deltas = wfTaskUtil.retrieveDeltasToProcess(wfTask.getTask());
} else {
deltas = wfTaskUtil.retrieveResultingDeltas(wfTask.getTask());
}
} catch (SchemaException e) {
throw new SystemException("Couldn't retrieve delta(s) from task " + wfTask.getTask(), e);
}
if (deltas != null) {
List<ObjectDelta<?>> deltaList = deltas.getDeltaList();
for (ObjectDelta delta : deltaList) {
auditEventRecord.addDelta(new ObjectDeltaOperation(delta));
}
}
return auditEventRecord;
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class RAuditEventRecord method fromRepo.
public static AuditEventRecord fromRepo(RAuditEventRecord repo, PrismContext prismContext) throws DtoTranslationException {
AuditEventRecord audit = new AuditEventRecord();
audit.setChannel(repo.getChannel());
audit.setEventIdentifier(repo.getEventIdentifier());
if (repo.getEventStage() != null) {
audit.setEventStage(repo.getEventStage().getStage());
}
if (repo.getEventType() != null) {
audit.setEventType(repo.getEventType().getType());
}
audit.setHostIdentifier(repo.getHostIdentifier());
audit.setRemoteHostAddress(repo.getRemoteHostAddress());
audit.setNodeIdentifier(repo.getNodeIdentifier());
audit.setMessage(repo.getMessage());
if (repo.getOutcome() != null) {
audit.setOutcome(repo.getOutcome().getStatus());
}
audit.setParameter(repo.getParameter());
audit.setResult(repo.getResult());
audit.setSessionIdentifier(repo.getSessionIdentifier());
audit.setTaskIdentifier(repo.getTaskIdentifier());
audit.setTaskOID(repo.getTaskOID());
if (repo.getTimestamp() != null) {
audit.setTimestamp(repo.getTimestamp().getTime());
}
List<ObjectDeltaOperation> odos = new ArrayList<>();
for (RObjectDeltaOperation rodo : repo.getDeltas()) {
try {
ObjectDeltaOperation odo = RObjectDeltaOperation.fromRepo(rodo, prismContext);
if (odo != null) {
odos.add(odo);
}
} catch (Exception ex) {
// TODO: for now thi is OK, if we cannot parse detla, just skipp
// it.. Have to be resolved later;
}
}
audit.getDeltas().addAll((Collection) odos);
for (RAuditPropertyValue rPropertyValue : repo.getPropertyValues()) {
audit.addPropertyValue(rPropertyValue.getName(), rPropertyValue.getValue());
}
for (RAuditReferenceValue rRefValue : repo.getReferenceValues()) {
audit.addReferenceValue(rRefValue.getName(), rRefValue.fromRepo());
}
audit.setRepoId(repo.getId());
return audit;
// initiator, target, targetOwner
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestActivation method test160ModifyUserJackAssignAccountKhaki.
/**
* Khaki resource has simulated activation capability.
*/
@Test
public void test160ModifyUserJackAssignAccountKhaki() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
dummyAuditService.clear();
XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
// WHEN
when();
assignAccountToUser(USER_JACK_OID, RESOURCE_DUMMY_KHAKI_OID, null, task, result);
// THEN
then();
XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertUserJack(userAfter);
String accountKhakiOid = getLiveLinkRefOid(userAfter, RESOURCE_DUMMY_KHAKI_OID);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountKhakiOid, null, result);
display("Shadow (repo)", accountShadow);
assertAccountShadowRepo(accountShadow, accountKhakiOid, "jack", resourceDummyKhakiType);
TestUtil.assertCreateTimestamp(accountShadow, start, end);
assertEnableTimestampShadow(accountShadow, start, end);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountKhakiOid, null, task, result);
display("Shadow (model)", accountModel);
assertAccountShadowModel(accountModel, accountKhakiOid, "jack", resourceDummyKhakiType);
TestUtil.assertCreateTimestamp(accountModel, start, end);
assertEnableTimestampShadow(accountModel, start, end);
// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_KHAKI_NAME, "jack", "Jack Sparrow", true);
assertDummyEnabled(RESOURCE_DUMMY_KHAKI_NAME, "jack");
TestUtil.assertModifyTimestamp(userAfter, start, end);
checkAdminStatusFor15x(userAfter, true, true, true);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
// fourth one (trigger-related) was here by mistake
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
Collection<ObjectDeltaOperation<? extends ObjectType>> executionDeltas = dummyAuditService.getExecutionDeltas();
boolean found = false;
for (ObjectDeltaOperation<? extends ObjectType> executionDelta : executionDeltas) {
ObjectDelta<? extends ObjectType> objectDelta = executionDelta.getObjectDelta();
if (objectDelta.getObjectTypeClass() == ShadowType.class) {
// Actually, there should be no F_TRIGGER delta! It was there by mistake.
// if (objectDelta.findContainerDelta(ShadowType.F_TRIGGER) != null) {
// continue;
// }
PropertyDelta<Object> enableTimestampDelta = objectDelta.findPropertyDelta(PATH_ACTIVATION_ENABLE_TIMESTAMP);
displayDumpable("Audit enableTimestamp delta", enableTimestampDelta);
assertNotNull("EnableTimestamp delta vanished from audit record, delta: " + objectDelta, enableTimestampDelta);
found = true;
}
}
assertTrue("Shadow delta not found", found);
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class TestActivation method test600AddUser1.
// attempt to simulate MID-3348 (unsuccessful for now)
@Test
public void test600AddUser1() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> user1 = prismContext.createObject(UserType.class);
prismContext.deltaFor(UserType.class).item(UserType.F_NAME).replace(new PolyString("user1")).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(resourceDummyCoral, prismContext).asPrismContainerValue()).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).<UserType>asObjectDelta(null).applyTo(user1);
ObjectDelta<UserType> addDelta = user1.createAddDelta();
// WHEN
when();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = executeChanges(addDelta, null, task, result);
// THEN
then();
user1 = getUser(ObjectDeltaOperation.findFocusDeltaOidInCollection(executedChanges));
display("User after change execution", user1);
DummyAccount dummyAccount = dummyResourceCoral.getAccountByUsername("user1");
displayDumpable("Dummy account", dummyAccount);
checkSuspendedAttribute(dummyAccount, Boolean.TRUE);
String accountOid = getSingleLinkOid(user1);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
display("Shadow: ", shadow);
// TODO check real state of the account and shadow
}
Aggregations