Search in sources :

Example 1 with AuditEventType

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);
}
Also used : TextFormGroup(com.evolveum.midpoint.web.component.form.TextFormGroup) IModel(org.apache.wicket.model.IModel) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) ExportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExportType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DateFormGroup(com.evolveum.midpoint.web.component.form.DateFormGroup)

Example 2 with AuditEventType

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);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) QName(javax.xml.namespace.QName) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) JasperReportParameterDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto) JasperReportValueDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportValueDto) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismObject(com.evolveum.midpoint.prism.PrismObject) AuditEventStageType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType)

Example 3 with AuditEventType

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);
    }
}
Also used : AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Aggregations

AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)1 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 DateFormGroup (com.evolveum.midpoint.web.component.form.DateFormGroup)1 DropDownFormGroup (com.evolveum.midpoint.web.component.form.DropDownFormGroup)1 TextFormGroup (com.evolveum.midpoint.web.component.form.TextFormGroup)1 JasperReportParameterDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto)1 JasperReportValueDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportValueDto)1 ReportDto (com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto)1 AuditEventStageType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType)1 ExportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExportType)1 ReportParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1