@Test public void testAudit() { AuditEventRecord record = new AuditEventRecord(); record.setChannel("http://midpoint.evolveum.com/xml/ns/public/provisioning/channels-3#import"); record.setEventIdentifier("1511974895961-0-1"); record.setEventStage(AuditEventStage.EXECUTION); record.setEventType(AuditEventType.ADD_OBJECT); ObjectDeltaOperation delta = new ObjectDeltaOperation(); delta.setObjectDelta(prismContext.deltaFactory().object().createModificationAddReference(UserType.class, "1234", UserType.F_LINK_REF, "123")); record.getDeltas().add(delta); delta = new ObjectDeltaOperation(); delta.setObjectDelta(prismContext.deltaFactory().object().createModificationAddReference(UserType.class, "1234", UserType.F_LINK_REF, "124")); record.getDeltas().add(delta); auditService.audit(record, new SimpleTaskAdapter()); }
audit.setEventIdentifier(repo.getEventIdentifier()); if (repo.getEventStage() != null) { audit.setEventStage(repo.getEventStage().getStage());
public AuditEventRecord prepareProcessInstanceAuditRecord(WfTask wfTask, AuditEventStage stage, OperationResult result) { WfContextType wfc = wfTask.getTask().getWorkflowContext(); AuditEventRecord record = new AuditEventRecord(); record.setEventType(WORKFLOW_PROCESS_INSTANCE); record.setEventStage(stage); record.setInitiator(wfTask.getRequesterIfExists(result)); // set real principal in case of explicitly requested process termination (MID-4263) ObjectReferenceType objectRef = resolveIfNeeded(wfc.getObjectRef(), result); record.setTarget(objectRef.asReferenceValue()); record.setOutcome(OperationResultStatus.SUCCESS); record.addReferenceValueIgnoreNull(WorkflowConstants.AUDIT_OBJECT, objectRef); record.addReferenceValueIgnoreNull(WorkflowConstants.AUDIT_TARGET, resolveIfNeeded(wfc.getTargetRef(), result)); if (stage == EXECUTION) { String stageInfo = wfTask.getCompleteStageInfo(); record.setParameter(stageInfo); String answer = wfTask.getAnswerNice(); record.setResult(answer); record.setMessage(stageInfo != null ? stageInfo + " : " + answer : answer); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_NUMBER, wfc.getStageNumber()); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_COUNT, WfContextUtil.getStageCount(wfc)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_NAME, WfContextUtil.getStageName(wfc)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_DISPLAY_NAME, WfContextUtil.getStageDisplayName(wfc)); } record.addPropertyValue(WorkflowConstants.AUDIT_PROCESS_INSTANCE_ID, wfc.getProcessInstanceId()); OperationBusinessContextType businessContext = WfContextUtil.getBusinessContext(wfc); String requesterComment = businessContext != null ? businessContext.getComment() : null; if (requesterComment != null) { record.addPropertyValue(WorkflowConstants.AUDIT_REQUESTER_COMMENT, requesterComment); } return record; }
public AuditEventRecord prepareWorkItemAuditReportCommon(WorkItemType workItem, WfTask wfTask, AuditEventStage stage, OperationResult result) throws WorkflowException { AuditEventRecord record = new AuditEventRecord(); record.setEventType(AuditEventType.WORK_ITEM); record.setEventStage(stage); ObjectReferenceType objectRef = resolveIfNeeded(WfContextUtil.getObjectRef(workItem), result); record.setTarget(objectRef.asReferenceValue()); record.setOutcome(OperationResultStatus.SUCCESS); record.setParameter(wfTask.getCompleteStageInfo()); record.addReferenceValueIgnoreNull(WorkflowConstants.AUDIT_OBJECT, objectRef); record.addReferenceValueIgnoreNull(WorkflowConstants.AUDIT_TARGET, resolveIfNeeded(WfContextUtil.getTargetRef(workItem), result)); record.addReferenceValueIgnoreNull(WorkflowConstants.AUDIT_ORIGINAL_ASSIGNEE, resolveIfNeeded(workItem.getOriginalAssigneeRef(), result)); record.addReferenceValues(WorkflowConstants.AUDIT_CURRENT_ASSIGNEE, resolveIfNeeded(workItem.getAssigneeRef(), result)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_NUMBER, workItem.getStageNumber()); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_COUNT, WfContextUtil.getStageCount(workItem)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_NAME, WfContextUtil.getStageName(workItem)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_STAGE_DISPLAY_NAME, WfContextUtil.getStageDisplayName(workItem)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_ESCALATION_LEVEL_NUMBER, WfContextUtil.getEscalationLevelNumber(workItem)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_ESCALATION_LEVEL_NAME, WfContextUtil.getEscalationLevelName(workItem)); record.addPropertyValueIgnoreNull(WorkflowConstants.AUDIT_ESCALATION_LEVEL_DISPLAY_NAME, WfContextUtil.getEscalationLevelDisplayName(workItem)); record.addPropertyValue(WorkflowConstants.AUDIT_WORK_ITEM_ID, workItem.getExternalId()); record.addPropertyValue(WorkflowConstants.AUDIT_PROCESS_INSTANCE_ID, WfContextUtil.getProcessInstanceId(workItem)); return record; }
auditRecord.setTimestamp(System.currentTimeMillis()); auditRecord.setOutcome(result.getStatus()); auditRecord.setEventStage(AuditEventStage.EXECUTION); auditRecord.getDeltas().clear(); auditRecord.getDeltas().addAll(executedDeltas);