You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ho...@apache.org on 2026/10/22 12:38:27 UTC

(streampipes) 01/03: standard

This is an automated email from the ASF dual-hosted git repository.

JHoelli pushed a commit to branch 5111-add-datasets-to-audit-log
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit c766081825bd92fd2ecfaa6e6ffadb38a534b6b2
Author: Jacqueline Höllig <j....@gmx.net>
AuthorDate: Thu Oct 22 13:33:26 2026 +0200

    standard
---
 .../audit/events/StandardAuditEvents.java          | 11 ++++
 .../audit/events/dataset/DatasetAuditReporter.java | 49 ++++++++++++++
 .../events/dataset/DatasetCreatedDetails.java      | 25 ++++++++
 .../events/dataset/DatasetDeletedDetails.java      | 25 ++++++++
 .../audit/events/dataset/DatasetEditedDetails.java | 25 ++++++++
 .../events/dataset/DatasetAuditReporterTest.java   | 74 ++++++++++++++++++++++
 .../rest/impl/dataset/DatasetMetadataResource.java | 12 ++++
 7 files changed, 221 insertions(+)

diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/StandardAuditEvents.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/StandardAuditEvents.java
index 77be74032a..931c1639b0 100644
--- a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/StandardAuditEvents.java
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/StandardAuditEvents.java
@@ -24,11 +24,21 @@ import org.apache.streampipes.audit.events.adapter.AdapterCreatedDetails;
 import org.apache.streampipes.audit.events.adapter.AdapterEditedDetails;
 import org.apache.streampipes.audit.events.adapter.AdapterLifecycleDetails;
 import org.apache.streampipes.audit.events.authentication.AuthenticationDetails;
