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 @@ -31,7 +31,7 @@
import java.util.stream.Collectors;

/**
* Simple app that launches an UI offering logout capabilities for scopes/applications that use and maintain
* Simple app that launches a UI offering logout capabilities for scopes/applications that use and maintain
* credentials, e.g.logbook. This is not in any way associated with the APIs controlling Phoebus internal
* authorizations for the various apps. The credentials in the case of the Credentials Management app are
* typically associated with credentials used to authenticate against external services.
Expand Down Expand Up @@ -64,7 +64,7 @@ public AppInstance create() {
.collect(Collectors.toList());
try {
SecureStore secureStore = new SecureStore();
new CredentialsManagementStage(authenticationProviders, secureStore).show();
new CredentialsManagementDialog(authenticationProviders, secureStore).showAndWait();
} catch (Exception e) {
ExceptionDetailsErrorDialog.openError(Messages.SecureStoreErrorTitle, Messages.SecureStoreErrorBody, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;
import javafx.util.Callback;
Expand Down Expand Up @@ -113,7 +106,7 @@ public class CredentialsManagementController {
*/
private final IntegerProperty loggedInCount = new SimpleIntegerProperty(0);

private Stage stage;
private Dialog dialog;

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

updateTable();

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

}

private void configureCellFactory() {
Expand Down Expand Up @@ -221,7 +210,7 @@ public synchronized void loginToAll() {
login(serviceItem, tableView.getItems().size());
}
if (loggedInCount.get() == tableView.getItems().size()) {
stage.close();
dialog.close();
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to login to all services", e);
Expand All @@ -239,7 +228,7 @@ private synchronized void login(ServiceItem serviceItem, int expectedLoginCount)
if (authenticationResult.equals(AuthenticationStatus.AUTHENTICATED)) {
loggedInCount.set(loggedInCount.get() + 1);
if (expectedLoginCount == loggedInCount.get()) {
stage.close();
dialog.close();
}
}
}
Expand Down Expand Up @@ -406,7 +395,9 @@ public void updateItem(StringProperty item, final boolean empty) {
TextField textField = new TextField();
textField.getStyleClass().add("text-field-styling");
textField.textProperty().bindBidirectional(serviceItem.username);
textField.disableProperty().bind(Bindings.createBooleanBinding(() -> serviceItem.authenticationStatus.get().equals(AuthenticationStatus.AUTHENTICATED),
textField.disableProperty().bind(Bindings.createBooleanBinding(() ->
serviceItem.authenticationStatus.get().equals(AuthenticationStatus.AUTHENTICATED) ||
serviceItem.authenticationStatus.get().equals(AuthenticationStatus.CACHED),
serviceItem.authenticationStatus));
textField.setOnKeyPressed(keyEvent -> {
if (keyEvent.getCode() == KeyCode.ENTER &&
Expand Down Expand Up @@ -477,7 +468,7 @@ protected void updateItem(StringProperty item, final boolean empty) {
}
}

public void setStage(Stage stage) {
this.stage = stage;
public void setDialog(Dialog dialog) {
this.dialog = dialog;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.phoebus.applications.credentialsmanagement;

import javafx.fxml.FXMLLoader;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import org.phoebus.framework.nls.NLS;
import org.phoebus.security.authorization.ServiceAuthenticationProvider;
import org.phoebus.security.store.SecureStore;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link Dialog} for the Credentials Management UI.
*/
public class CredentialsManagementDialog extends Dialog<Void> {

public CredentialsManagementDialog(List<ServiceAuthenticationProvider> authenticationProviders, SecureStore secureStore){
super();

ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setResources(resourceBundle);
URL url = this.getClass().getResource("CredentialsManagement.fxml");
fxmlLoader.setLocation(url);
fxmlLoader.setControllerFactory(clazz -> {
try {
CredentialsManagementController controller =
(CredentialsManagementController) clazz.getConstructor(List.class, SecureStore.class)
.newInstance(authenticationProviders, secureStore);
controller.setDialog(this);
return controller;

} catch (Exception e) {
Logger.getLogger(CredentialsManagementDialog.class.getName()).log(Level.SEVERE, "Failed to construct CredentialsManagementController", e);
}
return null;
});
try {
fxmlLoader.load();
getDialogPane().setContent(fxmlLoader.getRoot());
getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
} catch (Exception exception) {
Logger.getLogger(CredentialsManagementDialog.class.getName()).log(Level.WARNING, "Unable to load fxml for log Credentials Management UI", exception);
}
}
}

This file was deleted.

Loading