Skip to content
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

Prompt user to skip authentication when opening browser #8

Merged
merged 1 commit into from
Feb 15, 2024
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 @@ -7,6 +7,7 @@
import qupath.ext.omero.core.WebClient;
import qupath.ext.omero.core.WebClients;
import qupath.ext.omero.gui.UiUtilities;
import qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions.NewConnectionOptions;
import qupath.fx.dialogs.Dialogs;

import java.io.IOException;
Expand Down Expand Up @@ -54,36 +55,63 @@ public BrowserCommand(URI uri) {
@Override
public void run() {
if (browser == null) {
WebClients.createClient(uri.toString(), true).thenAccept(client -> Platform.runLater(() -> {
if (client.getStatus().equals(WebClient.Status.SUCCESS)) {
try {
browser = new Browser(client);
this.client = client;
} catch (IOException e) {
logger.error("Error while creating the browser", e);
}
} else if (client.getStatus().equals(WebClient.Status.FAILED)) {
Optional<WebClient.FailReason> failReason = client.getFailReason();
String message = null;
Optional<WebClient> existingClient = WebClients.getClients().stream()
.filter(client -> client.getApisHandler().getWebServerURI().equals(uri))
.findAny();

if (failReason.isPresent()) {
if (failReason.get().equals(WebClient.FailReason.INVALID_URI_FORMAT)) {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.invalidURI"), uri.toString());
} else if (failReason.get().equals(WebClient.FailReason.ALREADY_CREATING)) {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.alreadyCreating"), uri.toString());
}
} else {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.connectionFailed"), uri.toString());
}
if (existingClient.isPresent()) {
try {
browser = new Browser(existingClient.get());
this.client = existingClient.get();
} catch (IOException e) {
logger.error("Error while creating the browser", e);
}
} else {
NewConnectionOptions newConnectionOptions = null;
try {
newConnectionOptions = new NewConnectionOptions();
} catch (IOException e) {
logger.error("Error when creating the new connection options form", e);
}

if (message != null) {
Dialogs.showErrorMessage(
resources.getString("Browser.BrowserCommand.webServer"),
message
);
}
boolean dialogConfirmed = newConnectionOptions != null && Dialogs.showConfirmDialog(
resources.getString("Browser.NewConnectionOptions.title"),
newConnectionOptions
);

if (dialogConfirmed) {
WebClients.createClient(uri.toString(), newConnectionOptions.canSkipAuthentication()).thenAccept(client -> Platform.runLater(() -> {
if (client.getStatus().equals(WebClient.Status.SUCCESS)) {
try {
browser = new Browser(client);
this.client = client;
} catch (IOException e) {
logger.error("Error while creating the browser", e);
}
} else if (client.getStatus().equals(WebClient.Status.FAILED)) {
Optional<WebClient.FailReason> failReason = client.getFailReason();
String message = null;

if (failReason.isPresent()) {
if (failReason.get().equals(WebClient.FailReason.INVALID_URI_FORMAT)) {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.invalidURI"), uri.toString());
} else if (failReason.get().equals(WebClient.FailReason.ALREADY_CREATING)) {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.alreadyCreating"), uri.toString());
}
} else {
message = MessageFormat.format(resources.getString("Browser.BrowserCommand.connectionFailed"), uri.toString());
}

if (message != null) {
Dialogs.showErrorMessage(
resources.getString("Browser.BrowserCommand.webServer"),
message
);
}
}
}));
}
}));
}
} else {
UiUtilities.showWindow(browser);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions;

import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.VBox;
import qupath.ext.omero.gui.UiUtilities;

import java.io.IOException;

/**
* A form to prompt the user for parameters before attempting to create a connection to a server.
*/
public class NewConnectionOptions extends VBox {

@FXML
private CheckBox skipAuthentication;

/**
* Creates the new connection options form.
*
* @throws IOException if an error occurs while creating the form
*/
public NewConnectionOptions() throws IOException {
UiUtilities.loadFXML(this, NewConnectionOptions.class.getResource("new_connection_options.fxml"));
}

/**
* @return whether to try skipping authentication when connecting to the server
*/
public boolean canSkipAuthentication() {
return skipAuthentication.isSelected();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* <p>This package provides a form to prompt the user for parameters before attempting to create a connection to a server.</p>
* <p>This is handled by {@link qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions.NewConnectionOptions NewConnectionOptions}.</p>
*/
package qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.VBox?>

<fx:root alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="5.0" stylesheets="@../../../../styles.css" type="VBox" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<CheckBox fx:id="skipAuthentication" mnemonicParsing="false" selected="true" text="%Browser.NewConnectionOptions.skipAuthentication">
<tooltip>
<Tooltip text="%Browser.NewConnectionOptions.skipAuthentication" />
</tooltip>
</CheckBox>
</fx:root>
3 changes: 3 additions & 0 deletions src/main/resources/qupath/ext/omero/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Browser.BrowserCommand.alreadyCreating = A connection to {0} is already being es
Browser.BrowserCommand.connectionFailed = Connection to {0} failed.\n\nCheck the following:\n- Valid credentials.\n- Access permission.\n- Correct URL.
Browser.BrowserCommand.webServer = Web server

Browser.NewConnectionOptions.title = New connection
Browser.NewConnectionOptions.skipAuthentication = Enable logging in as a public user

Browser.ServerBrowser.omeroWebServer = OMERO web server
Browser.ServerBrowser.server = Server:
Browser.ServerBrowser.username = Username:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/qupath/ext/omero/strings_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Browser.BrowserCommand.alreadyCreating = Une connection vers {0} est déjà en t
Browser.BrowserCommand.connectionFailed = Impossible de se connecter à {0}.\n\nVérifiez les informations suivantes:\n- Identifiants valides.\n- Droits d'accès.\n- URL correcte.
Browser.BrowserCommand.webServer = Serveur web

Browser.NewConnectionOptions.title = Nouvelle connection
Browser.NewConnectionOptions.skipAuthentication = Est-ce qu'il faut passer l'authentification si le serveur le permet

Browser.ServerBrowser.omeroWebServer = Serveur web OMERO
Browser.ServerBrowser.server = Serveur:
Browser.ServerBrowser.username = Nom d'utilisateur:
Expand Down
Loading