diff --git a/app/save-and-restore/app/doc/images/compare-snapshots-view.png b/app/save-and-restore/app/doc/images/compare-snapshots-view.png index c5fb8b30c7..cb833589f1 100644 Binary files a/app/save-and-restore/app/doc/images/compare-snapshots-view.png and b/app/save-and-restore/app/doc/images/compare-snapshots-view.png differ diff --git a/app/save-and-restore/app/doc/images/operation-failed.png b/app/save-and-restore/app/doc/images/operation-failed.png index 8b94c53aa1..5dc8989fab 100644 Binary files a/app/save-and-restore/app/doc/images/operation-failed.png and b/app/save-and-restore/app/doc/images/operation-failed.png differ diff --git a/app/save-and-restore/app/doc/images/restore-failed.png b/app/save-and-restore/app/doc/images/restore-failed.png index b8eb1e8fa7..820e8d8e4a 100644 Binary files a/app/save-and-restore/app/doc/images/restore-failed.png and b/app/save-and-restore/app/doc/images/restore-failed.png differ diff --git a/app/save-and-restore/app/doc/images/restore-mode-invalid.png b/app/save-and-restore/app/doc/images/restore-mode-invalid.png new file mode 100644 index 0000000000..2150c8a4f8 Binary files /dev/null and b/app/save-and-restore/app/doc/images/restore-mode-invalid.png differ diff --git a/app/save-and-restore/app/doc/images/restore-with-scale.png b/app/save-and-restore/app/doc/images/restore-with-scale.png index 716435b4a5..bd04a4121a 100644 Binary files a/app/save-and-restore/app/doc/images/restore-with-scale.png and b/app/save-and-restore/app/doc/images/restore-with-scale.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-new.png b/app/save-and-restore/app/doc/images/snapshot-new.png index d0c25cd6fb..74aeb4f999 100644 Binary files a/app/save-and-restore/app/doc/images/snapshot-new.png and b/app/save-and-restore/app/doc/images/snapshot-new.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-restore-filter.png b/app/save-and-restore/app/doc/images/snapshot-restore-filter.png index b0600b120c..81dfa52b38 100644 Binary files a/app/save-and-restore/app/doc/images/snapshot-restore-filter.png and b/app/save-and-restore/app/doc/images/snapshot-restore-filter.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-restore.png b/app/save-and-restore/app/doc/images/snapshot-restore.png index a55c20407c..f9d13f7b9d 100644 Binary files a/app/save-and-restore/app/doc/images/snapshot-restore.png and b/app/save-and-restore/app/doc/images/snapshot-restore.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-taken.png b/app/save-and-restore/app/doc/images/snapshot-taken.png index 7769f9ef20..54054fb1ea 100644 Binary files a/app/save-and-restore/app/doc/images/snapshot-taken.png and b/app/save-and-restore/app/doc/images/snapshot-taken.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-threshold.png b/app/save-and-restore/app/doc/images/snapshot-threshold.png index 5e47ce7320..68d13d64a7 100644 Binary files a/app/save-and-restore/app/doc/images/snapshot-threshold.png and b/app/save-and-restore/app/doc/images/snapshot-threshold.png differ diff --git a/app/save-and-restore/app/doc/images/snapshot-with-references.png b/app/save-and-restore/app/doc/images/snapshot-with-references.png deleted file mode 100644 index 7761baad5a..0000000000 Binary files a/app/save-and-restore/app/doc/images/snapshot-with-references.png and /dev/null differ diff --git a/app/save-and-restore/app/doc/images/toggle-delta-zero.png b/app/save-and-restore/app/doc/images/toggle-delta-zero.png index cadbac5171..d7745ea0cf 100644 Binary files a/app/save-and-restore/app/doc/images/toggle-delta-zero.png and b/app/save-and-restore/app/doc/images/toggle-delta-zero.png differ diff --git a/app/save-and-restore/app/doc/images/toggle-readback.png b/app/save-and-restore/app/doc/images/toggle-readback.png index 52db957ace..c412f59818 100644 Binary files a/app/save-and-restore/app/doc/images/toggle-readback.png and b/app/save-and-restore/app/doc/images/toggle-readback.png differ diff --git a/app/save-and-restore/app/doc/index.rst b/app/save-and-restore/app/doc/index.rst index 6af024597a..e6c36f51fe 100644 --- a/app/save-and-restore/app/doc/index.rst +++ b/app/save-and-restore/app/doc/index.rst @@ -363,6 +363,14 @@ Prior to restore user has the option to: Restoring from a composite snapshot works in the same manner as the restore operation from a single-snapshot. +The preference setting ``org.phoebus.applications.saveandrestore/default_restore_mode`` selects the preferred +mode of a restore operation, i.e. to let the Phoebus client perform the restore operation, or to delegate that +to the service. Note though that a restore operation on the service requires a dedicated user role. In case +``org.phoebus.applications.saveandrestore/default_restore_mode`` is set to ``SERVICE_RESTORE``, +but user is not authorized to call the service to perform a restore operation, the UI will indicate it thus: + +.. image:: images/restore-mode-invalid.png + Filter PV items in list ^^^^^^^^^^^^^^^^^^^^^^^ The list of items in the snapshot view can be filtered based on the PV name. See screenshot for highlighted UI element diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClient.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClient.java index a9cfa50944..281d8c04e1 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClient.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClient.java @@ -36,6 +36,7 @@ import javax.ws.rs.core.MultivaluedMap; import java.util.List; +import java.util.Optional; /** * Implementations of this interface shall handle the communication to the save-and-restore service. @@ -275,4 +276,10 @@ public interface SaveAndRestoreClient { * @return A {@link List} of {@link SnapshotItem}s carrying snapshot values read by the service. */ List takeSnapshot(String configurationNodeId); + + /** + * @return An empty {@link Optional} if user is not yet authenticated, otherwise a value + * indicating if user is authorized to call server side restore operations. + */ + Optional serverRestoreAuthorized(); } 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 67ec7536c8..56f3e277a7 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 @@ -43,6 +43,7 @@ import java.time.Duration; import java.util.Base64; import java.util.List; +import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; @@ -665,6 +666,29 @@ public List takeSnapshot(String configurationNodeId) { }); } + @Override + public Optional serverRestoreAuthorized(){ + String basicAuthenticationHeader = getBasicAuthenticationHeader(); + if(basicAuthenticationHeader == null){ // User not signed in + return Optional.empty(); + } + try { + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(Preferences.jmasarServiceUrl + "/server-restore-authorized")) + .header("Authorization", basicAuthenticationHeader) + .POST(HttpRequest.BodyPublishers.noBody()) + .build(); + HttpResponse response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); + if (response.statusCode() != 200) { + return Optional.of(false); + } + + return Optional.of(OBJECT_MAPPER.readValue(response.body(), Boolean.class)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private T getCall(String relativeUrl, Class clazz) { HttpResponse response = getCall(relativeUrl); try { diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java index 62694681f2..fbb85bd9f5 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java @@ -352,7 +352,6 @@ public Filter fromString(String s) { saveAndRestoreService.setConnectCallback(this::handleWebSocketConnected); saveAndRestoreService.setDisconnectCallback(this::handleWebSocketDisconnected); saveAndRestoreService.connectWebSocket(); - } /** diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreService.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreService.java index 458bd7f7db..000dafcc6d 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreService.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreService.java @@ -58,6 +58,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; @@ -517,4 +518,12 @@ public void handleWebSocketMessage(String message) { } } + /** + * @return false if user is not yet authenticated or is not + * authorized to call restore operations on the server. + */ + public Optional serverRestoreAuthorized(){ + return saveAndRestoreClient.serverRestoreAuthorized(); + } + } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java index 3386b85292..d3069d9c9a 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java @@ -93,6 +93,7 @@ import org.phoebus.saveandrestore.util.Threshold; import org.phoebus.saveandrestore.util.Utilities; import org.phoebus.saveandrestore.util.VNoData; +import org.phoebus.security.tokens.ScopedAuthenticationToken; import org.phoebus.ui.application.ContextMenuHelper; import org.phoebus.ui.dialog.DialogHelper; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; @@ -202,14 +203,6 @@ public class SnapshotController extends SaveAndRestoreBaseController @FXML private RadioButton readFromArchiver; - @SuppressWarnings("unused") - @FXML - private RadioButton restoreFromClient; - - @SuppressWarnings("unused") - @FXML - private RadioButton restoreFromService; - @SuppressWarnings("unused") @FXML private TooltipTableColumn pvNameColumn; @@ -229,6 +222,9 @@ public class SnapshotController extends SaveAndRestoreBaseController @FXML private TableColumn actionResultColumn; + @FXML + private Label invalidConfigLabel; + @SuppressWarnings("unused") @FXML private TableColumn actionResultReadbackColumn; @@ -348,6 +344,13 @@ public class SnapshotController extends SaveAndRestoreBaseController */ protected final SimpleBooleanProperty disabledUi = new SimpleBooleanProperty(false); + /** + * Used to manage UI components based on preferred restore mode (client or service) and + * actual user authorization for server restore operations. Initially this is true, + * but checks are performed to verify this. + */ + private final SimpleBooleanProperty serverRestoreSettingsConsistent = new SimpleBooleanProperty(true); + /** * The {@link Snapshot} object holding the data for this controller. */ @@ -419,8 +422,10 @@ public void initialize() { logAction.visibleProperty().set(ServiceLoader.load(SaveAndRestoreEventReceiver.class).iterator().hasNext()); restoreButton.disableProperty().bind(Bindings.createBooleanBinding(() -> - snapshotRestorableProperty.not().get() || - userIdentity.isNull().get(), snapshotRestorableProperty, userIdentity)); + snapshotRestorableProperty.not().get() || serverRestoreSettingsConsistent.not().get() || + userIdentity.isNull().get(), snapshotRestorableProperty, userIdentity, serverRestoreSettingsConsistent)); + + invalidConfigLabel.visibleProperty().bind(serverRestoreSettingsConsistent.not()); SpinnerValueFactory thresholdSpinnerValueFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 999.0, 0.0, 0.01); thresholdSpinnerValueFactory.setConverter(new DoubleStringConverter()); @@ -505,26 +510,13 @@ public void initialize() { toggleGroup.selectedToggleProperty().addListener((obs, o, n) -> snapshotModeProperty.set((SnapshotMode) n.getUserData())); - restoreFromClient.setUserData(RestoreMode.CLIENT_RESTORE); - restoreFromService.setUserData(RestoreMode.SERVICE_RESTORE); - - String restoreModeString = Preferences.default_restore_mode; - if (restoreModeString == null || restoreModeString.isEmpty()) { + try { + restoreModeProperty.set(RestoreMode.valueOf(Preferences.default_restore_mode.toUpperCase())); + } catch (IllegalArgumentException e) { + LOGGER.log(Level.WARNING, "Unknown restore mode \"" + Preferences.default_restore_mode + "\", defaulting to " + RestoreMode.CLIENT_RESTORE); restoreModeProperty.set(RestoreMode.CLIENT_RESTORE); - } else { - try { - restoreModeProperty.set(RestoreMode.valueOf(restoreModeString)); - } catch (IllegalArgumentException e) { - LOGGER.log(Level.WARNING, "Unknown restore mode \"" + restoreModeString + "\", defaulting to " + RestoreMode.CLIENT_RESTORE); - restoreModeProperty.set(RestoreMode.CLIENT_RESTORE); - } } - - ToggleGroup restoreToggleGroup = new ToggleGroup(); - restoreToggleGroup.getToggles().addAll(restoreFromClient, restoreFromService); - restoreToggleGroup.selectToggle(restoreToggleGroup.getToggles().stream() - .filter(t -> t.getUserData().equals(restoreModeProperty.get())).findFirst().get()); - restoreToggleGroup.selectedToggleProperty().addListener((obs, o, n) -> restoreModeProperty.set((RestoreMode) n.getUserData())); + checkRestoreMode(); snapshotTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN); snapshotTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); @@ -917,7 +909,7 @@ public void loadSnapshot(Node snapshotNode) { selectedColumn.visibleProperty().set(true); tabTitleProperty.setValue(snapshotNode.getName()); tabIdProperty.setValue(snapshotNode.getUniqueId()); - snapshotRestorableProperty.set(true); + snapshotRestorableProperty.setValue(true); setTabImage(snapshotNode); }); updateUi(); @@ -1653,4 +1645,28 @@ public void updateItem(AlarmSeverity alarmSeverity, boolean empty) { } } + + /** + * If preference is set to {@link RestoreMode#SERVICE_RESTORE}, this method will check with + * the service if the current user is authorized to perform server side restore. If not authorized, + * UI elements are updated accordingly. + */ + private void checkRestoreMode(){ + if(restoreModeProperty.get().equals(RestoreMode.CLIENT_RESTORE)){ + serverRestoreSettingsConsistent.setValue(true); + return; + } + + JobManager.schedule("Check server restore authorization", monitor -> { + Optional serverRestoreAuthorizedOptional = saveAndRestoreService.serverRestoreAuthorized(); + serverRestoreSettingsConsistent.setValue(serverRestoreAuthorizedOptional.isPresent() && + serverRestoreAuthorizedOptional.get()); + }); + } + + @Override + public void secureStoreChanged(List validTokens) { + super.secureStoreChanged(validTokens); + checkRestoreMode(); + } } diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties index cf69af6a78..ab92740683 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties @@ -187,6 +187,7 @@ restoreFailed=Restore operation failed restoreFailedPVs=Failed to write the following PVs: restoreFromClient=From client restoreFromService=From service +restoreSettingsInconsistent=User not authorized for server side restore. SaveAndRestore=Save And Restore save=Save saveAsFilter=Save As Filter diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotView.fxml b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotView.fxml index 0202f5bd1b..f7e4fd4036 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotView.fxml +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotView.fxml @@ -5,35 +5,14 @@ This is the contents of the top portion of a snapshot tab. Since tabs are added save-and-restore UI, this fxml does not make use of TabPane and Tab elements. --> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + @@ -154,20 +133,11 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements. - - - - - - - - - - - - - - + @@ -183,7 +153,7 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
- + @@ -264,7 +234,7 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements. - + @@ -292,6 +262,6 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
- +
diff --git a/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties b/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties index f05356604a..e0638592f4 100644 --- a/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties +++ b/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties @@ -33,7 +33,8 @@ default_snapshot_name_date_format= # - `FROM_ARCHIVER`: PV values read from archiver at point in time selected by user default_snapshot_mode=READ_PVS -# Defines the default restore mode. +# Defines the wanted restore mode. If `SERVICE_RESTORE` is selected, +# runtime checks are done to ensure user is authorized to call server side restore. # # - `CLIENT_RESTORE`: the restore operation is performed by the client # - `SERVICE_RESTORE`: the restore operation is performed by the server