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;
}
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;
}
}
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;
}
Aggregations