+import org.apache.streampipes.audit.events.dataset.DatasetCreatedDetails;
+import org.apache.streampipes.audit.events.dataset.DatasetDeletedDetails;
+import org.apache.streampipes.audit.events.dataset.DatasetEditedDetails;
 
 import java.util.List;
 
 public final class StandardAuditEvents implements AuditEventProvider {
 
+  public static final AuditEventDefinition<DatasetCreatedDetails> DATASET_CREATE =
+      new AuditEventDefinition<>("sp.dataset.create", DatasetCreatedDetails.class, "dataset");
+  public static final AuditEventDefinition<DatasetEditedDetails> DATASET_EDIT =
+      new AuditEventDefinition<>("sp.dataset.edit", DatasetEditedDetails.class, "dataset");
+  public static final AuditEventDefinition<DatasetDeletedDetails> DATASET_DELETE =
+      new AuditEventDefinition<>("sp.dataset.delete", DatasetDeletedDetails.class, "dataset");
+
   public static final AuditEventDefinition<AdapterCreatedDetails> ADAPTER_CREATE =
       new AuditEventDefinition<>("sp.adapter.create", AdapterCreatedDetails.class, "adapter");
   public static final AuditEventDefinition<AdapterLifecycleDetails> ADAPTER_START =
@@ -45,6 +55,7 @@ public final class StandardAuditEvents implements AuditEventProvider {
 
 
   private static final List<AuditEventDefinition<?>> EVENT_TYPES = List.of(
+      DATASET_CREATE, DATASET_EDIT, DATASET_DELETE,
       ADAPTER_CREATE, ADAPTER_START, ADAPTER_STOP, ADAPTER_EDIT, AUTH_LOGIN, AUTH_LOGOUT);
 
   @Override
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporter.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporter.java
new file mode 100644
index 0000000000..73703e8b18
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporter.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.audit.events.dataset;
+
+import org.apache.streampipes.audit.api.AuditOutcome;
+import org.apache.streampipes.audit.api.AuditService;
+import org.apache.streampipes.audit.events.StandardAuditEvents;
+
+import java.util.Objects;
+
+/** Publishes dataset lifecycle events with safe, resource-free details. */
+public final class DatasetAuditReporter {
+  private final AuditService auditService;
+
+  public DatasetAuditReporter(AuditService auditService) {
+    this.auditService = Objects.requireNonNull(auditService);
+  }
+
+  public void created(String actor, String datasetId) {
+    auditService.record(StandardAuditEvents.DATASET_CREATE, AuditOutcome.SUCCEEDED, actor, datasetId,
+        new DatasetCreatedDetails());
+  }
+
+  public void edited(String actor, String datasetId) {
+    auditService.record(StandardAuditEvents.DATASET_EDIT, AuditOutcome.SUCCEEDED, actor, datasetId,
+        new DatasetEditedDetails());
+  }
+
+  public void deleted(String actor, String datasetId) {
+    auditService.record(StandardAuditEvents.DATASET_DELETE, AuditOutcome.SUCCEEDED, actor, datasetId,
+        new DatasetDeletedDetails());
+  }
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetCreatedDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetCreatedDetails.java
new file mode 100644
index 0000000000..5649929c4b
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetCreatedDetails.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.audit.events.dataset;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+/** The dataset ID is stored in the audit event envelope; no dataset data is retained. */
+public record DatasetCreatedDetails() implements AuditDetails {
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetDeletedDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetDeletedDetails.java
new file mode 100644
index 0000000000..ac284e9d35
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetDeletedDetails.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.audit.events.dataset;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+/** The dataset ID is retained in the audit event envelope after deletion. */
+public record DatasetDeletedDetails() implements AuditDetails {
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetEditedDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetEditedDetails.java
new file mode 100644
index 0000000000..8a95d4ac0f
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/dataset/DatasetEditedDetails.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.audit.events.dataset;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+/** The dataset ID is stored in the audit event envelope; no dataset data is retained. */
+public record DatasetEditedDetails() implements AuditDetails {
+}
diff --git a/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporterTest.java b/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporterTest.java
new file mode 100644
index 0000000000..c5905447e3
--- /dev/null
+++ b/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/dataset/DatasetAuditReporterTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.audit.events.dataset;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+import org.apache.streampipes.audit.api.AuditEventDefinition;
+import org.apache.streampipes.audit.api.AuditOutcome;
+import org.apache.streampipes.audit.api.AuditService;
+import org.apache.streampipes.audit.events.StandardAuditEvents;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class DatasetAuditReporterTest {
+
+  @Test
+  void reportsDatasetLifecycleEvents() {
+    var auditService = new RecordingAuditService();
+    var reporter = new DatasetAuditReporter(auditService);
+
+    reporter.created("user-1", "dataset-1");
+    reporter.edited("user-1", "dataset-1");
+    reporter.deleted("user-1", "dataset-1");
+
+    assertEquals(List.of(
+        new AuditRecord(StandardAuditEvents.DATASET_CREATE, AuditOutcome.SUCCEEDED,
+            "user-1", "dataset-1", new DatasetCreatedDetails()),
+        new AuditRecord(StandardAuditEvents.DATASET_EDIT, AuditOutcome.SUCCEEDED,
+            "user-1", "dataset-1", new DatasetEditedDetails()),
+        new AuditRecord(StandardAuditEvents.DATASET_DELETE, AuditOutcome.SUCCEEDED,
+            "user-1", "dataset-1", new DatasetDeletedDetails())
+    ), auditService.records);
+  }
+
+  private static final class RecordingAuditService implements AuditService {
+    private final List<AuditRecord> records = new ArrayList<>();
+
+    @Override
+    public <T extends AuditDetails> void record(AuditEventDefinition<T> definition,
+                                                AuditOutcome outcome,
+                                                String actor,
+                                                String resourceId,
+                                                T details) {
+      records.add(new AuditRecord(definition, outcome, actor, resourceId, details));
+    }
+  }
+
+  private record AuditRecord(AuditEventDefinition<?> definition,
+                            AuditOutcome outcome,
+                            String actor,
+                            String resourceId,
+                            AuditDetails details) {
+  }
+}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/dataset/DatasetMetadataResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/dataset/DatasetMetadataResource.java
index 31917f8143..5cad630917 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/dataset/DatasetMetadataResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/dataset/DatasetMetadataResource.java
@@ -18,6 +18,7 @@
 
 package org.apache.streampipes.rest.impl.dataset;
 
+import org.apache.streampipes.audit.events.dataset.DatasetAuditReporter;
 import org.apache.streampipes.dataexplorer.management.DataExplorerDispatcher;
 import org.apache.streampipes.manager.pipeline.update.ChartSchemaUpdateCoordinator;
 import org.apache.streampipes.model.dataset.DatasetMetadata;
@@ -49,11 +50,13 @@ import java.util.Objects;
 @RequestMapping("/api/v4/datalake/measure")
 public class DatasetMetadataResource extends AbstractDatasetResource {
 
+  private final DatasetAuditReporter datasetAudit;
   private final SpResourceManager resourceManager;
 
   public DatasetMetadataResource(IChartStorage chartStorage,
                                  SpResourceManager resourceManager) {
     super(new ChartSchemaUpdateCoordinator(chartStorage), resourceManager);
+    this.datasetAudit = new DatasetAuditReporter(resourceManager.getAuditService());
     this.resourceManager = resourceManager;
   }
 
@@ -67,10 +70,17 @@ public class DatasetMetadataResource extends AbstractDatasetResource {
   @PreAuthorize("this.hasWriteAuthority()")
   public ResponseEntity<?> addDataLake(@RequestBody DatasetMetadata datasetMetadata) {
     try {
+      var existingDataset = this.datasetMetadataManagement
+          .getExistingMeasureByName(datasetMetadata.getMeasureName());
       DatasetMetadata result = this.datasetMetadataManagement.createOrUpdateMeasurement(
           datasetMetadata,
           getAuthenticatedUserSid()
       );
+      if (existingDataset.isPresent()) {
+        datasetAudit.edited(getAuthenticatedUserSid(), result.getElementId());
+      } else {
+        datasetAudit.created(getAuthenticatedUserSid(), result.getElementId());
+      }
       return ok(result);
     } catch (RuntimeException e) {
       return badRequest(SpLogMessage.from(e));
@@ -141,6 +151,7 @@ public class DatasetMetadataResource extends AbstractDatasetResource {
     if (elementId.equals(measure.getElementId())) {
       try {
         this.datasetMetadataManagement.updateMeasurement(measure);
+        datasetAudit.edited(getAuthenticatedUserSid(), elementId);
         return ok();
       } catch (IllegalArgumentException e) {
         return badRequest(e.getMessage());
@@ -154,6 +165,7 @@ public class DatasetMetadataResource extends AbstractDatasetResource {
   public ResponseEntity<?> deleteDatasetMetadata(@PathVariable("id") String elementId) {
     try {
       this.datasetMetadataManagement.deleteMeasurement(elementId);
+      datasetAudit.deleted(getAuthenticatedUserSid(), elementId);
       return ok();
     } catch (IllegalArgumentException e) {
       return badRequest(e.getMessage());