Search in sources :

Example 1 with AuditReferenceValue

use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.

the class RAuditEventRecord method toRepo.

public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
    Validate.notNull(record, "Audit event record must not be null.");
    Validate.notNull(prismContext, "Prism context must not be null.");
    RAuditEventRecord repo = new RAuditEventRecord();
    if (record.getRepoId() != null) {
        repo.setId(record.getRepoId());
    }
    repo.setChannel(record.getChannel());
    if (record.getTimestamp() != null) {
        repo.setTimestamp(new Timestamp(record.getTimestamp()));
    }
    repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
    repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
    repo.setSessionIdentifier(record.getSessionIdentifier());
    repo.setEventIdentifier(record.getEventIdentifier());
    repo.setHostIdentifier(record.getHostIdentifier());
    repo.setRemoteHostAddress(record.getRemoteHostAddress());
    repo.setNodeIdentifier(record.getNodeIdentifier());
    repo.setParameter(record.getParameter());
    repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
    if (record.getOutcome() != null) {
        repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
    }
    repo.setTaskIdentifier(record.getTaskIdentifier());
    repo.setTaskOID(record.getTaskOID());
    repo.setResult(record.getResult());
    try {
        if (record.getTarget() != null) {
            PrismReferenceValue target = record.getTarget();
            repo.setTargetName(getOrigName(target));
            repo.setTargetOid(target.getOid());
            repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
        }
        if (record.getTargetOwner() != null) {
            PrismObject targetOwner = record.getTargetOwner();
            repo.setTargetOwnerName(getOrigName(targetOwner));
            repo.setTargetOwnerOid(targetOwner.getOid());
        }
        if (record.getInitiator() != null) {
            PrismObject<UserType> initiator = record.getInitiator();
            repo.setInitiatorName(getOrigName(initiator));
            repo.setInitiatorOid(initiator.getOid());
        }
        for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
            if (delta == null) {
                continue;
            }
            ObjectDelta<?> objectDelta = delta.getObjectDelta();
            for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
                ItemPath path = itemDelta.getPath();
                if (path != null) {
                    // TODO what if empty?
                    CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
                    for (int i = 0; i < canonical.size(); i++) {
                        RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
                        repo.getChangedItems().add(changedItem);
                    }
                }
            }
            RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
            rDelta.setTransient(true);
            rDelta.setRecord(repo);
            repo.getDeltas().add(rDelta);
        }
        for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
            for (String propertyValue : propertyEntry.getValue()) {
                repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
            }
        }
        for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
            for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
                repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
            }
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    return repo;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) Timestamp(java.sql.Timestamp) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with AuditReferenceValue

use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.

the class WfTestUtil method checkWfProcessAuditRecords.

public static void checkWfProcessAuditRecords(Map<String, WorkflowResult> expectedResults, DummyAuditService dummyAuditService) {
    List<AuditEventRecord> records = dummyAuditService.getRecordsOfType(AuditEventType.WORKFLOW_PROCESS_INSTANCE);
    assertEquals("Unexpected number of workflow process instance audit records", expectedResults.size() * 2, records.size());
    for (AuditEventRecord record : records) {
        if (record.getEventStage() != AuditEventStage.EXECUTION) {
            continue;
        }
        Set<AuditReferenceValue> targetRef = record.getReferenceValues(AuditingConstants.AUDIT_TARGET);
        assertEquals("Wrong # of targetRef values in " + record.debugDump(), 1, targetRef.size());
        String oid = targetRef.iterator().next().getOid();
        assertTrue("Unexpected role to approve: " + oid, expectedResults.containsKey(oid));
        assertEquals("Unexpected result for " + oid + ": " + record.getResult(), expectedResults.get(oid), WorkflowResult.fromNiceWfAnswer(record.getResult()));
        if (expectedResults.get(oid) == WorkflowResult.APPROVED) {
            assertEquals("Wrong # of deltas in " + record.debugDump(), 1, record.getDeltas().size());
        }
    }
}
Also used : AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 3 with AuditReferenceValue

use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.

the class SqaleAuditService method insertReferences.

private void insertReferences(JdbcSession jdbcSession, MAuditEventRecord auditRow, Map<String, Set<AuditReferenceValue>> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qr = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qr);
    for (String refName : references.keySet()) {
        for (AuditReferenceValue refValue : references.get(refName)) {
            // id will be generated, but we're not interested in those here
            PolyString targetName = refValue.getTargetName();
            insertBatch.set(qr.recordId, auditRow.id).set(qr.timestamp, auditRow.timestamp).set(qr.name, refName).set(qr.targetOid, SqaleUtils.oidToUUid(refValue.getOid())).set(qr.targetType, refValue.getType() != null ? MObjectType.fromTypeQName(refValue.getType()) : null).set(qr.targetNameOrig, PolyString.getOrig(targetName)).set(qr.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
        }
    }
    if (insertBatch.getBatchCount() == 0) {
        // strange, no values anywhere?
        return;
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue)

Example 4 with AuditReferenceValue

use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertAuditReferenceValue.

protected void assertAuditReferenceValue(AuditEventRecord event, String refName, String oid, QName type, String name) {
    Set<AuditReferenceValue> values = event.getReferenceValues(refName);
    assertEquals("Wrong # of reference values of '" + refName + "'", 1, values.size());
    AuditReferenceValue value = values.iterator().next();
    assertEquals("Wrong OID", oid, value.getOid());
    assertEquals("Wrong type", type, value.getType());
    assertEquals("Wrong name", name, PolyString.getOrig(value.getTargetName()));
}
Also used : AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue)

Example 5 with AuditReferenceValue

use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.

the class SqlAuditServiceImpl method insertReferences.

private void insertReferences(JdbcSession jdbcSession, long recordId, Map<String, Set<AuditReferenceValue>> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qAuditRefValue = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditRefValue);
    for (String refName : references.keySet()) {
        for (AuditReferenceValue refValue : references.get(refName)) {
            // id will be generated, but we're not interested in those here
            PolyString targetName = refValue.getTargetName();
            insertBatch.set(qAuditRefValue.recordId, recordId).set(qAuditRefValue.name, refName).set(qAuditRefValue.oid, refValue.getOid()).set(qAuditRefValue.type, RUtil.qnameToString(refValue.getType())).set(qAuditRefValue.targetNameOrig, PolyString.getOrig(targetName)).set(qAuditRefValue.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
        }
    }
    if (insertBatch.getBatchCount() == 0) {
        // strange, no values anywhere?
        return;
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue)

Aggregations

AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)1 QAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord)1 ROperationResultStatus (com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus)1 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 NullTaskImpl (com.evolveum.midpoint.task.api.test.NullTaskImpl)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Timestamp (java.sql.Timestamp)1 Test (org.testng.annotations.Test)1