From adf1697e16087daf241c3ab6f6f209a98b8c1b33 Mon Sep 17 00:00:00 2001 From: chenkins Date: Mon, 30 Oct 2023 14:15:47 +0100 Subject: [PATCH] Refactoring protocol serialization (#4). --- .../org/cryptomator/hub/api/ConfigResource.java | 14 ++++++-------- .../main/resources/cipherduck/hubbookmark.duck | 15 +++++++++++++-- .../cipherduck/hubprotocol.cyberduckprofile | 16 ---------------- 3 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 backend/src/main/resources/cipherduck/hubprotocol.cyberduckprofile diff --git a/backend/src/main/java/org/cryptomator/hub/api/ConfigResource.java b/backend/src/main/java/org/cryptomator/hub/api/ConfigResource.java index cc5c8f871..ac2fd65fd 100644 --- a/backend/src/main/java/org/cryptomator/hub/api/ConfigResource.java +++ b/backend/src/main/java/org/cryptomator/hub/api/ConfigResource.java @@ -68,19 +68,17 @@ public ConfigDto getConfig() { @Operation(summary = "get cipherduck bookmark for this hub") public String cipherduckhubbookmark(@Context UriInfo uriInfo) throws IOException { final URI requestUri = uriInfo.getRequestUri(); - String profileTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubprotocol.cyberduckprofile").readAllBytes()); + String bookmarkTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubbookmark.duck").readAllBytes()); // Scheme - profileTemplate = profileTemplate.replace("Scheme", String.format("%s", requestUri.getScheme())); + bookmarkTemplate = bookmarkTemplate.replace("Scheme", String.format("%s", requestUri.getScheme())); // N.B. we use client_id="cryptomator" in cipherduck, see discussion https://github.com/chenkins/cipherduck-hub/issues/6 - profileTemplate = profileTemplate.replace("OAuth Client ID", String.format("%s", getConfig().keycloakClientIdCryptomator())); - profileTemplate = profileTemplate.replace("OAuth Authorization Url", String.format("%s", getConfig().authEndpoint())); - profileTemplate = profileTemplate.replace("OAuth Token Url", String.format("%s", getConfig().tokenEndpoint())); + bookmarkTemplate = bookmarkTemplate.replace("OAuth Client ID", String.format("%s", getConfig().keycloakClientIdCryptomator())); + bookmarkTemplate = bookmarkTemplate.replace("OAuth Authorization Url", String.format("%s", getConfig().authEndpoint())); + bookmarkTemplate = bookmarkTemplate.replace("OAuth Token Url", String.format("%s", getConfig().tokenEndpoint())); - - String bookmarkTemplate = new String(ConfigResource.class.getResourceAsStream("/cipherduck/hubbookmark.duck").readAllBytes()); String hubUrl = String.format("%s://%s:%s", requestUri.getScheme(), requestUri.getHost(), requestUri.getPort()); // nickname bookmarkTemplate = bookmarkTemplate.replace("Cipherduck", String.format("Cipherduck (%s)", hubUrl)); @@ -92,7 +90,7 @@ public String cipherduckhubbookmark(@Context UriInfo uriInfo) throws IOException bookmarkTemplate = bookmarkTemplate.replace("c36acf24-e331-4919-9f19-ff52a08e7885", String.format("%s", Settings.get().hubId)); // protocol - bookmarkTemplate = bookmarkTemplate.replace("serialized_protocol/string>", String.format("%s", new String(Base64.getEncoder().encode(profileTemplate.getBytes(StandardCharsets.UTF_8))))); + bookmarkTemplate = bookmarkTemplate.replace("serialized_protocol/string>", String.format("%s", new String(Base64.getEncoder().encode(bookmarkTemplate.getBytes(StandardCharsets.UTF_8))))); diff --git a/backend/src/main/resources/cipherduck/hubbookmark.duck b/backend/src/main/resources/cipherduck/hubbookmark.duck index 755552e00..0a493eeaa 100644 --- a/backend/src/main/resources/cipherduck/hubbookmark.duck +++ b/backend/src/main/resources/cipherduck/hubbookmark.duck @@ -12,7 +12,18 @@ localhost Port 8080 - serialized_protocol - serialized_protocol/string> + Custom + + Protocol + hub + Scheme + Scheme + OAuth Authorization Url + OAuth Authorization Url + OAuth Token Url + OAuth Token Url + OAuth Client ID + OAuth Client ID + \ No newline at end of file diff --git a/backend/src/main/resources/cipherduck/hubprotocol.cyberduckprofile b/backend/src/main/resources/cipherduck/hubprotocol.cyberduckprofile deleted file mode 100644 index 7d458ff35..000000000 --- a/backend/src/main/resources/cipherduck/hubprotocol.cyberduckprofile +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Protocol - hub - Scheme - Scheme - OAuth Authorization Url - OAuth Authorization Url - OAuth Token Url - OAuth Token Url - OAuth Client ID - OAuth Client ID - - \ No newline at end of file