use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertAuditEventRecord.
/**
* Inserts audit event record aggregate root without any subentities.
*
* @return ID of created audit event record
*/
private Long insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecord record) {
QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
QAuditEventRecord aer = aerMapping.defaultAlias();
MAuditEventRecord aerBean = aerMapping.toRowObject(record);
SQLInsertClause insert = jdbcSession.newInsert(aer).populate(aerBean);
Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
for (Entry<String, String> property : record.getCustomColumnProperty().entrySet()) {
String propertyName = property.getKey();
if (!customColumns.containsKey(propertyName)) {
throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + propertyName);
}
// Like insert.set, but that one is too parameter-type-safe for our generic usage here.
insert.columns(aer.getPath(propertyName)).values(property.getValue());
}
Long returnedId = insert.executeWithKey(aer.id);
// If returned ID is null, it was provided. If not, it fails, something went bad.
return returnedId != null ? returnedId : record.getRepoId();
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class QAuditEventRecordMapping method toRowObject.
/**
* Transforms {@link AuditEventRecord} to {@link MAuditEventRecord} without any subentities.
*/
public MAuditEventRecord toRowObject(AuditEventRecord record) {
MAuditEventRecord bean = new MAuditEventRecord();
// this better be null if we want to insert
bean.id = record.getRepoId();
bean.eventIdentifier = record.getEventIdentifier();
bean.timestamp = MiscUtil.asInstant(record.getTimestamp());
bean.channel = record.getChannel();
bean.eventStage = MiscUtil.enumOrdinal(RAuditEventStage.from(record.getEventStage()));
bean.eventType = MiscUtil.enumOrdinal(RAuditEventType.from(record.getEventType()));
bean.hostIdentifier = record.getHostIdentifier();
PrismReferenceValue attorney = record.getAttorneyRef();
if (attorney != null) {
bean.attorneyName = attorney.getDescription();
bean.attorneyOid = attorney.getOid();
}
PrismReferenceValue initiator = record.getInitiatorRef();
if (initiator != null) {
bean.initiatorName = initiator.getDescription();
bean.initiatorOid = initiator.getOid();
bean.initiatorType = targetTypeToRepoOrdinal(initiator);
}
bean.message = trim(record.getMessage(), MESSAGE);
bean.nodeIdentifier = record.getNodeIdentifier();
bean.outcome = MiscUtil.enumOrdinal(ROperationResultStatus.from(record.getOutcome()));
bean.parameter = record.getParameter();
bean.remoteHostAddress = record.getRemoteHostAddress();
bean.requestIdentifier = record.getRequestIdentifier();
bean.result = record.getResult();
bean.sessionIdentifier = record.getSessionIdentifier();
PrismReferenceValue target = record.getTargetRef();
if (target != null) {
bean.targetName = target.getDescription();
bean.targetOid = target.getOid();
bean.targetType = targetTypeToRepoOrdinal(target);
}
PrismReferenceValue targetOwner = record.getTargetOwnerRef();
if (targetOwner != null) {
bean.targetOwnerName = targetOwner.getDescription();
bean.targetOwnerOid = targetOwner.getOid();
bean.targetOwnerType = targetTypeToRepoOrdinal(targetOwner);
}
bean.taskIdentifier = record.getTaskIdentifier();
bean.taskOid = record.getTaskOid();
return bean;
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class CleanupTest method testAuditCleanupMaxAge.
@Test
public void testAuditCleanupMaxAge() throws Exception {
// GIVEN
prepareAuditEventRecords();
// WHEN
Calendar calendar = create_2013_07_12_12_00_Calendar();
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.add(Calendar.MINUTE, 1);
final long NOW = System.currentTimeMillis();
CleanupPolicyType policy = createPolicy(calendar, NOW);
OperationResult result = new OperationResult("Cleanup audit");
auditService.cleanupAudit(policy, result);
result.recomputeStatus();
then();
AssertJUnit.assertTrue(result.isSuccess());
MAuditEventRecord record = assertAndReturnAuditEventRecord(1);
Date finished = Date.from(record.timestamp);
Date mark = new Date(NOW);
Duration duration = policy.getMaxAge();
duration.addTo(mark);
AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class AuditTest method test100AuditSimple.
@Test
public void test100AuditSimple() throws QueryException {
OperationResult result = createOperationResult();
when();
AuditEventRecord record = new AuditEventRecord();
record.addPropertyValue("prop1", "val1.1");
record.addPropertyValue("prop1", "val1.2");
record.addPropertyValue("prop2", "val2");
record.addPropertyValue("prop3", null);
AuditReferenceValue refVal1_1 = new AuditReferenceValue("oid1.1", UserType.COMPLEX_TYPE, poly("user1.1"));
AuditReferenceValue refVal1_2 = new AuditReferenceValue("oid1.2", RoleType.COMPLEX_TYPE, poly("role1.2"));
AuditReferenceValue refVal2 = new AuditReferenceValue("oid2", null, poly("object2"));
AuditReferenceValue refVal3 = new AuditReferenceValue();
record.addReferenceValue("ref1", refVal1_1);
record.addReferenceValue("ref1", refVal1_2);
record.addReferenceValue("ref2", refVal2);
record.addReferenceValue("ref3", refVal3);
logger.info("Adding audit record {}", record);
auditService.audit(record, new NullTaskImpl(), result);
then();
System.out.println("Record written:\n" + record.debugDump());
System.out.println("Repo ID: " + record.getRepoId());
MAuditEventRecord loaded = getAuditEventRecord(1, 0);
System.out.println("Record loaded:\n" + loaded);
assertThat(loaded.properties).withFailMessage("Wrong # of properties").hasSize(3);
assertThat(loaded.properties.get("prop1")).describedAs("prop1 values").containsExactlyInAnyOrder("val1.1", "val1.2");
assertThat(loaded.properties.get("prop2")).describedAs("prop2 values").containsExactlyInAnyOrder("val2");
assertThat(loaded.properties.get("prop3")).describedAs("prop3 values").containsExactlyInAnyOrder((String) null);
assertThat(loaded.refValues).withFailMessage("Wrong # of references").hasSize(3);
assertThat(loaded.refValues.get("ref1")).describedAs("ref1 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal1_1, refVal1_2);
assertThat(loaded.refValues.get("ref2")).describedAs("ref2 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal2);
assertThat(loaded.refValues.get("ref3")).describedAs("ref3 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal3);
}
Aggregations