From ecb3dd0cd58976c61e6313cba48c4919c2e7bc64 Mon Sep 17 00:00:00 2001 From: milenaschedle Date: Thu, 9 Jul 2026 14:11:56 +0200 Subject: [PATCH 1/2] bugfix when committing log entry --- .../logbook/olog/ui/write/LogEntryEditorController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java index 49579d09f1..2b69de2cc0 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java @@ -388,10 +388,9 @@ public void initialize() { textArea.textProperty().bindBidirectional(descriptionProperty); switch(editMode){ - case NEW_LOG_ENTRY -> descriptionProperty.set(""); + case NEW_LOG_ENTRY -> descriptionProperty.set(logEntry.getDescription()!= null ? logEntry.getDescription(): ""); case UPDATE_LOG_ENTRY, NEW_LOG_ENTRY_FROM_SELECTION -> descriptionProperty.set(logEntry.getSource()); } -// descriptionProperty.set(logEntry.getSource()); descriptionProperty.addListener((observable, oldValue, newValue) -> isDirty = true); Image tagIcon = ImageCache.getImage(LogEntryEditorController.class, "/icons/add_tag.png"); From c6062e0145d214918a931d989d6997ee5f67df76 Mon Sep 17 00:00:00 2001 From: milenaschedle Date: Fri, 10 Jul 2026 10:20:57 +0200 Subject: [PATCH 2/2] moved SaveAndRestoreAuthenticationScope to model module and fixed user name for restored log entry --- .../SaveAndRestoreAuthenticationProvider.java | 1 + .../client/SaveAndRestoreClientImpl.java | 2 +- .../ui/ContextMenuCreateSaveset.java | 2 +- .../ui/SaveAndRestoreBaseController.java | 2 +- .../client/HttpClientTestIT.java | 4 +--- .../logging/SaveAndRestoreEventLogger.java | 21 +++++++++++++++++-- app/save-and-restore/model/pom.xml | 6 ++++++ .../SaveAndRestoreAuthenticationScope.java | 2 +- 8 files changed, 31 insertions(+), 9 deletions(-) rename app/save-and-restore/{app/src/main/java/org/phoebus/applications/saveandrestore => model/src/main/java/org/phoebus/applications/saveandrestore/model}/authentication/SaveAndRestoreAuthenticationScope.java (84%) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationProvider.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationProvider.java index ee3e237945..8c4ffafb9e 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationProvider.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationProvider.java @@ -19,6 +19,7 @@ package org.phoebus.applications.saveandrestore.authentication; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService; import org.phoebus.security.authorization.AuthenticationStatus; import org.phoebus.security.authorization.ServiceAuthenticationProvider; diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java index 3cf5aa6dd1..a83d29f86a 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.phoebus.applications.saveandrestore.Messages; import org.phoebus.applications.saveandrestore.SaveAndRestoreClientException; -import org.phoebus.applications.saveandrestore.authentication.SaveAndRestoreAuthenticationScope; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.applications.saveandrestore.model.CompositeSnapshot; import org.phoebus.applications.saveandrestore.model.Configuration; import org.phoebus.applications.saveandrestore.model.ConfigurationData; diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCreateSaveset.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCreateSaveset.java index 19837adcbf..4a9f8e8846 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCreateSaveset.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCreateSaveset.java @@ -27,7 +27,7 @@ import javafx.stage.Stage; import org.phoebus.applications.saveandrestore.Messages; import org.phoebus.applications.saveandrestore.SaveAndRestoreApplication; -import org.phoebus.applications.saveandrestore.authentication.SaveAndRestoreAuthenticationScope; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.NodeType; import org.phoebus.applications.saveandrestore.ui.configuration.ConfigurationFromSelectionController; diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreBaseController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreBaseController.java index 0a8f04ce11..ac6216a634 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreBaseController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreBaseController.java @@ -20,7 +20,7 @@ package org.phoebus.applications.saveandrestore.ui; import javafx.beans.property.SimpleStringProperty; -import org.phoebus.applications.saveandrestore.authentication.SaveAndRestoreAuthenticationScope; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.security.store.SecureStore; import org.phoebus.security.tokens.ScopedAuthenticationToken; diff --git a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/client/HttpClientTestIT.java b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/client/HttpClientTestIT.java index 38c5c6da62..4f2b8ab263 100644 --- a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/client/HttpClientTestIT.java +++ b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/client/HttpClientTestIT.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.phoebus.applications.saveandrestore.authentication.SaveAndRestoreAuthenticationScope; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.applications.saveandrestore.model.CompositeSnapshot; import org.phoebus.applications.saveandrestore.model.CompositeSnapshotData; import org.phoebus.applications.saveandrestore.model.ConfigPv; @@ -30,12 +30,10 @@ import org.phoebus.security.PhoebusSecurity; import org.phoebus.security.store.SecureStore; import org.phoebus.security.store.SecureStoreTarget; -import org.phoebus.security.tokens.AuthenticationScope; import org.phoebus.security.tokens.ScopedAuthenticationToken; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; -import java.net.ConnectException; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java index 469e322832..a8b466dc20 100644 --- a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java +++ b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java @@ -22,14 +22,18 @@ import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.RestoreResult; import org.phoebus.applications.saveandrestore.model.Tag; +import org.phoebus.applications.saveandrestore.model.authentication.SaveAndRestoreAuthenticationScope; import org.phoebus.applications.saveandrestore.model.event.SaveAndRestoreEventReceiver; import org.phoebus.framework.selection.SelectionService; import org.phoebus.framework.workbench.ApplicationService; import org.phoebus.logbook.LogEntry; import org.phoebus.logbook.LogbookPreferences; +import org.phoebus.security.store.SecureStore; +import org.phoebus.security.tokens.ScopedAuthenticationToken; import java.util.List; import java.util.function.Consumer; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -59,7 +63,7 @@ public void snapshotSaved(Node node, Consumer errorHandler) { SaveSnapshotActionInfo saveSnapshotActionInfo = new SaveSnapshotActionInfo(); saveSnapshotActionInfo.setSnapshotUniqueId(node.getUniqueId()); saveSnapshotActionInfo.setSnapshotCreatedDate(node.getCreated()); - saveSnapshotActionInfo.setActionPerformedBy(System.getProperty("user.name")); + saveSnapshotActionInfo.setActionPerformedBy(getUser()); saveSnapshotActionInfo.setComment(node.getDescription()); saveSnapshotActionInfo.setSnapshotName(node.getName()); SelectionService.getInstance().setSelection("SaveAndRestoreLogging", List.of(saveSnapshotActionInfo)); @@ -84,7 +88,7 @@ public void snapshotRestored(Node node, List failedPVs, Consumer< RestoreSnapshotActionInfo restoreSnapshotActionInfo = new RestoreSnapshotActionInfo(); restoreSnapshotActionInfo.setSnapshotUniqueId(node.getUniqueId()); restoreSnapshotActionInfo.setSnapshotCreatedDate(node.getCreated()); - restoreSnapshotActionInfo.setActionPerformedBy(System.getProperty("user.name")); + restoreSnapshotActionInfo.setActionPerformedBy(getUser()); restoreSnapshotActionInfo.setComment(node.getDescription()); restoreSnapshotActionInfo.setGolden(node.hasTag(Tag.GOLDEN)); restoreSnapshotActionInfo.setSnapshotName(node.getName()); @@ -92,4 +96,17 @@ public void snapshotRestored(Node node, List failedPVs, Consumer< SelectionService.getInstance().setSelection("SaveAndRestoreLogging", List.of(restoreSnapshotActionInfo)); Platform.runLater(() -> ApplicationService.createInstance("logbook")); } + + private String getUser(){ + try { + SecureStore store = new SecureStore(); + ScopedAuthenticationToken scopedAuthenticationToken = store.getScopedAuthenticationToken(new SaveAndRestoreAuthenticationScope()); + if (scopedAuthenticationToken != null) { + return scopedAuthenticationToken.getUsername(); + } + } catch (Exception e){ + logger.log(Level.WARNING, "Unable to get Authentication Token.", e); + } + return ""; + } } diff --git a/app/save-and-restore/model/pom.xml b/app/save-and-restore/model/pom.xml index 2356047846..d12ad82c47 100644 --- a/app/save-and-restore/model/pom.xml +++ b/app/save-and-restore/model/pom.xml @@ -17,6 +17,12 @@ 6.0.0-SNAPSHOT + + org.phoebus + core-security + 6.0.0-SNAPSHOT + + org.phoebus core-websocket-common diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationScope.java b/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/authentication/SaveAndRestoreAuthenticationScope.java similarity index 84% rename from app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationScope.java rename to app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/authentication/SaveAndRestoreAuthenticationScope.java index bbb87323ed..f65a7bad07 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationScope.java +++ b/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/authentication/SaveAndRestoreAuthenticationScope.java @@ -2,7 +2,7 @@ * Copyright (C) 2025 European Spallation Source ERIC. */ -package org.phoebus.applications.saveandrestore.authentication; +package org.phoebus.applications.saveandrestore.model.authentication; import org.phoebus.security.tokens.AuthenticationScope;