use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class AuditTest method test200AuditDelta.
@Test
public void test200AuditDelta() {
AuditEventRecord record = new AuditEventRecord();
record.setChannel("http://midpoint.evolveum.com/xml/ns/public/common/channels-3#import");
record.setEventIdentifier("1511974895961-0-1");
record.setEventStage(AuditEventStage.EXECUTION);
record.setEventType(AuditEventType.ADD_OBJECT);
ObjectDeltaOperation<UserType> delta = new ObjectDeltaOperation<>();
delta.setObjectDelta(prismContext.deltaFactory().object().createModificationAddReference(UserType.class, "1234", UserType.F_LINK_REF, "123"));
record.addDelta(delta);
delta = new ObjectDeltaOperation<>();
delta.setObjectDelta(prismContext.deltaFactory().object().createModificationAddReference(UserType.class, "1234", UserType.F_LINK_REF, "124"));
record.addDelta(delta);
auditService.audit(record, new NullTaskImpl(), createOperationResult());
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class AuditServiceProxy method completeRecord.
/**
* Complete the record with data that can be computed or discovered from the
* environment
*/
private void completeRecord(AuditEventRecord record, Task task, OperationResult result) {
LightweightIdentifier id = null;
if (record.getEventIdentifier() == null) {
id = lightweightIdentifierGenerator.generate();
record.setEventIdentifier(id.toString());
}
if (record.getTimestamp() == null) {
if (id == null) {
record.setTimestamp(System.currentTimeMillis());
} else {
// To be consistent with the ID
record.setTimestamp(id.getTimestamp());
}
}
if (record.getTaskIdentifier() == null && task != null) {
record.setTaskIdentifier(task.getTaskIdentifier());
}
if (record.getTaskOid() == null && task != null) {
if (task instanceof RunningTask) {
record.setTaskOid(((RunningTask) task).getRootTaskOid());
} else {
record.setTaskOid(task.getOid());
}
}
if (record.getChannel() == null && task != null) {
record.setChannel(task.getChannel());
}
if (record.getInitiatorRef() == null && task != null) {
PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
record.setInitiator(taskOwner);
}
if (record.getNodeIdentifier() == null && taskManager != null) {
record.setNodeIdentifier(taskManager.getNodeId());
}
HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
if (connInfo == null && securityContextManager != null) {
connInfo = securityContextManager.getStoredConnectionInformation();
}
if (connInfo != null) {
if (record.getSessionIdentifier() == null) {
record.setSessionIdentifier(connInfo.getSessionId());
}
if (record.getRemoteHostAddress() == null) {
record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
}
if (record.getHostIdentifier() == null) {
record.setHostIdentifier(connInfo.getLocalHostName());
}
}
if (record.getSessionIdentifier() == null && task != null) {
record.setSessionIdentifier(task.getTaskIdentifier());
}
for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
// currently this does not work as expected (retrieves all default items)
Collection<SelectorOptions<GetOperationOptions>> nameOnlyOptions = schemaService.getOperationOptionsBuilder().item(ObjectType.F_NAME).retrieve().build();
ObjectDeltaSchemaLevelUtil.NameResolver nameResolver = (objectClass, oid) -> {
if (record.getNonExistingReferencedObjects().contains(oid)) {
// save a useless getObject call plus associated warning (MID-5378)
return null;
}
if (repositoryService == null) {
LOGGER.warn("No repository, no OID resolution (for {})", oid);
return null;
}
LOGGER.warn("Unresolved object reference in delta being audited (for {}: {}) -- this might indicate " + "a performance problem, as these references are normally resolved using repository cache", objectClass.getSimpleName(), oid);
PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, nameOnlyOptions, new OperationResult(AuditServiceProxy.class.getName() + ".completeRecord.resolveName"));
return object.getName();
};
resolveNames(delta, nameResolver, prismContext);
}
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestAuditServiceImpl method testAuditSimple.
@Test
public void testAuditSimple() throws FileNotFoundException {
// GIVEN
AuditEventRecord auditRecord = new AuditEventRecord(AuditEventType.ADD_OBJECT);
Task task = taskManager.createTaskInstance();
// WHEN
auditService.audit(auditRecord, task, task.getResult());
// THEN
// Thread.sleep(2000);
System.err.println("FOOOOOOOOOOOOO");
String auditLine = parseAuditLineFromLogFile(LOG_FILENAME);
assertNotNull(auditLine);
System.out.println("Audit line:");
System.out.println(auditLine);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class AuditSearchTest method initAuditEvents.
@BeforeClass
public void initAuditEvents() throws Exception {
clearAudit();
OperationResult result = createOperationResult();
PrismObject<UserType> initiator = createUser("initiator");
initiatorOid = initiator.getOid();
PrismObject<UserType> attorney = createUser("attorney");
attorneyOid = attorney.getOid();
PrismObject<UserType> target = createUser("target");
targetOid = target.getOid();
PrismObject<? extends FocusType> targetOwner = createUser("targetOwner");
targetOwnerOid = targetOwner.getOid();
AuditEventRecord record1 = new AuditEventRecord();
// all tested records have parameter, it is used for assertions where practical
record1.setParameter("1");
record1.addPropertyValue("prop1", "val1");
record1.setTimestamp(TIMESTAMP_1);
record1.setEventType(AuditEventType.ADD_OBJECT);
record1.setMessage("record1");
record1.setOutcome(OperationResultStatus.SUCCESS);
record1.setResult("result1");
record1.setHostIdentifier("localhost");
record1.setNodeIdentifier("node1");
record1.setRemoteHostAddress("192.168.10.1");
record1.setSessionIdentifier("session-1");
record1.setTarget(target);
record1.setTargetOwner(targetOwner);
// values are not even necessary
record1.addDelta(createDelta(UserType.F_FULL_NAME));
record1.addDelta(createDelta(UserType.F_FAMILY_NAME, PolyString.fromOrig("familyNameVal")));
ObjectDeltaOperation<UserType> delta3 = createDelta(ItemPath.create(ObjectType.F_METADATA, MetadataType.F_REQUEST_TIMESTAMP), MiscUtil.asXMLGregorianCalendar(System.currentTimeMillis()));
// adding execution result to one of deltas
OperationResult opResult3 = new OperationResult("delta-op", OperationResultStatus.SUCCESS, "message");
opResult3.subresult("sub-op1").setMinor().build().setStatus(OperationResultStatus.PARTIAL_ERROR);
opResult3.subresult("sub-op2").setMinor().build().setSuccess();
opResult3.subresult("sub-op3").build().setSuccess();
delta3.setExecutionResult(opResult3);
record1.addDelta(delta3);
// just want to see two values, that's all
record1.addReferenceValue("ref1", ObjectTypeUtil.createObjectRef(targetOid, ObjectTypes.USER).asReferenceValue());
record1.addReferenceValue("ref2", ObjectTypeUtil.createObjectRef(targetOid, ObjectTypes.USER).asReferenceValue());
record1.addResourceOid(resourceOid);
record1.addResourceOid(UUID.randomUUID().toString());
record1.addResourceOid(UUID.randomUUID().toString());
record1.getCustomColumnProperty().put("foo", "foo-val");
auditService.audit(record1, NullTaskImpl.INSTANCE, result);
record1EventIdentifier = record1.getEventIdentifier();
AuditEventRecord record2 = new AuditEventRecord();
record2.setParameter("2");
record2.addPropertyValue("prop1", "val2");
record2.setTimestamp(TIMESTAMP_2);
record2.setEventType(AuditEventType.MODIFY_OBJECT);
record2.setEventStage(AuditEventStage.EXECUTION);
record2.setMessage("record2");
record2.setOutcome(OperationResultStatus.UNKNOWN);
record2.setInitiator(initiator);
record2.setHostIdentifier("127.0.0.1");
record2.setRemoteHostAddress("192.168.10.2");
// session-1 on purpose
record2.setSessionIdentifier("session-1");
record2.setAttorney(attorney);
record2.setRequestIdentifier("req-id");
record2.addDelta(createDelta(UserType.F_FULL_NAME, PolyString.fromOrig("somePolyString")));
record2.addDelta(createDelta(UserType.F_ADDITIONAL_NAME));
// These two deltas should collapse into single no-op delta + no changed items for them.
// They must have the same OID too, so they have the same resulting checksum.
record2.addDelta(createDeltaWithIgnoredPath(UserType.F_GIVEN_NAME));
record2.addDelta(createDeltaWithIgnoredPath(UserType.F_FAMILY_NAME));
record2.getCustomColumnProperty().put("foo", "foo-value-2");
record2.getCustomColumnProperty().put("bar", "bar-val");
record2.setTaskOid(UUID.randomUUID().toString());
auditService.audit(record2, NullTaskImpl.INSTANCE, result);
AuditEventRecord record3 = new AuditEventRecord();
record3.setParameter("3");
record3.addPropertyValue("prop1", "val3-1");
record3.addPropertyValue("prop1", "val3-2");
record3.addPropertyValue("prop1", "val3-3");
record3.addPropertyValue("prop2", null);
record3.setTimestamp(TIMESTAMP_3);
record3.setEventType(AuditEventType.MODIFY_OBJECT);
record3.setEventStage(AuditEventStage.EXECUTION);
record3.setMessage("RECORD THREE");
// null outcome is kinda like "unknown", but not quite, filter/GUI must handle it
record3.setChannel(CHANNEL_REST_URI);
record3.setTaskIdentifier("task-identifier");
record3.setTaskOid(taskOid);
auditService.audit(record3, NullTaskImpl.INSTANCE, result);
AuditEventRecord record4 = new AuditEventRecord();
record4.setParameter("4");
record4.setTimestamp(TIMESTAMP_4);
auditService.audit(record4, NullTaskImpl.INSTANCE, result);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class AuditDeltaOperationResultTest method createAuditRecordWithDeltas.
private void createAuditRecordWithDeltas(OperationResult result) throws SchemaException {
AuditEventRecord record = new AuditEventRecord();
ObjectDeltaOperation<UserType> delta1 = createDelta(UserType.F_FULL_NAME);
OperationResult opResult1 = new OperationResult("delta-op1", OperationResultStatus.WARNING, "warn message");
opResult1.subresult("sub-op1-1").setMinor().build().setStatus(OperationResultStatus.PARTIAL_ERROR);
opResult1.subresult("sub-op1-2").setMinor().build().setSuccess();
opResult1.subresult("sub-op1-3").build().setSuccess();
delta1.setExecutionResult(opResult1);
record.addDelta(delta1);
ObjectDeltaOperation<UserType> delta2 = createDelta(UserType.F_ADDITIONAL_NAME);
OperationResult opResult2 = new OperationResult("delta-op2", OperationResultStatus.SUCCESS, "message");
opResult2.subresult("sub-op2-1").setMinor().build().setStatus(OperationResultStatus.PARTIAL_ERROR);
opResult2.subresult("sub-op2-2").setMinor().build().setSuccess();
opResult2.subresult("sub-op2-3").build().setSuccess();
delta2.setExecutionResult(opResult2);
record.addDelta(delta2);
auditService.audit(record, NullTaskImpl.INSTANCE, result);
}
Aggregations