use of com.evolveum.midpoint.audit.api.AuditEventType in project midpoint by Evolveum.
the class AuditPopupPanel method initLayout.
@SuppressWarnings("serial")
private void initLayout(final Component component) {
TextFormGroup name = new TextFormGroup(ID_NAME, new PropertyModel<String>(getModel(), AuditReportDto.F_NAME), createStringResource("ObjectType.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, true);
add(name);
TextFormGroup description = new TextFormGroup(ID_DESCRIPTION, new PropertyModel<String>(getModel(), AuditReportDto.F_DESCRIPTION), createStringResource("ObjectType.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, true);
add(description);
IModel choices = WebComponentUtil.createReadonlyModelFromEnum(ExportType.class);
IChoiceRenderer renderer = new EnumChoiceRenderer();
DropDownFormGroup exportType = new DropDownFormGroup(ID_EXPORT_TYPE, new PropertyModel<ExportType>(getModel(), AuditReportDto.F_EXPORT_TYPE), choices, renderer, createStringResource("AuditPopulPanel.exportType.label"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
add(exportType);
choices = WebComponentUtil.createReadonlyModelFromEnum(AuditEventType.class);
DropDownFormGroup auditEventType = new DropDownFormGroup(ID_AUDITEVENTTYPE, new PropertyModel<AuditEventType>(getModel(), AuditReportDto.F_AUDITEVENTTYPE), choices, renderer, createStringResource("AuditPopupPanel.auditEventType"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
add(auditEventType);
DateFormGroup dateFrom = new DateFormGroup(ID_DATE_FROM, new PropertyModel<XMLGregorianCalendar>(getModel(), AuditReportDto.F_FROM_GREG), createStringResource("AuditPopupPanel.dateFrom"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
add(dateFrom);
DateFormGroup dateTo = new DateFormGroup(ID_DATE_TO, new PropertyModel<XMLGregorianCalendar>(getModel(), AuditReportDto.F_TO_GREG), createStringResource("AuditPopupPanel.dateTo"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
add(dateTo);
}
use of com.evolveum.midpoint.audit.api.AuditEventType in project midpoint by Evolveum.
the class RunReportPopupPanel method runConfirmPerformed.
// private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
// Component c = parent.get(id);
// if (c == null) {
// return;
// }
// c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// }
private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model) {
ReportDto reportDto = model.getObject();
PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
PrismContainer<ReportParameterType> paramContainer;
try {
paramContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
paramContainer.add(reportParamValue);
List<JasperReportParameterDto> params = getParametersView().getModelObject();
for (JasperReportParameterDto paramDto : params) {
if (paramDto.getValue() == null) {
continue;
}
List<JasperReportValueDto> values = paramDto.getValue();
Class<?> paramClass = paramDto.getType();
boolean multivalue = false;
if (List.class.isAssignableFrom(paramClass)) {
paramClass = paramDto.getNestedType();
if (paramClass == null) {
getSession().error("Nested type for list must be defined!");
target.add(getPageBase().getFeedbackPanel());
return;
}
}
QName typeName = getPrismContext().getSchemaRegistry().determineTypeForClass(paramClass);
PrismPropertyDefinitionImpl<?> def = new PrismPropertyDefinitionImpl<>(new QName(ReportConstants.NS_EXTENSION, paramDto.getName()), typeName, getPrismContext());
def.setDynamic(true);
def.setRuntimeSchema(true);
// TODO multivalue is always 'false' here ...
def.setMaxOccurs(multivalue ? -1 : 1);
PrismProperty prop = def.instantiate();
for (JasperReportValueDto paramValue : values) {
Object realValue = paramValue.getValue();
if (realValue == null) {
continue;
}
if (AuditEventType.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventTypeType.class;
realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
} else if (AuditEventStage.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventStageType.class;
realValue = AuditEventStage.fromAuditEventStage((AuditEventStage) realValue);
}
prop.addRealValue(realValue);
}
if (!prop.isEmpty()) {
reportParamValue.add(prop);
}
}
} catch (SchemaException | ClassNotFoundException e) {
OperationResult result = new OperationResult("Parameters serialization");
result.recordFatalError("Could not serialize parameters");
getPageBase().showResult(result);
return;
}
runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);
}
use of com.evolveum.midpoint.audit.api.AuditEventType in project midpoint by Evolveum.
the class Clockwork method auditEvent.
private <F extends ObjectType> void auditEvent(LensContext<F> context, AuditEventStage stage, XMLGregorianCalendar timestamp, boolean alwaysAudit, Task task, OperationResult result) throws SchemaException {
PrismObject<? extends ObjectType> primaryObject;
ObjectDelta<? extends ObjectType> primaryDelta;
if (context.getFocusContext() != null) {
primaryObject = context.getFocusContext().getObjectOld();
if (primaryObject == null) {
primaryObject = context.getFocusContext().getObjectNew();
}
primaryDelta = context.getFocusContext().getDelta();
} else {
Collection<LensProjectionContext> projectionContexts = context.getProjectionContexts();
if (projectionContexts == null || projectionContexts.isEmpty()) {
throw new IllegalStateException("No focus and no projections in " + context);
}
if (projectionContexts.size() > 1) {
throw new IllegalStateException("No focus and more than one projection in " + context);
}
LensProjectionContext projection = projectionContexts.iterator().next();
primaryObject = projection.getObjectOld();
if (primaryObject == null) {
primaryObject = projection.getObjectNew();
}
primaryDelta = projection.getDelta();
}
AuditEventType eventType;
if (primaryDelta == null) {
eventType = AuditEventType.SYNCHRONIZATION;
} else if (primaryDelta.isAdd()) {
eventType = AuditEventType.ADD_OBJECT;
} else if (primaryDelta.isModify()) {
eventType = AuditEventType.MODIFY_OBJECT;
} else if (primaryDelta.isDelete()) {
eventType = AuditEventType.DELETE_OBJECT;
} else {
throw new IllegalStateException("Unknown state of delta " + primaryDelta);
}
AuditEventRecord auditRecord = new AuditEventRecord(eventType, stage);
if (primaryObject != null) {
auditRecord.setTarget(primaryObject.clone());
// } else {
// throw new IllegalStateException("No primary object in:\n"+context.dump());
}
auditRecord.setChannel(context.getChannel());
if (stage == AuditEventStage.REQUEST) {
Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneDeltaCollection(context.getPrimaryChanges());
checkNamesArePresent(clonedDeltas, primaryObject);
auditRecord.addDeltas(clonedDeltas);
if (auditRecord.getTarget() == null) {
auditRecord.setTarget(Utils.determineAuditTargetDeltaOps(clonedDeltas));
}
} else if (stage == AuditEventStage.EXECUTION) {
auditRecord.setOutcome(result.getComputeStatus());
Collection<ObjectDeltaOperation<? extends ObjectType>> unauditedExecutedDeltas = context.getUnauditedExecutedDeltas();
if (!alwaysAudit && (unauditedExecutedDeltas == null || unauditedExecutedDeltas.isEmpty())) {
// No deltas, nothing to audit in this wave
return;
}
Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneCollection(unauditedExecutedDeltas);
checkNamesArePresent(clonedDeltas, primaryObject);
auditRecord.addDeltas(clonedDeltas);
} else {
throw new IllegalStateException("Unknown audit stage " + stage);
}
if (timestamp != null) {
auditRecord.setTimestamp(XmlTypeConverter.toMillis(timestamp));
}
addRecordMessage(auditRecord, result);
auditService.audit(auditRecord, task);
if (stage == AuditEventStage.EXECUTION) {
// We need to clean up so these deltas will not be audited again in next wave
context.markExecutedDeltasAudited();
context.setExecutionAudited(true);
} else if (stage == AuditEventStage.REQUEST) {
context.setRequestAudited(true);
} else {
throw new IllegalStateException("Unknown audit stage " + stage);
}
}
Aggregations