Search in sources :

Example 1 with MAuditEventRecord

use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.

the class AuditTest method test110AuditSecond.

@Test
public void test110AuditSecond() throws QueryException {
    OperationResult result = createOperationResult();
    when();
    AuditEventRecord record = new AuditEventRecord();
    record.addPropertyValue("prop", "val");
    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(2, 1);
    System.out.println("Record loaded:\n" + loaded);
    assertThat(loaded.properties).describedAs("# of properties").hasSize(1);
    assertThat(loaded.properties.get("prop")).withFailMessage("Wrong prop values").containsExactlyInAnyOrder("val");
    // not initialized if nothing is there, so it's null (meaning empty)
    assertThat(loaded.refValues).describedAs("# of references").isNullOrEmpty();
}
Also used : MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) QAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl) Test(org.testng.annotations.Test)

Example 2 with MAuditEventRecord

use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.

the class AuditTest method getAuditEventRecord.

private MAuditEventRecord getAuditEventRecord(int expectedCount, int index) throws QueryException {
    // "create" does not actually create a new audit service, but returns the existing one
    SqlRepoContext sqlRepoContext = auditServiceFactory.createAuditService().getSqlRepoContext();
    SqlQueryContext<AuditEventRecordType, QAuditEventRecord, MAuditEventRecord> context = AuditSqlQueryContext.from(AuditEventRecordType.class, sqlRepoContext);
    QAuditEventRecord aer = context.root();
    context.sqlQuery().orderBy(aer.id.asc());
    try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
        PageOf<MAuditEventRecord> result = context.executeQuery(jdbcSession).map(t -> t.get(aer));
        assertThat(result).hasSize(expectedCount);
        return result.get(index);
    }
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) QAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord)

Example 3 with MAuditEventRecord

use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.

the class QAuditEventRecordMapping method toRowObject.

public MAuditEventRecord toRowObject(AuditEventRecordType 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(AuditEventStage.fromSchemaValue(record.getEventStage())));
    bean.eventType = MiscUtil.enumOrdinal(RAuditEventType.from(AuditEventType.fromSchemaValue(record.getEventType())));
    bean.hostIdentifier = record.getHostIdentifier();
    ObjectReferenceType attorney = record.getAttorneyRef();
    if (attorney != null) {
        bean.attorneyName = attorney.getDescription();
        bean.attorneyOid = attorney.getOid();
    }
    ObjectReferenceType 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(OperationResultStatus.parseStatusType(record.getOutcome())));
    bean.parameter = record.getParameter();
    bean.remoteHostAddress = record.getRemoteHostAddress();
    bean.requestIdentifier = record.getRequestIdentifier();
    bean.result = record.getResult();
    bean.sessionIdentifier = record.getSessionIdentifier();
    ObjectReferenceType target = record.getTargetRef();
    if (target != null) {
        bean.targetName = target.getDescription();
        bean.targetOid = target.getOid();
        bean.targetType = targetTypeToRepoOrdinal(target);
    }
    ObjectReferenceType 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;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)

Example 4 with MAuditEventRecord

use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.

the class SqlAuditServiceImpl method auditAttempt.

private void auditAttempt(AuditEventRecordType record) {
    try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
        try {
            MAuditEventRecord auditRow = insertAuditEventRecord(jdbcSession, record);
            insertAuditDeltas(jdbcSession, auditRow, record.getDelta());
            insertChangedItemPaths(jdbcSession, auditRow);
            insertProperties(jdbcSession, auditRow.id, record.getProperty());
            insertReferences(jdbcSession, auditRow.id, record.getReference());
            insertResourceOids(jdbcSession, auditRow.id, record.getResourceOid());
            jdbcSession.commit();
        } catch (RuntimeException ex) {
            baseHelper.handleGeneralRuntimeException(ex, jdbcSession, null);
        }
    }
}
Also used : MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)

Example 5 with MAuditEventRecord

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 MAuditEventRecord insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecordType record) {
    QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
    QAuditEventRecord aer = aerMapping.defaultAlias();
    MAuditEventRecord row = aerMapping.toRowObject(record);
    SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
    Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
    for (AuditEventRecordCustomColumnPropertyType property : record.getCustomColumnProperty()) {
        String propertyName = property.getName();
        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.
    row.id = returnedId != null ? returnedId : record.getRepoId();
    return row;
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)9 QAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Test (org.testng.annotations.Test)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 NullTaskImpl (com.evolveum.midpoint.task.api.test.NullTaskImpl)2 ColumnMetadata (com.querydsl.sql.ColumnMetadata)2 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)1 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Duration (javax.xml.datatype.Duration)1