Skip to content

Commit a4bd6c6

Browse files
authored
Merge pull request #3856 from ControlSystemStudio/CSSTUDIO-2669
Converted Credentials Management UI to Dialog
2 parents e4a4802 + 2e3e0ed commit a4bd6c6

4 files changed

Lines changed: 61 additions & 90 deletions

File tree

app/credentials-management/src/main/java/org/phoebus/applications/credentialsmanagement/CredentialsManagementApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.stream.Collectors;
3232

3333
/**
34-
* Simple app that launches an UI offering logout capabilities for scopes/applications that use and maintain
34+
* Simple app that launches a UI offering logout capabilities for scopes/applications that use and maintain
3535
* credentials, e.g.logbook. This is not in any way associated with the APIs controlling Phoebus internal
3636
* authorizations for the various apps. The credentials in the case of the Credentials Management app are
3737
* typically associated with credentials used to authenticate against external services.
@@ -64,7 +64,7 @@ public AppInstance create() {
6464
.collect(Collectors.toList());
6565
try {
6666
SecureStore secureStore = new SecureStore();
67-
new CredentialsManagementStage(authenticationProviders, secureStore).show();
67+
new CredentialsManagementDialog(authenticationProviders, secureStore).showAndWait();
6868
} catch (Exception e) {
6969
ExceptionDetailsErrorDialog.openError(Messages.SecureStoreErrorTitle, Messages.SecureStoreErrorBody, e);
7070
}

app/credentials-management/src/main/java/org/phoebus/applications/credentialsmanagement/CredentialsManagementController.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@
3232
import javafx.event.ActionEvent;
3333
import javafx.fxml.FXML;
3434
import javafx.scene.Node;
35-
import javafx.scene.control.Button;
36-
import javafx.scene.control.Label;
37-
import javafx.scene.control.PasswordField;
38-
import javafx.scene.control.TableCell;
39-
import javafx.scene.control.TableColumn;
40-
import javafx.scene.control.TableView;
41-
import javafx.scene.control.TextField;
42-
import javafx.scene.control.Tooltip;
35+
import javafx.scene.control.*;
4336
import javafx.scene.input.KeyCode;
4437
import javafx.stage.Stage;
4538
import javafx.util.Callback;
@@ -113,7 +106,7 @@ public class CredentialsManagementController {
113106
*/
114107
private final IntegerProperty loggedInCount = new SimpleIntegerProperty(0);
115108

116-
private Stage stage;
109+
private Dialog dialog;
117110

118111
public CredentialsManagementController(List<ServiceAuthenticationProvider> authenticationProviders, SecureStore secureStore) {
119112
this.authenticationProviders = authenticationProviders;
@@ -152,10 +145,6 @@ public void initialize() {
152145

153146
updateTable();
154147

155-
// Don't want focus on the username field for "login to all" as that obscures the prompt.
156-
// Let table request focus.
157-
Platform.runLater(() -> tableView.requestFocus());
158-
159148
}
160149

161150
private void configureCellFactory() {
@@ -221,7 +210,7 @@ public synchronized void loginToAll() {
221210
login(serviceItem, tableView.getItems().size());
222211
}
223212
if (loggedInCount.get() == tableView.getItems().size()) {
224-
stage.close();
213+
dialog.close();
225214
}
226215
} catch (Exception e) {
227216
LOGGER.log(Level.WARNING, "Failed to login to all services", e);
@@ -239,7 +228,7 @@ private synchronized void login(ServiceItem serviceItem, int expectedLoginCount)
239228
if (authenticationResult.equals(AuthenticationStatus.AUTHENTICATED)) {
240229
loggedInCount.set(loggedInCount.get() + 1);
241230
if (expectedLoginCount == loggedInCount.get()) {
242-
stage.close();
231+
dialog.close();
243232
}
244233
}
245234
}
@@ -406,7 +395,9 @@ public void updateItem(StringProperty item, final boolean empty) {
406395
TextField textField = new TextField();
407396
textField.getStyleClass().add("text-field-styling");
408397
textField.textProperty().bindBidirectional(serviceItem.username);
409-
textField.disableProperty().bind(Bindings.createBooleanBinding(() -> serviceItem.authenticationStatus.get().equals(AuthenticationStatus.AUTHENTICATED),
398+
textField.disableProperty().bind(Bindings.createBooleanBinding(() ->
399+
serviceItem.authenticationStatus.get().equals(AuthenticationStatus.AUTHENTICATED) ||
400+
serviceItem.authenticationStatus.get().equals(AuthenticationStatus.CACHED),
410401
serviceItem.authenticationStatus));
411402
textField.setOnKeyPressed(keyEvent -> {
412403
if (keyEvent.getCode() == KeyCode.ENTER &&
@@ -477,7 +468,7 @@ protected void updateItem(StringProperty item, final boolean empty) {
477468
}
478469
}
479470

480-
public void setStage(Stage stage) {
481-
this.stage = stage;
471+
public void setDialog(Dialog dialog) {
472+
this.dialog = dialog;
482473
}
483474
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.phoebus.applications.credentialsmanagement;
2+
3+
import javafx.fxml.FXMLLoader;
4+
import javafx.scene.control.ButtonType;
5+
import javafx.scene.control.Dialog;
6+
import org.phoebus.framework.nls.NLS;
7+
import org.phoebus.security.authorization.ServiceAuthenticationProvider;
8+
import org.phoebus.security.store.SecureStore;
9+
10+
import java.net.URL;
11+
import java.util.List;
12+
import java.util.ResourceBundle;
13+
import java.util.logging.Level;
14+
import java.util.logging.Logger;
15+
16+
/**
17+
* {@link Dialog} for the Credentials Management UI.
18+
*/
19+
public class CredentialsManagementDialog extends Dialog<Void> {
20+
21+
public CredentialsManagementDialog(List<ServiceAuthenticationProvider> authenticationProviders, SecureStore secureStore){
22+
super();
23+
24+
ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
25+
FXMLLoader fxmlLoader = new FXMLLoader();
26+
fxmlLoader.setResources(resourceBundle);
27+
URL url = this.getClass().getResource("CredentialsManagement.fxml");
28+
fxmlLoader.setLocation(url);
29+
fxmlLoader.setControllerFactory(clazz -> {
30+
try {
31+
CredentialsManagementController controller =
32+
(CredentialsManagementController) clazz.getConstructor(List.class, SecureStore.class)
33+
.newInstance(authenticationProviders, secureStore);
34+
controller.setDialog(this);
35+
return controller;
36+
37+
} catch (Exception e) {
38+
Logger.getLogger(CredentialsManagementDialog.class.getName()).log(Level.SEVERE, "Failed to construct CredentialsManagementController", e);
39+
}
40+
return null;
41+
});
42+
try {
43+
fxmlLoader.load();
44+
getDialogPane().setContent(fxmlLoader.getRoot());
45+
getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
46+
} catch (Exception exception) {
47+
Logger.getLogger(CredentialsManagementDialog.class.getName()).log(Level.WARNING, "Unable to load fxml for log Credentials Management UI", exception);
48+
}
49+
}
50+
}

app/credentials-management/src/main/java/org/phoebus/applications/credentialsmanagement/CredentialsManagementStage.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)