Search in sources :

Example 1 with DeltaConversionOptions

use of com.evolveum.midpoint.schema.DeltaConversionOptions in project midpoint by Evolveum.

the class AuditEventRecord method createAuditEventRecordType.

// TODO: currently unused (2021), but if audit(AERType) will be reused as part of audit(AER) it can still be useful
public AuditEventRecordType createAuditEventRecordType(boolean tolerateInconsistencies) {
    AuditEventRecordType auditRecord = new AuditEventRecordType();
    auditRecord.setRepoId(repoId);
    auditRecord.setChannel(channel);
    auditRecord.setEventIdentifier(eventIdentifier);
    auditRecord.setEventStage(AuditEventStage.toSchemaValue(eventStage));
    auditRecord.setEventType(AuditEventType.toSchemaValue(eventType));
    auditRecord.setHostIdentifier(hostIdentifier);
    auditRecord.setRemoteHostAddress(remoteHostAddress);
    auditRecord.setNodeIdentifier(nodeIdentifier);
    auditRecord.setInitiatorRef(ObjectTypeUtil.createObjectRef(initiatorRef, true));
    auditRecord.setAttorneyRef(ObjectTypeUtil.createObjectRef(attorneyRef, true));
    auditRecord.setMessage(message);
    auditRecord.setOutcome(OperationResultStatus.createStatusType(outcome));
    auditRecord.setParameter(parameter);
    auditRecord.setResult(result);
    auditRecord.setSessionIdentifier(sessionIdentifier);
    auditRecord.setTargetOwnerRef(ObjectTypeUtil.createObjectRef(targetOwnerRef, true));
    auditRecord.setTargetRef(ObjectTypeUtil.createObjectRef(targetRef, true));
    auditRecord.setRequestIdentifier(requestIdentifier);
    auditRecord.setTaskIdentifier(taskIdentifier);
    auditRecord.setTaskOID(taskOid);
    auditRecord.getResourceOid().addAll(resourceOids);
    auditRecord.setTimestamp(MiscUtil.asXMLGregorianCalendar(timestamp));
    for (ObjectDeltaOperation<?> delta : deltas) {
        ObjectDeltaOperationType odo = new ObjectDeltaOperationType();
        try {
            DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
            // This can be tricky because it can create human-readable but machine-unprocessable
            // data, see MID-6262. But in current context the results of this method are to be
            // used only in GUI and reports, so we are safe here.
            options.setEscapeInvalidCharacters(true);
            DeltaConvertor.toObjectDeltaOperationType(delta, odo, options);
            auditRecord.getDelta().add(odo);
        } catch (Exception e) {
            if (tolerateInconsistencies) {
                if (delta.getExecutionResult() != null) {
                    // TODO does this even work? [med]
                    delta.getExecutionResult().setMessage("Could not show audit record, bad data in delta: " + delta.getObjectDelta());
                } else {
                    OperationResult result = new OperationResult("Create audit event record type");
                    result.setMessage("Could not show audit record, bad data in delta: " + delta.getObjectDelta());
                    odo.setExecutionResult(result.createOperationResultType());
                }
            } else {
                throw new SystemException(e.getMessage(), e);
            }
        }
    }
    for (Map.Entry<String, Set<String>> propertyEntry : properties.entrySet()) {
        AuditEventRecordPropertyType propertyType = new AuditEventRecordPropertyType();
        propertyType.setName(propertyEntry.getKey());
        propertyType.getValue().addAll(propertyEntry.getValue());
        auditRecord.getProperty().add(propertyType);
    }
    for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : references.entrySet()) {
        AuditEventRecordReferenceType referenceType = new AuditEventRecordReferenceType();
        referenceType.setName(referenceEntry.getKey());
        referenceEntry.getValue().forEach(v -> referenceType.getValue().add(v.toXml()));
        auditRecord.getReference().add(referenceType);
    }
    for (Map.Entry<String, String> customColumnEntry : customColumnProperty.entrySet()) {
        AuditEventRecordCustomColumnPropertyType customColumn = new AuditEventRecordCustomColumnPropertyType();
        customColumn.setName(customColumnEntry.getKey());
        customColumn.setValue(customColumnEntry.getValue());
        auditRecord.getCustomColumnProperty().add(customColumn);
    }
    // TODO MID-5531 convert custom properties too? What about other than string types?
    return auditRecord;
}
Also used : AuditEventRecordReferenceType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) SystemException(com.evolveum.midpoint.util.exception.SystemException) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) DeltaConversionOptions(com.evolveum.midpoint.schema.DeltaConversionOptions) AuditEventRecordPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordPropertyType)

