Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Copy link
Copy Markdown
Collaborator

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) of logEntry.getSource()?

Copy link
Copy Markdown
Collaborator

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.

}
// descriptionProperty.set(logEntry.getSource());
descriptionProperty.addListener((observable, oldValue, newValue) -> isDirty = true);

Image tagIcon = ImageCache.getImage(LogEntryEditorController.class, "/icons/add_tag.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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));
Expand All @@ -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>";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

}
}
6 changes: 6 additions & 0 deletions app/save-and-restore/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<version>6.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.phoebus</groupId>
<artifactId>core-security</artifactId>
<version>6.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.phoebus</groupId>
<artifactId>core-websocket-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading