diff --git a/src/main/java/qupath/ext/omero/core/WebClients.java b/src/main/java/qupath/ext/omero/core/WebClients.java index 36db1a5..0d4330f 100644 --- a/src/main/java/qupath/ext/omero/core/WebClients.java +++ b/src/main/java/qupath/ext/omero/core/WebClients.java @@ -68,6 +68,10 @@ public static CompletableFuture createClient(String url, WebClient.Au return WebClient.create(serverURI.get(), authentication, args).thenApply(client -> { if (client.getStatus().equals(WebClient.Status.SUCCESS)) { ClientsPreferencesManager.addURI(client.getApisHandler().getWebServerURI()); + ClientsPreferencesManager.setEnableUnauthenticated(client.getApisHandler().getWebServerURI(), switch (authentication) { + case ENFORCE -> false; + case TRY_TO_SKIP, SKIP -> true; + }); updateClients(client, Operation.ADD); } clientsBeingCreated.remove(serverURI.get()); diff --git a/src/main/java/qupath/ext/omero/core/imageserver/OmeroImageServerBuilder.java b/src/main/java/qupath/ext/omero/core/imageserver/OmeroImageServerBuilder.java index 0576a28..2ac676c 100644 --- a/src/main/java/qupath/ext/omero/core/imageserver/OmeroImageServerBuilder.java +++ b/src/main/java/qupath/ext/omero/core/imageserver/OmeroImageServerBuilder.java @@ -2,6 +2,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import qupath.ext.omero.core.ClientsPreferencesManager; import qupath.lib.images.servers.ImageServer; import qupath.lib.images.servers.ImageServerBuilder; import qupath.ext.omero.core.WebClient; @@ -84,7 +85,12 @@ public boolean matchClassName(String... classNames) { private static Optional getClientAndCheckURIReachable(URI uri, String... args) { try { if (RequestSender.isLinkReachableWithGet(uri).get()) { - WebClient client = WebClients.createClientSync(uri.toString(), WebClient.Authentication.TRY_TO_SKIP, args); + WebClient client = WebClients.createClientSync( + uri.toString(), + ClientsPreferencesManager.getEnableUnauthenticated(uri).orElse(true) ? WebClient.Authentication.TRY_TO_SKIP : WebClient.Authentication.ENFORCE, + args + ); + if (client.getStatus().equals(WebClient.Status.SUCCESS)) { return Optional.of(client); } else { diff --git a/src/main/java/qupath/ext/omero/gui/browser/newserver/NewServerForm.java b/src/main/java/qupath/ext/omero/gui/browser/newserver/NewServerForm.java index 48dd694..59abf66 100644 --- a/src/main/java/qupath/ext/omero/gui/browser/newserver/NewServerForm.java +++ b/src/main/java/qupath/ext/omero/gui/browser/newserver/NewServerForm.java @@ -8,6 +8,8 @@ import qupath.ext.omero.gui.UiUtilities; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; /** * Window that provides an input allowing the user to write a server URL. @@ -27,7 +29,16 @@ public class NewServerForm extends VBox { public NewServerForm() throws IOException { UiUtilities.loadFXML(this, NewServerForm.class.getResource("new_server_form.fxml")); - url.setText(ClientsPreferencesManager.getLastServerURI()); + String lastURI = ClientsPreferencesManager.getLastServerURI(); + url.setText(lastURI); + + boolean skipAuthentication = true; + try { + skipAuthentication = ClientsPreferencesManager.getEnableUnauthenticated(new URI(lastURI)).orElse(true); + } catch (URISyntaxException ignored) { + // Nothing happens if the last URI is not valid + } + this.skipAuthentication.setSelected(skipAuthentication); } /** diff --git a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/BrowserCommand.java b/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/BrowserCommand.java index 32bda73..c5c9043 100644 --- a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/BrowserCommand.java +++ b/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/BrowserCommand.java @@ -4,10 +4,10 @@ import javafx.collections.ListChangeListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import qupath.ext.omero.core.ClientsPreferencesManager; 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; @@ -67,53 +67,39 @@ public void run() { 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); - } - - boolean dialogConfirmed = newConnectionOptions != null && Dialogs.showConfirmDialog( - resources.getString("Browser.NewConnectionOptions.title"), - newConnectionOptions - ); - - if (dialogConfirmed) { - WebClients.createClient( - uri.toString(), - newConnectionOptions.canSkipAuthentication() ? WebClient.Authentication.TRY_TO_SKIP : WebClient.Authentication.ENFORCE - ).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 failReason = client.getFailReason(); - String message = null; + WebClients.createClient( + uri.toString(), + ClientsPreferencesManager.getEnableUnauthenticated(uri).orElse(true) ? WebClient.Authentication.TRY_TO_SKIP : WebClient.Authentication.ENFORCE + ).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 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 (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 - ); - } + if (message != null) { + Dialogs.showErrorMessage( + resources.getString("Browser.BrowserCommand.webServer"), + message + ); } - })); - } + } + })); } } else { UiUtilities.showWindow(browser); diff --git a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/NewConnectionOptions.java b/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/NewConnectionOptions.java deleted file mode 100644 index 3d2d1f6..0000000 --- a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/NewConnectionOptions.java +++ /dev/null @@ -1,34 +0,0 @@ -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(); - } -} - diff --git a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/package-info.java b/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/package-info.java deleted file mode 100644 index 2271ce0..0000000 --- a/src/main/java/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - *

This package provides a form to prompt the user for parameters before attempting to create a connection to a server.

- *

This is handled by {@link qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions.NewConnectionOptions NewConnectionOptions}.

- */ -package qupath.ext.omero.gui.browser.serverbrowser.newconnectionoptions; \ No newline at end of file diff --git a/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/Connection.java b/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/Connection.java index f4819df..0a407e9 100644 --- a/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/Connection.java +++ b/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/Connection.java @@ -6,6 +6,7 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.TitledPane; import javafx.scene.layout.HBox; @@ -63,6 +64,8 @@ public class Connection extends VBox { @FXML private Button remove; @FXML + private CheckBox skipAuthentication; + @FXML private TitledPane imagesPane; @FXML private VBox imagesContainer; @@ -115,33 +118,19 @@ private void onBrowseClicked(ActionEvent ignoredEvent) { @FXML private void onConnectClicked(ActionEvent ignoredEvent) { - NewConnectionOptions newConnectionOptions = null; - try { - newConnectionOptions = new NewConnectionOptions(); - } catch (IOException e) { - logger.error("Error when creating the new connection options form", e); - } - - boolean dialogConfirmed = newConnectionOptions != null && Dialogs.showConfirmDialog( - resources.getString("ConnectionsManager.NewConnectionOptions.title"), - newConnectionOptions - ); - - if (dialogConfirmed) { - WebClients.createClient( - serverURI.toString(), - newConnectionOptions.canSkipAuthentication() ? WebClient.Authentication.TRY_TO_SKIP : WebClient.Authentication.ENFORCE - ).thenAccept(client -> Platform.runLater(() -> { - if (client.getStatus().equals(WebClient.Status.SUCCESS)) { - Dialogs.showInfoNotification( - resources.getString("ConnectionsManager.Connection.webServer"), - MessageFormat.format(resources.getString("ConnectionsManager.Connection.connectedTo"), serverURI.toString()) - ); - } else if (client.getStatus().equals(WebClient.Status.FAILED)) { - showConnectionError(serverURI.toString(), client.getFailReason().orElse(null)); - } - })); - } + WebClients.createClient( + serverURI.toString(), + skipAuthentication.isSelected() ? WebClient.Authentication.TRY_TO_SKIP : WebClient.Authentication.ENFORCE + ).thenAccept(client -> Platform.runLater(() -> { + if (client.getStatus().equals(WebClient.Status.SUCCESS)) { + Dialogs.showInfoNotification( + resources.getString("ConnectionsManager.Connection.webServer"), + MessageFormat.format(resources.getString("ConnectionsManager.Connection.connectedTo"), serverURI.toString()) + ); + } else if (client.getStatus().equals(WebClient.Status.FAILED)) { + showConnectionError(serverURI.toString(), client.getFailReason().orElse(null)); + } + })); } @FXML @@ -234,6 +223,11 @@ private void onRemoveClicked(ActionEvent ignoredEvent) { } } + @FXML + private void onSkipAuthenticationClicked(ActionEvent ignoredEvent) { + ClientsPreferencesManager.setEnableUnauthenticated(serverURI, skipAuthentication.isSelected()); + } + private void initUI() throws IOException { UiUtilities.loadFXML(this, Connection.class.getResource("connection.fxml")); @@ -262,6 +256,8 @@ private void initUI() throws IOException { imagesContainer.getChildren().add(new Image(client, uri)); } } + + skipAuthentication.setSelected(ClientsPreferencesManager.getEnableUnauthenticated(serverURI).orElse(true)); } private void setUpListeners() { diff --git a/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/NewConnectionOptions.java b/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/NewConnectionOptions.java deleted file mode 100644 index 7001b7a..0000000 --- a/src/main/java/qupath/ext/omero/gui/connectionsmanager/connection/NewConnectionOptions.java +++ /dev/null @@ -1,33 +0,0 @@ -package qupath.ext.omero.gui.connectionsmanager.connection; - -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. - */ -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(); - } -} diff --git a/src/main/resources/qupath/ext/omero/gui/browser/newserver/new_server_form.fxml b/src/main/resources/qupath/ext/omero/gui/browser/newserver/new_server_form.fxml index 2290ac5..af8f754 100644 --- a/src/main/resources/qupath/ext/omero/gui/browser/newserver/new_server_form.fxml +++ b/src/main/resources/qupath/ext/omero/gui/browser/newserver/new_server_form.fxml @@ -17,7 +17,7 @@ - + diff --git a/src/main/resources/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/new_connection_options.fxml b/src/main/resources/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/new_connection_options.fxml deleted file mode 100644 index c9af6b3..0000000 --- a/src/main/resources/qupath/ext/omero/gui/browser/serverbrowser/newconnectionoptions/new_connection_options.fxml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/connection.fxml b/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/connection.fxml index 16b7bfb..e518917 100644 --- a/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/connection.fxml +++ b/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/connection.fxml @@ -2,6 +2,7 @@ + @@ -45,6 +46,7 @@ + diff --git a/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/new_connection_options.fxml b/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/new_connection_options.fxml deleted file mode 100644 index f851431..0000000 --- a/src/main/resources/qupath/ext/omero/gui/connectionsmanager/connection/new_connection_options.fxml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/main/resources/qupath/ext/omero/strings.properties b/src/main/resources/qupath/ext/omero/strings.properties index 2c1f761..3b7419f 100644 --- a/src/main/resources/qupath/ext/omero/strings.properties +++ b/src/main/resources/qupath/ext/omero/strings.properties @@ -105,9 +105,6 @@ 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: @@ -313,14 +310,12 @@ ConnectionsManager.Connection.connectDescription = Attempt to connect to this se ConnectionsManager.Connection.disconnect = Disconnect ConnectionsManager.Connection.disconnectDescription = Disconnect from this server ConnectionsManager.Connection.removeDescription = Close the connection to this server and remove it from this list +ConnectionsManager.Connection.skipAuthentication = Enable logging in as a public user ConnectionsManager.Connection.noImage = 0 image ConnectionsManager.Connection.loginSuccessful = Login successful: {0} ("{1}") ConnectionsManager.Connection.logoutSuccessful = Log out successful ConnectionsManager.Connection.logoutSuccessfulButNoUnauthenticated = Log out successful, but creating an unauthenticated connection to this server failed -ConnectionsManager.NewConnectionOptions.title = New connection -ConnectionsManager.NewConnectionOptions.skipAuthentication = Enable logging in as a public user - ConnectionsManager.ConnectionManager.noClients = No clients ConnectionsManager.ConnectionManager.webClients = Web clients diff --git a/src/main/resources/qupath/ext/omero/strings_fr.properties b/src/main/resources/qupath/ext/omero/strings_fr.properties index 56d2c5b..193036b 100644 --- a/src/main/resources/qupath/ext/omero/strings_fr.properties +++ b/src/main/resources/qupath/ext/omero/strings_fr.properties @@ -105,9 +105,6 @@ 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: @@ -313,14 +310,12 @@ ConnectionsManager.Connection.connectDescription = Tente de se connecter à ce s ConnectionsManager.Connection.disconnect = Se déconnecter ConnectionsManager.Connection.disconnectDescription = Se déconnecter de ce serveur ConnectionsManager.Connection.removeDescription = Se déconnecter de ce serveur et le supprimer de cette liste +ConnectionsManager.Connection.skipAuthentication = Est-ce qu'il faut passer l'authentification si le serveur le permet ConnectionsManager.Connection.noImage = 0 image ConnectionsManager.Connection.loginSuccessful = Connexion réussie: {0} ("{1}") ConnectionsManager.Connection.logoutSuccessful = Déconnection du compte actuel réussie ConnectionsManager.Connection.logoutSuccessfulButNoUnauthenticated = Déconnection du compte actuel réussie, mais la création d'une connexion non authentifiée à ce serveur a échoué -ConnectionsManager.NewConnectionOptions.title = Nouvelle connection -ConnectionsManager.NewConnectionOptions.skipAuthentication = Est-ce qu'il faut passer l'authentification si le serveur le permet - ConnectionsManager.ConnectionManager.noClients = Aucun client ConnectionsManager.ConnectionManager.webClients = Clients Web