Example 2 with DeltaConversionOptions

use of com.evolveum.midpoint.schema.DeltaConversionOptions in project midpoint by Evolveum.

the class AuditInsertion method convertDelta.

/**
 * Returns prepared audit delta row without PK columns which will be added later.
 * For normal repo this code would be in mapper, but here we know exactly what type we work with.
 */
@Nullable
private MAuditDelta convertDelta(ObjectDeltaOperationType deltaOperation) {
    try {
        MAuditDelta deltaRow = new MAuditDelta();
        ObjectDeltaType delta = deltaOperation.getObjectDelta();
        if (delta != null) {
            DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
            options.setEscapeInvalidCharacters(escapeIllegalCharacters);
            String serializedDelta = DeltaConvertor.serializeDelta(delta, options, repoContext.getJdbcRepositoryConfiguration().getFullObjectFormat());
            // serializedDelta is transient, needed for changed items later
            deltaRow.serializedDelta = serializedDelta;
            deltaRow.delta = serializedDelta.getBytes(StandardCharsets.UTF_8);
            deltaRow.deltaOid = SqaleUtils.oidToUUid(delta.getOid());
            deltaRow.deltaType = delta.getChangeType();
        }
        OperationResultType executionResult = deltaOperation.getExecutionResult();
        byte[] fullResult = null;
        if (executionResult != null) {
            fullResult = repoContext.createFullResult(executionResult);
            deltaRow.status = executionResult.getStatus();
            deltaRow.fullResult = fullResult;
        }
        deltaRow.resourceOid = SqaleUtils.oidToUUid(deltaOperation.getResourceOid());
        if (deltaOperation.getObjectName() != null) {
            deltaRow.objectNameOrig = deltaOperation.getObjectName().getOrig();
            deltaRow.objectNameNorm = deltaOperation.getObjectName().getNorm();
        }
        if (deltaOperation.getResourceName() != null) {
            deltaRow.resourceNameOrig = deltaOperation.getResourceName().getOrig();
            deltaRow.resourceNameNorm = deltaOperation.getResourceName().getNorm();
        }
        deltaRow.checksum = computeChecksum(deltaRow.delta, fullResult);
        return deltaRow;
    } catch (Exception ex) {
        logger.warn("Unexpected problem during audit delta conversion", ex);
        return null;
    }
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) DeltaConversionOptions(com.evolveum.midpoint.schema.DeltaConversionOptions) IOException(java.io.IOException) SystemException(com.evolveum.midpoint.util.exception.SystemException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DeltaConversionOptions

use of com.evolveum.midpoint.schema.DeltaConversionOptions in project midpoint by Evolveum.

the class LensObjectDeltaOperation method toLensObjectDeltaOperationType.

@NotNull
public LensObjectDeltaOperationType toLensObjectDeltaOperationType() throws SchemaException {
    LensObjectDeltaOperationType retval = new LensObjectDeltaOperationType();
    DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
    // Escaping invalid characters in serialized deltas could be questionable; see MID-6262.
    // But because we currently do not use the deltas for other than human readers we can afford
    // to replace invalid characters by descriptive text.
    options.setEscapeInvalidCharacters(true);
    retval.setObjectDeltaOperation(DeltaConvertor.toObjectDeltaOperationType(this, options));
    retval.setAudited(audited);
    return retval;
}
Also used : LensObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensObjectDeltaOperationType) DeltaConversionOptions(com.evolveum.midpoint.schema.DeltaConversionOptions) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DeltaConversionOptions (com.evolveum.midpoint.schema.DeltaConversionOptions)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 AuditEventRecordCustomColumnPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType)1 AuditEventRecordPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordPropertyType)1 AuditEventRecordReferenceType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType)1 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)1 LensObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.LensObjectDeltaOperationType)1 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)1 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)1 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1