From db0e266fdeaae9b8d1be318dac2519e5d85c4612 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 11 Mar 2026 19:48:37 +0100 Subject: [PATCH] clean up dialog --- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../hub/CheckHostAuthenticityController.java | 20 +++++-- .../keyloading/hub/HubKeyLoadingModule.java | 12 +++++ .../hub/UnauthorizedHostController.java | 34 ++++++++++++ .../fxml/hub_check_host_authenticity.fxml | 17 +++++- .../resources/fxml/hub_unauthorized_host.fxml | 52 +++++++++++++++++++ src/main/resources/i18n/strings.properties | 3 ++ 7 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedHostController.java create mode 100644 src/main/resources/fxml/hub_unauthorized_host.fxml diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 68bf2adff..b5ffa9fb4 100644 --- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -30,6 +30,7 @@ public enum FxmlFile { HUB_REGISTER_FAILED("/fxml/hub_register_failed.fxml"), // HUB_REGISTER_DEVICE("/fxml/hub_register_device.fxml"), // HUB_UNAUTHORIZED_DEVICE("/fxml/hub_unauthorized_device.fxml"), // + HUB_UNAUTHORIZED_HOST("/fxml/hub_unauthorized_host.fxml"), // HUB_REQUIRE_ACCOUNT_INIT("/fxml/hub_require_account_init.fxml"), // LOCK_FORCED("/fxml/lock_forced.fxml"), // LOCK_FAILED("/fxml/lock_failed.fxml"), // diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostAuthenticityController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostAuthenticityController.java index 31f94ce78..5b1666469 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostAuthenticityController.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostAuthenticityController.java @@ -14,7 +14,8 @@ import javax.inject.Inject; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.Scene; -import javafx.scene.control.ListView; +import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; import javafx.stage.Stage; import java.net.URI; import java.util.Arrays; @@ -31,18 +32,20 @@ public class CheckHostAuthenticityController implements FxController { private final Stage window; private final HubConfig hubConfig; private final Lazy authFlowScene; + private final Lazy unauthorizedHostScene; private final CompletableFuture result; private final Settings settings; private final Set hostnames; @FXML - private ListView hostnamesList; + private TextFlow hostnamesFlow; @Inject - public CheckHostAuthenticityController(@KeyLoading Stage window, HubConfig hubConfig, @FxmlScene(FxmlFile.HUB_AUTH_FLOW) Lazy authFlowScene, CompletableFuture result, Settings settings) { + public CheckHostAuthenticityController(@KeyLoading Stage window, HubConfig hubConfig, @FxmlScene(FxmlFile.HUB_AUTH_FLOW) Lazy authFlowScene, @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_HOST) Lazy unauthorizedHostScene, CompletableFuture result, Settings settings) { this.window = window; this.hubConfig = hubConfig; this.authFlowScene = authFlowScene; + this.unauthorizedHostScene = unauthorizedHostScene; this.result = result; this.settings = settings; this.hostnames = new HashSet<>(); @@ -62,7 +65,7 @@ public class CheckHostAuthenticityController implements FxController { trust(); } else if (Boolean.getBoolean("cryptomator.allowUnknownHubHosts")) { hostnames.addAll(List.of(authUri.getAuthority(), tokenUri.getAuthority(), apiBaseUri.getAuthority(), webappBaseUri.getAuthority())); - hostnamesList.getItems().addAll(hostnames); + renderHostnames(); } else { LOG.warn("Cryptomator is not allowed to connect to {}. Check your cryptomator.allowedHubHosts config.", webappBaseUri); Platform.runLater(this::deny); @@ -78,7 +81,14 @@ public class CheckHostAuthenticityController implements FxController { @FXML public void deny() { result.cancel(true); - window.close(); // TODO: show "denied" scene with explanation and "learn more" link to documentation + window.setScene(unauthorizedHostScene.get()); + } + + private void renderHostnames() { + hostnamesFlow.getChildren().clear(); + hostnames.stream().sorted().forEach(hostname -> { + hostnamesFlow.getChildren().add(new Text(hostname + System.lineSeparator())); + }); } private boolean isConsistentHubConfig() { diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java index f5d5cf55f..9aa4b8d5e 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java @@ -175,6 +175,13 @@ public abstract class HubKeyLoadingModule { return fxmlLoaders.createScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE); } + @Provides + @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_HOST) + @KeyLoadingScoped + static Scene provideHubUnauthorizedHostScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.HUB_UNAUTHORIZED_HOST); + } + @Provides @FxmlScene(FxmlFile.HUB_REQUIRE_ACCOUNT_INIT) @KeyLoadingScoped @@ -237,6 +244,11 @@ public abstract class HubKeyLoadingModule { @FxControllerKey(UnauthorizedDeviceController.class) abstract FxController bindUnauthorizedDeviceController(UnauthorizedDeviceController controller); + @Binds + @IntoMap + @FxControllerKey(UnauthorizedHostController.class) + abstract FxController bindUnauthorizedHostController(UnauthorizedHostController controller); + @Binds @IntoMap @FxControllerKey(RequireAccountInitController.class) diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedHostController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedHostController.java new file mode 100644 index 000000000..c6b67b330 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedHostController.java @@ -0,0 +1,34 @@ +package org.cryptomator.ui.keyloading.hub; + +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.keyloading.KeyLoading; +import org.cryptomator.ui.keyloading.KeyLoadingScoped; + +import javax.inject.Inject; +import javafx.fxml.FXML; +import javafx.stage.Stage; +import javafx.stage.WindowEvent; +import java.util.concurrent.CompletableFuture; + +@KeyLoadingScoped +public class UnauthorizedHostController implements FxController { + + private final Stage window; + private final CompletableFuture result; + + @Inject + public UnauthorizedHostController(@KeyLoading Stage window, CompletableFuture result) { + this.window = window; + this.result = result; + this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed); + } + + @FXML + public void close() { + window.close(); + } + + private void windowClosed(WindowEvent windowEvent) { + result.cancel(true); + } +} diff --git a/src/main/resources/fxml/hub_check_host_authenticity.fxml b/src/main/resources/fxml/hub_check_host_authenticity.fxml index 1cbf039d4..b14089e18 100644 --- a/src/main/resources/fxml/hub_check_host_authenticity.fxml +++ b/src/main/resources/fxml/hub_check_host_authenticity.fxml @@ -1,13 +1,17 @@ + - + + + + + + + + + + + + +