-
Notifications
You must be signed in to change notification settings - Fork 128
Use authenticated user name when creating log entries from save&restore #3876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<String> 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,12 +88,25 @@ public void snapshotRestored(Node node, List<RestoreResult> 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()); | ||
| restoreSnapshotActionInfo.setFailedPVs(failedPVs.stream().map(restoreResult -> restoreResult.getSnapshotItem().getConfigPv().getPvName()).toList()); | ||
| 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 "<Not Available>"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the retrieval of the authentication token is not successful, shouldn't that be an error, and the log message should not be written? @georgweiss @kasemir I am not familiar with the way authentication is handled; could you provide your input?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case an error dialog would be a bit confusing in the context of the workflow as it is not obvious why it is shown. Moreover, the exception would be a corner case as logging of an action is relevant only when a user has been signed-in. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this line also have an additional check for
null(analogous to the one added on the preceding line) oflogEntry.getSource()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there is no need for a null check.