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 14:18:43 UTC
(streampipes) branch 5115-add-configuration-to-audit-log updated: feat(#5115): audit settings changes
This is an automated email from the ASF dual-hosted git repository.
JHoelli pushed a commit to branch 5115-add-configuration-to-audit-log
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/5115-add-configuration-to-audit-log by this push:
new b63b354c85 feat(#5115): audit settings changes
b63b354c85 is described below
commit b63b354c85fc85071c7c1cf87633b8907dbf3efa
Author: Jacqueline Höllig <j....@gmx.net>
AuthorDate: Thu Oct 22 16:18:30 2026 +0200
feat(#5115): audit settings changes
---
.../audit/events/StandardAuditEvents.java | 29 +++-
.../events/settings/AssetTransferDetails.java | 32 ++++
.../settings/ExportProviderAuditDetails.java | 30 ++++
.../audit/events/settings/FileAuditDetails.java | 25 +++
.../audit/events/settings/MailAuditDetails.java | 30 ++++
.../events/settings/SettingsAuditRecorder.java | 177 +++++++++++++++++++++
.../events/settings/SettingsAuditRecorderTest.java | 140 ++++++++++++++++
.../apache/streampipes/rest/impl/FileResource.java | 20 ++-
.../rest/impl/admin/DataExportResource.java | 26 ++-
.../rest/impl/admin/DataImportResource.java | 11 ++
.../impl/admin/EmailConfigurationResource.java | 10 +-
.../admin/ExportProviderConfigurationResource.java | 26 ++-
12 files changed, 539 insertions(+), 17 deletions(-)
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..1a9285937d 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,6 +24,10 @@ 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.settings.AssetTransferDetails;
+import org.apache.streampipes.audit.events.settings.ExportProviderAuditDetails;
+import org.apache.streampipes.audit.events.settings.FileAuditDetails;
+import org.apache.streampipes.audit.events.settings.MailAuditDetails;
import java.util.List;
@@ -43,9 +47,32 @@ public final class StandardAuditEvents implements AuditEventProvider {
public static final AuditEventDefinition<AuthenticationDetails> AUTH_LOGOUT =
new AuditEventDefinition<>("sp.auth.logout", AuthenticationDetails.class);
+ public static final AuditEventDefinition<AssetTransferDetails> EXPORT_DOWNLOAD =
+ new AuditEventDefinition<>("sp.export.download", AssetTransferDetails.class, "export");
+ public static final AuditEventDefinition<AssetTransferDetails> IMPORT_EXECUTE =
+ new AuditEventDefinition<>("sp.import.execute", AssetTransferDetails.class, "import");
+
+ public static final AuditEventDefinition<ExportProviderAuditDetails> EXPORT_PROVIDER_CREATE =
+ new AuditEventDefinition<>("sp.export-provider.create", ExportProviderAuditDetails.class, "export-provider");
+ public static final AuditEventDefinition<ExportProviderAuditDetails> EXPORT_PROVIDER_UPDATE =
+ new AuditEventDefinition<>("sp.export-provider.update", ExportProviderAuditDetails.class, "export-provider");
+ public static final AuditEventDefinition<ExportProviderAuditDetails> EXPORT_PROVIDER_DELETE =
+ new AuditEventDefinition<>("sp.export-provider.delete", ExportProviderAuditDetails.class, "export-provider");
+ public static final AuditEventDefinition<FileAuditDetails> FILE_UPLOAD =
+ new AuditEventDefinition<>("sp.file.upload", FileAuditDetails.class, "file");
+ public static final AuditEventDefinition<FileAuditDetails> FILE_DELETE =
+ new AuditEventDefinition<>("sp.file.delete", FileAuditDetails.class, "file");
+
+ public static final AuditEventDefinition<MailAuditDetails> MAIL_CONFIGURATION_UPDATE =
+ new AuditEventDefinition<>("sp.mail.configuration.update", MailAuditDetails.class, "mail-configuration");
+ public static final AuditEventDefinition<MailAuditDetails> MAIL_TEMPLATE_UPDATE =
+ new AuditEventDefinition<>("sp.mail.template.update", MailAuditDetails.class, "mail-template");
private static final List<AuditEventDefinition<?>> EVENT_TYPES = List.of(
- ADAPTER_CREATE, ADAPTER_START, ADAPTER_STOP, ADAPTER_EDIT, AUTH_LOGIN, AUTH_LOGOUT);
+ ADAPTER_CREATE, ADAPTER_START, ADAPTER_STOP, ADAPTER_EDIT, AUTH_LOGIN, AUTH_LOGOUT,
+ EXPORT_DOWNLOAD, IMPORT_EXECUTE,
+ EXPORT_PROVIDER_CREATE, EXPORT_PROVIDER_UPDATE, EXPORT_PROVIDER_DELETE,
+ FILE_UPLOAD, FILE_DELETE, MAIL_CONFIGURATION_UPDATE, MAIL_TEMPLATE_UPDATE);
@Override
public List<AuditEventDefinition<?>> eventTypes() {
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/AssetTransferDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/AssetTransferDetails.java
new file mode 100644
index 0000000000..f9f28f2918
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/AssetTransferDetails.java
@@ -0,0 +1,32 @@
+/*
+ * 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.settings;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+import java.util.List;
+
+/** Bounded transfer scope. The package contents and export item labels are deliberately excluded. */
+public record AssetTransferDetails(List<String> assetIds, int assetCount,
+ boolean overwriteExistingDocuments,
+ boolean overrideBrokerSettings) implements AuditDetails {
+ public AssetTransferDetails {
+ assetIds = List.copyOf(assetIds);
+ }
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/ExportProviderAuditDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/ExportProviderAuditDetails.java
new file mode 100644
index 0000000000..6753adc82d
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/ExportProviderAuditDetails.java
@@ -0,0 +1,30 @@
+/*
+ * 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.settings;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+import java.util.List;
+
+/** Safe provider metadata; changed fields name credentials but never expose their values. */
+public record ExportProviderAuditDetails(String providerType, List<String> changedFields) implements AuditDetails {
+ public ExportProviderAuditDetails {
+ changedFields = List.copyOf(changedFields);
+ }
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/FileAuditDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/FileAuditDetails.java
new file mode 100644
index 0000000000..5701550822
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/FileAuditDetails.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.settings;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+/** File type is retained for audit filtering; names and contents are excluded. */
+public record FileAuditDetails(String fileType) implements AuditDetails {
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/MailAuditDetails.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/MailAuditDetails.java
new file mode 100644
index 0000000000..ee9d8c29b5
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/MailAuditDetails.java
@@ -0,0 +1,30 @@
+/*
+ * 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.settings;
+
+import org.apache.streampipes.audit.api.AuditDetails;
+
+import java.util.List;
+
+/** Changed field names only; server, recipient, credentials, and template contents are never stored. */
+public record MailAuditDetails(List<String> changedFields) implements AuditDetails {
+ public MailAuditDetails {
+ changedFields = List.copyOf(changedFields);
+ }
+}
diff --git a/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorder.java b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorder.java
new file mode 100644
index 0000000000..97bebaf32a
--- /dev/null
+++ b/streampipes-audit-events/src/main/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorder.java
@@ -0,0 +1,177 @@
+/*
+ * 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.settings;
+
+import org.apache.streampipes.audit.api.AuditOutcome;
+import org.apache.streampipes.audit.api.AuditService;
+import org.apache.streampipes.audit.events.StandardAuditEvents;
+import org.apache.streampipes.model.configuration.EmailConfig;
+import org.apache.streampipes.model.configuration.ExportProviderSettings;
+import org.apache.streampipes.model.export.AssetExportConfiguration;
+import org.apache.streampipes.model.export.ExportConfiguration;
+import org.apache.streampipes.model.file.FileMetadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/** Publishes bounded settings events without serializing configuration values or file contents. */
+public final class SettingsAuditRecorder {
+ private static final int MAX_ASSET_IDS = 100;
+
+ private final AuditService auditService;
+
+ public SettingsAuditRecorder(AuditService auditService) {
+ this.auditService = Objects.requireNonNull(auditService);
+ }
+
+ public void exportDownloaded(String actor, AuditOutcome outcome, ExportConfiguration configuration) {
+ auditService.record(StandardAuditEvents.EXPORT_DOWNLOAD, outcome, actor, null,
+ transferDetails(configuration));
+ }
+
+ public void imported(String actor, AuditOutcome outcome, AssetExportConfiguration configuration) {
+ auditService.record(StandardAuditEvents.IMPORT_EXECUTE, outcome, actor, null,
+ transferDetails(configuration));
+ }
+
+ public void exportProviderCreated(String actor, ExportProviderSettings settings) {
+ auditService.record(StandardAuditEvents.EXPORT_PROVIDER_CREATE, AuditOutcome.SUCCEEDED, actor,
+ settings.getProviderId(), providerDetails(settings, List.of()));
+ }
+
+ public void exportProviderUpdated(String actor, ExportProviderSettings before, ExportProviderSettings after) {
+ auditService.record(StandardAuditEvents.EXPORT_PROVIDER_UPDATE, AuditOutcome.SUCCEEDED, actor,
+ after.getProviderId(), providerDetails(after, changedProviderFields(before, after)));
+ }
+
+ public void exportProviderDeleted(String actor, ExportProviderSettings settings) {
+ auditService.record(StandardAuditEvents.EXPORT_PROVIDER_DELETE, AuditOutcome.SUCCEEDED, actor,
+ settings.getProviderId(), providerDetails(settings, List.of()));
+ }
+
+ public void fileUploaded(String actor, FileMetadata file) {
+ auditService.record(StandardAuditEvents.FILE_UPLOAD, AuditOutcome.SUCCEEDED, actor, file.getFileId(),
+ new FileAuditDetails(file.getFiletype()));
+ }
+
+ public void fileUploadFailed(String actor) {
+ auditService.record(StandardAuditEvents.FILE_UPLOAD, AuditOutcome.FAILED, actor, null, null);
+ }
+
+ public void fileDeleted(String actor, String fileId) {
+ auditService.record(StandardAuditEvents.FILE_DELETE, AuditOutcome.SUCCEEDED, actor, fileId, null);
+ }
+
+ public void fileDeleteFailed(String actor, String fileId) {
+ auditService.record(StandardAuditEvents.FILE_DELETE, AuditOutcome.FAILED, actor, fileId, null);
+ }
+
+ public void mailConfigurationUpdated(String actor, EmailConfig before, EmailConfig after) {
+ auditService.record(StandardAuditEvents.MAIL_CONFIGURATION_UPDATE, AuditOutcome.SUCCEEDED, actor, null,
+ new MailAuditDetails(changedMailFields(before, after)));
+ }
+
+ public void mailTemplateUpdated(String actor) {
+ auditService.record(StandardAuditEvents.MAIL_TEMPLATE_UPDATE, AuditOutcome.SUCCEEDED, actor, null,
+ new MailAuditDetails(List.of("template")));
+ }
+
+ private AssetTransferDetails transferDetails(List<String> assetIds,
+ boolean overwriteExistingDocuments,
+ boolean overrideBrokerSettings) {
+ var allAssetIds = assetIds == null ? List.<String>of() : assetIds.stream()
+ .filter(Objects::nonNull)
+ .filter(id -> !id.isBlank())
+ .toList();
+ return new AssetTransferDetails(allAssetIds.stream().limit(MAX_ASSET_IDS).toList(), allAssetIds.size(),
+ overwriteExistingDocuments, overrideBrokerSettings);
+ }
+
+ private AssetTransferDetails transferDetails(ExportConfiguration configuration) {
+ if (configuration == null || configuration.getAssetExportConfiguration() == null) {
+ return transferDetails(List.of(), false, false);
+ }
+ return transferDetails(configuration.getAssetExportConfiguration());
+ }
+
+ private AssetTransferDetails transferDetails(AssetExportConfiguration configuration) {
+ return configuration == null ? transferDetails(List.of(), false, false)
+ : transferDetails(List.of(configuration));
+ }
+
+ private AssetTransferDetails transferDetails(List<AssetExportConfiguration> configurations) {
+ var validConfigurations = configurations == null ? List.<AssetExportConfiguration>of() : configurations.stream()
+ .filter(Objects::nonNull)
+ .toList();
+ var assetIds = validConfigurations.stream().map(AssetExportConfiguration::getAssetId).toList();
+ boolean overwriteExistingDocuments = validConfigurations.stream()
+ .anyMatch(AssetExportConfiguration::isOverwriteExistingDocuments);
+ boolean overrideBrokerSettings = validConfigurations.stream()
+ .anyMatch(AssetExportConfiguration::isOverrideBrokerSettings);
+ return transferDetails(assetIds, overwriteExistingDocuments, overrideBrokerSettings);
+ }
+
+ private ExportProviderAuditDetails providerDetails(ExportProviderSettings settings, List<String> changedFields) {
+ var providerType = settings.getProviderType() == null ? null : settings.getProviderType().name();
+ return new ExportProviderAuditDetails(providerType, changedFields);
+ }
+
+ private List<String> changedProviderFields(ExportProviderSettings before, ExportProviderSettings after) {
+ var changes = new ArrayList<String>();
+ addIfChanged(changes, "providerType", before.getProviderType(), after.getProviderType());
+ addIfChanged(changes, "accessKey", before.getAccessKey(), after.getAccessKey());
+ addIfChanged(changes, "secretKey", before.getSecretKey(), after.getSecretKey());
+ addIfChanged(changes, "bucketName", before.getBucketName(), after.getBucketName());
+ addIfChanged(changes, "endPoint", before.getEndPoint(), after.getEndPoint());
+ addIfChanged(changes, "awsRegion", before.getAwsRegion(), after.getAwsRegion());
+ return List.copyOf(changes);
+ }
+
+ private List<String> changedMailFields(EmailConfig before, EmailConfig after) {
+ if (before == null || after == null) {
+ return List.of("configuration");
+ }
+ var changes = new ArrayList<String>();
+ addIfChanged(changes, "emailConfigured", before.isEmailConfigured(), after.isEmailConfigured());
+ addIfChanged(changes, "transportStrategy", before.getTransportStrategy(), after.getTransportStrategy());
+ addIfChanged(changes, "smtpServerHost", before.getSmtpServerHost(), after.getSmtpServerHost());
+ addIfChanged(changes, "smtpServerPort", before.getSmtpServerPort(), after.getSmtpServerPort());
+ addIfChanged(changes, "usesAuthentication", before.isUsesAuthentication(), after.isUsesAuthentication());
+ addIfChanged(changes, "smtpUsername", before.getSmtpUsername(), after.getSmtpUsername());
+ addIfChanged(changes, "smtpPassword", before.getSmtpPassword(), after.getSmtpPassword());
+ addIfChanged(changes, "senderAddress", before.getSenderAddress(), after.getSenderAddress());
+ addIfChanged(changes, "senderName", before.getSenderName(), after.getSenderName());
+ addIfChanged(changes, "usesProxy", before.isUsesProxy(), after.isUsesProxy());
+ addIfChanged(changes, "proxyHost", before.getProxyHost(), after.getProxyHost());
+ addIfChanged(changes, "proxyPort", before.getProxyPort(), after.getProxyPort());
+ addIfChanged(changes, "usesProxyAuthentication", before.isUsesProxyAuthentication(),
+ after.isUsesProxyAuthentication());
+ addIfChanged(changes, "proxyUser", before.getProxyUser(), after.getProxyUser());
+ addIfChanged(changes, "proxyPassword", before.getProxyPassword(), after.getProxyPassword());
+ addIfChanged(changes, "testRecipientAddress", before.getTestRecipientAddress(), after.getTestRecipientAddress());
+ return List.copyOf(changes);
+ }
+
+ private void addIfChanged(List<String> changes, String field, Object before, Object after) {
+ if (!Objects.equals(before, after)) {
+ changes.add(field);
+ }
+ }
+}
diff --git a/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorderTest.java b/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorderTest.java
new file mode 100644
index 0000000000..049f12e6d9
--- /dev/null
+++ b/streampipes-audit-events/src/test/java/org/apache/streampipes/audit/events/settings/SettingsAuditRecorderTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.settings;
+
+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.apache.streampipes.model.configuration.EmailConfig;
+import org.apache.streampipes.model.configuration.ExportProviderSettings;
+import org.apache.streampipes.model.configuration.ProviderType;
+import org.apache.streampipes.model.export.AssetExportConfiguration;
+import org.apache.streampipes.model.export.ExportConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SettingsAuditRecorderTest {
+
+ @Test
+ void recordsBoundedAssetScopeForExportDownload() {
+ var auditService = new CapturingAuditService();
+ var recorder = new SettingsAuditRecorder(auditService);
+ var assetConfigurations = new ArrayList<AssetExportConfiguration>();
+ for (int i = 0; i < 101; i++) {
+ var assetConfiguration = new AssetExportConfiguration();
+ assetConfiguration.setAssetId("asset-" + i);
+ assetConfigurations.add(assetConfiguration);
+ }
+ var exportConfiguration = new ExportConfiguration();
+ exportConfiguration.setAssetExportConfiguration(assetConfigurations);
+
+ recorder.exportDownloaded("user-1", AuditOutcome.REQUESTED, exportConfiguration);
+
+ var call = auditService.calls.getFirst();
+ var details = (AssetTransferDetails) call.details();
+ assertEquals(StandardAuditEvents.EXPORT_DOWNLOAD, call.definition());
+ assertEquals(AuditOutcome.REQUESTED, call.outcome());
+ assertEquals(101, details.assetCount());
+ assertEquals(100, details.assetIds().size());
+ }
+
+ @Test
+ void recordsMailConfigurationChangesWithoutConfigurationValues() {
+ var auditService = new CapturingAuditService();
+ var recorder = new SettingsAuditRecorder(auditService);
+ var before = new EmailConfig();
+ before.setSmtpServerHost("old.example.org");
+ before.setSmtpPassword("old-password");
+ var after = new EmailConfig();
+ after.setSmtpServerHost("new.example.org");
+ after.setSmtpPassword("new-password");
+
+ recorder.mailConfigurationUpdated("user-1", before, after);
+
+ var call = auditService.calls.getFirst();
+ var details = (MailAuditDetails) call.details();
+ assertEquals(StandardAuditEvents.MAIL_CONFIGURATION_UPDATE, call.definition());
+ assertEquals(List.of("smtpServerHost", "smtpPassword"), details.changedFields());
+ assertFalse(details.toString().contains("old-password"));
+ assertFalse(details.toString().contains("new-password"));
+ }
+
+ @Test
+ void recordsProviderChangesWithoutProviderCredentials() {
+ var auditService = new CapturingAuditService();
+ var recorder = new SettingsAuditRecorder(auditService);
+ var before = provider("old-access-key", "old-secret-key");
+ var after = provider("new-access-key", "new-secret-key");
+
+ recorder.exportProviderUpdated("user-1", before, after);
+
+ var call = auditService.calls.getFirst();
+ var details = (ExportProviderAuditDetails) call.details();
+ assertEquals(StandardAuditEvents.EXPORT_PROVIDER_UPDATE, call.definition());
+ assertEquals(List.of("accessKey", "secretKey"), details.changedFields());
+ assertFalse(details.toString().contains("old-access-key"));
+ assertFalse(details.toString().contains("new-secret-key"));
+ }
+
+ @Test
+ void registersAllSettingsEventTypes() {
+ var eventTypes = new StandardAuditEvents().eventTypes();
+
+ assertTrue(eventTypes.containsAll(List.of(
+ StandardAuditEvents.EXPORT_DOWNLOAD,
+ StandardAuditEvents.IMPORT_EXECUTE,
+ StandardAuditEvents.EXPORT_PROVIDER_CREATE,
+ StandardAuditEvents.EXPORT_PROVIDER_UPDATE,
+ StandardAuditEvents.EXPORT_PROVIDER_DELETE,
+ StandardAuditEvents.FILE_UPLOAD,
+ StandardAuditEvents.FILE_DELETE,
+ StandardAuditEvents.MAIL_CONFIGURATION_UPDATE,
+ StandardAuditEvents.MAIL_TEMPLATE_UPDATE)));
+ }
+
+ private ExportProviderSettings provider(String accessKey, String secretKey) {
+ return new ExportProviderSettings(ProviderType.S3, "provider-1", accessKey, secretKey,
+ "bucket", "https://storage.example.org", "eu-central-1");
+ }
+
+ private record AuditCall(AuditEventDefinition<?> definition, AuditOutcome outcome, AuditDetails details) {
+ }
+
+ private static final class CapturingAuditService implements AuditService {
+ private final List<AuditCall> calls = new ArrayList<>();
+
+ @Override
+ public <T extends AuditDetails> void record(AuditEventDefinition<T> definition,
+ AuditOutcome outcome,
+ String actor,
+ String resourceId,
+ T details) {
+ calls.add(new AuditCall(definition, outcome, details));
+ }
+ }
+}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FileResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FileResource.java
index b80cd36cce..ba5ef19193 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FileResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FileResource.java
@@ -17,10 +17,12 @@
*/
package org.apache.streampipes.rest.impl;
+import org.apache.streampipes.audit.events.settings.SettingsAuditRecorder;
import org.apache.streampipes.manager.file.FileManager;
import org.apache.streampipes.model.file.FileMetadata;
import org.apache.streampipes.model.message.Notifications;
import org.apache.streampipes.resource.management.ResourceDeletionManager;
+import org.apache.streampipes.resource.management.SpResourceManager;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;
import org.apache.streampipes.rest.shared.exception.SpMessageException;
@@ -59,12 +61,15 @@ public class FileResource extends AbstractAuthGuardedRestResource {
private final FileManager fileManager;
private final ResourceDeletionManager resourceDeletionManager;
+ private final SettingsAuditRecorder audit;
public FileResource(ISpCoreConfigurationStorage coreConfigurationStorage,
IFileMetadataStorage fileMetadataStorage,
- ResourceDeletionManager resourceDeletionManager) {
+ ResourceDeletionManager resourceDeletionManager,
+ SpResourceManager resourceManager) {
this.fileManager = new FileManager(coreConfigurationStorage, fileMetadataStorage);
this.resourceDeletionManager = resourceDeletionManager;
+ this.audit = new SettingsAuditRecorder(resourceManager.getAuditService());
}
@PostMapping(
@@ -79,8 +84,10 @@ public class FileResource extends AbstractAuthGuardedRestResource {
fileDetail.getOriginalFilename(),
fileDetail.getInputStream()
);
+ audit.fileUploaded(getAuthenticatedUserSid(), metadata);
return ok(metadata);
} catch (IllegalArgumentException e) {
+ audit.fileUploadFailed(getAuthenticatedUserSid());
return badRequest(Notifications.error(
String.format(
"This file type is not supported. Allowed file types are %s.",
@@ -88,6 +95,7 @@ public class FileResource extends AbstractAuthGuardedRestResource {
)
));
} catch (Exception e) {
+ audit.fileUploadFailed(getAuthenticatedUserSid());
return fail();
}
}
@@ -95,8 +103,14 @@ public class FileResource extends AbstractAuthGuardedRestResource {
@DeleteMapping(path = "{fileId}")
@PreAuthorize(AuthConstants.HAS_WRITE_FILE_PRIVILEGE)
public ResponseEntity<Void> deleteFile(@PathVariable("fileId") String fileId) {
- fileManager.deleteFile(fileId, resourceDeletionManager);
- return ok();
+ try {
+ fileManager.deleteFile(fileId, resourceDeletionManager);
+ audit.fileDeleted(getAuthenticatedUserSid(), fileId);
+ return ok();
+ } catch (RuntimeException e) {
+ audit.fileDeleteFailed(getAuthenticatedUserSid(), fileId);
+ throw e;
+ }
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java
index b5ee2446ec..057a7897cb 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java
@@ -18,6 +18,8 @@
package org.apache.streampipes.rest.impl.admin;
+import org.apache.streampipes.audit.api.AuditOutcome;
+import org.apache.streampipes.audit.events.settings.SettingsAuditRecorder;
import org.apache.streampipes.export.ExportManager;
import org.apache.streampipes.manager.api.extensions.ExtensionServiceRequestManager;
import org.apache.streampipes.manager.pipeline.PipelineManager;
@@ -45,12 +47,14 @@ public class DataExportResource extends AbstractAuthGuardedRestResource {
private final ExtensionServiceRequestManager extensionServiceRequestManager;
private final PipelineManager pipelineManager;
private final SpResourceManager resourceManager;
+ private final SettingsAuditRecorder audit;
public DataExportResource(ExtensionServiceRequestManager extensionServiceRequestManager,
SpResourceManager resourceManager) {
this.extensionServiceRequestManager = extensionServiceRequestManager;
this.pipelineManager = new PipelineManager(resourceManager);
this.resourceManager = resourceManager;
+ this.audit = new SettingsAuditRecorder(resourceManager.getAuditService());
}
@@ -69,13 +73,21 @@ public class DataExportResource extends AbstractAuthGuardedRestResource {
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> download(@RequestBody ExportConfiguration exportConfiguration) throws IOException {
- var applicationPackage = ExportManager
- .getExportPackage(
- exportConfiguration,
- extensionServiceRequestManager,
- resourceManager,
- pipelineManager);
- return ok(applicationPackage);
+ var actor = getAuthenticatedUserSid();
+ audit.exportDownloaded(actor, AuditOutcome.REQUESTED, exportConfiguration);
+ try {
+ var applicationPackage = ExportManager
+ .getExportPackage(
+ exportConfiguration,
+ extensionServiceRequestManager,
+ resourceManager,
+ pipelineManager);
+ audit.exportDownloaded(actor, AuditOutcome.SUCCEEDED, exportConfiguration);
+ return ok(applicationPackage);
+ } catch (IOException | RuntimeException e) {
+ audit.exportDownloaded(actor, AuditOutcome.FAILED, exportConfiguration);
+ throw e;
+ }
}
}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataImportResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataImportResource.java
index efe5f0f8aa..db877435f3 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataImportResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataImportResource.java
@@ -18,6 +18,8 @@
package org.apache.streampipes.rest.impl.admin;
+import org.apache.streampipes.audit.api.AuditOutcome;
+import org.apache.streampipes.audit.events.settings.SettingsAuditRecorder;
import org.apache.streampipes.export.ImportManager;
import org.apache.streampipes.manager.api.extensions.ExtensionServiceRequestManager;
import org.apache.streampipes.manager.pipeline.PipelineManager;
@@ -48,12 +50,14 @@ public class DataImportResource extends AbstractAuthGuardedRestResource {
private final ExtensionServiceRequestManager extensionServiceRequestManager;
private final PipelineManager pipelineManager;
private final SpResourceManager resourceManager;
+ private final SettingsAuditRecorder audit;
public DataImportResource(ExtensionServiceRequestManager extensionServiceRequestManager,
SpResourceManager resourceManager) {
this.extensionServiceRequestManager = extensionServiceRequestManager;
this.pipelineManager = new PipelineManager(resourceManager);
this.resourceManager = resourceManager;
+ this.audit = new SettingsAuditRecorder(resourceManager.getAuditService());
}
@PostMapping(
@@ -76,6 +80,8 @@ public class DataImportResource extends AbstractAuthGuardedRestResource {
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> importData(@RequestPart("file_upload") MultipartFile fileDetail,
@RequestPart("configuration") AssetExportConfiguration exportConfiguration) {
+ var actor = getAuthenticatedUserSid();
+ audit.imported(actor, AuditOutcome.REQUESTED, exportConfiguration);
try {
ImportManager.performImport(
fileDetail.getInputStream(),
@@ -85,10 +91,15 @@ public class DataImportResource extends AbstractAuthGuardedRestResource {
resourceManager,
pipelineManager
);
+ audit.imported(actor, AuditOutcome.SUCCEEDED, exportConfiguration);
return ok();
} catch (IOException e) {
+ audit.imported(actor, AuditOutcome.FAILED, exportConfiguration);
LOG.error("An error occurred while importing resources", e);
return fail();
+ } catch (RuntimeException e) {
+ audit.imported(actor, AuditOutcome.FAILED, exportConfiguration);
+ throw e;
}
}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/EmailConfigurationResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/EmailConfigurationResource.java
index 263307f255..2fd0c8684e 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/EmailConfigurationResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/EmailConfigurationResource.java
@@ -17,10 +17,12 @@
*/
package org.apache.streampipes.rest.impl.admin;
+import org.apache.streampipes.audit.events.settings.SettingsAuditRecorder;
import org.apache.streampipes.mail.MailTester;
import org.apache.streampipes.model.configuration.EmailConfig;
import org.apache.streampipes.model.configuration.EmailTemplateConfig;
import org.apache.streampipes.model.message.Notifications;
+import org.apache.streampipes.resource.management.SpResourceManager;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;
import org.apache.streampipes.rest.shared.exception.SpMessageException;
@@ -57,9 +59,12 @@ public class EmailConfigurationResource extends AbstractAuthGuardedRestResource
private static final Logger LOG = LoggerFactory.getLogger(EmailConfigurationResource.class);
private final ISpCoreConfigurationStorage configurationStorage;
+ private final SettingsAuditRecorder audit;
- public EmailConfigurationResource(ISpCoreConfigurationStorage coreConfigurationStorage) {
+ public EmailConfigurationResource(ISpCoreConfigurationStorage coreConfigurationStorage,
+ SpResourceManager resourceManager) {
this.configurationStorage = coreConfigurationStorage;
+ this.audit = new SettingsAuditRecorder(resourceManager.getAuditService());
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@@ -80,6 +85,7 @@ public class EmailConfigurationResource extends AbstractAuthGuardedRestResource
var config = configurationStorage.get();
config.setEmailTemplateConfig(templateConfig);
configurationStorage.updateElement(config);
+ audit.mailTemplateUpdated(getAuthenticatedUserSid());
return ok();
}
@@ -97,8 +103,10 @@ public class EmailConfigurationResource extends AbstractAuthGuardedRestResource
config.setSmtpPassEncrypted(true);
}
var cfg = configurationStorage.get();
+ var oldConfig = cfg.getEmailConfig();
cfg.setEmailConfig(config);
configurationStorage.updateElement(cfg);
+ audit.mailConfigurationUpdated(getAuthenticatedUserSid(), oldConfig, config);
return ok();
}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/ExportProviderConfigurationResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/ExportProviderConfigurationResource.java
index 84e5459fd9..37a62ccd16 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/ExportProviderConfigurationResource.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/ExportProviderConfigurationResource.java
@@ -17,9 +17,11 @@
*/
package org.apache.streampipes.rest.impl.admin;
+import org.apache.streampipes.audit.events.settings.SettingsAuditRecorder;
import org.apache.streampipes.dataexplorer.export.objectstorage.TestExportProviderConnection;
import org.apache.streampipes.model.configuration.ExportProviderSettings;
import org.apache.streampipes.model.monitoring.SpLogMessage;
+import org.apache.streampipes.resource.management.SpResourceManager;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;
import org.apache.streampipes.storage.api.system.ISpCoreConfigurationStorage;
@@ -47,9 +49,12 @@ import java.util.stream.Collectors;
public class ExportProviderConfigurationResource extends AbstractAuthGuardedRestResource {
private final ISpCoreConfigurationStorage configurationStorage;
+ private final SettingsAuditRecorder audit;
- public ExportProviderConfigurationResource(ISpCoreConfigurationStorage configurationStorage) {
+ public ExportProviderConfigurationResource(ISpCoreConfigurationStorage configurationStorage,
+ SpResourceManager resourceManager) {
this.configurationStorage = configurationStorage;
+ this.audit = new SettingsAuditRecorder(resourceManager.getAuditService());
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@@ -80,10 +85,7 @@ public class ExportProviderConfigurationResource extends AbstractAuthGuardedRest
if (exportProviderSetting.isPresent()) {
try {
Map<String, Object> response = TestExportProviderConnection.connectionTest(exportProviderSetting.get());
-
-
- return ok(response);
-
+ return ok(response);
} catch (Exception e) {
return serverError(SpLogMessage.from(e));
}
@@ -109,6 +111,10 @@ public class ExportProviderConfigurationResource extends AbstractAuthGuardedRest
providerSettings = new ArrayList<>();
}
+ var existingSetting = providerSettings.stream()
+ .filter(existing -> existing != null && existing.getProviderId().equals(config.getProviderId()))
+ .findFirst();
+
List<ExportProviderSettings> providerSettingsWithoutExisting = providerSettings.stream()
.filter(existing -> existing != null && !existing.getProviderId().equals(config.getProviderId()))
.collect(Collectors.toList());
@@ -117,6 +123,11 @@ public class ExportProviderConfigurationResource extends AbstractAuthGuardedRest
cfg.setExportProviderSettings(providerSettingsWithoutExisting);
configurationStorage.updateElement(cfg);
+ if (existingSetting.isPresent()) {
+ audit.exportProviderUpdated(getAuthenticatedUserSid(), existingSetting.get(), config);
+ } else {
+ audit.exportProviderCreated(getAuthenticatedUserSid(), config);
+ }
return ok();
}
@@ -127,6 +138,10 @@ public class ExportProviderConfigurationResource extends AbstractAuthGuardedRest
List<ExportProviderSettings> allProviders = configurationStorage.get().getExportProviderSettings();
+ var deletedProvider = allProviders.stream()
+ .filter(provider -> provider.getProviderId().equals(providerId))
+ .findFirst();
+
List<ExportProviderSettings> filteredProviders = allProviders.stream()
.filter(provider -> !provider.getProviderId().equals(providerId))
.collect(Collectors.toList());
@@ -134,6 +149,7 @@ public class ExportProviderConfigurationResource extends AbstractAuthGuardedRest
var cfg = configurationStorage.get();
cfg.setExportProviderSettings(filteredProviders);
configurationStorage.updateElement(cfg);
+ deletedProvider.ifPresent(provider -> audit.exportProviderDeleted(getAuthenticatedUserSid(), provider));
return ok();
}