From 55bb4a4508ef73f744617f5da19d1f48071cc037 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 19 Dec 2023 17:15:45 +0100 Subject: [PATCH] refactor: PR comment: use shared ApplicationAuthManager for Voice & Verification --- ...ationAuthManager.java => ApplicationAuthManager.java} | 4 ++-- .../sdk/auth/adapters/VoiceApplicationAuthManager.java | 9 --------- .../verification/adapters/VerificationService.java | 4 ++-- .../sinch/sdk/domains/voice/adapters/VoiceService.java | 4 ++-- ...hManagerTest.java => ApplicationAuthManagerTest.java} | 4 ++-- 5 files changed, 8 insertions(+), 17 deletions(-) rename client/src/main/com/sinch/sdk/auth/adapters/{VerificationApplicationAuthManager.java => ApplicationAuthManager.java} (95%) delete mode 100644 client/src/main/com/sinch/sdk/auth/adapters/VoiceApplicationAuthManager.java rename client/src/test/java/com/sinch/sdk/auth/adapters/{VerificationApplicationAuthManagerTest.java => ApplicationAuthManagerTest.java} (93%) diff --git a/client/src/main/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManager.java b/client/src/main/com/sinch/sdk/auth/adapters/ApplicationAuthManager.java similarity index 95% rename from client/src/main/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManager.java rename to client/src/main/com/sinch/sdk/auth/adapters/ApplicationAuthManager.java index 4fa13cdd..ee0d53c1 100644 --- a/client/src/main/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManager.java +++ b/client/src/main/com/sinch/sdk/auth/adapters/ApplicationAuthManager.java @@ -17,14 +17,14 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -public class VerificationApplicationAuthManager implements AuthManager { +public class ApplicationAuthManager implements AuthManager { private static final String AUTH_KEYWORD = "Application"; private static final String XTIMESTAMP_HEADER = "x-timestamp"; private final String key; private final byte[] secret; - public VerificationApplicationAuthManager(String key, String base64Secret) { + public ApplicationAuthManager(String key, String base64Secret) { this.key = key; this.secret = Base64.getDecoder().decode(base64Secret); } diff --git a/client/src/main/com/sinch/sdk/auth/adapters/VoiceApplicationAuthManager.java b/client/src/main/com/sinch/sdk/auth/adapters/VoiceApplicationAuthManager.java deleted file mode 100644 index abc2e9c3..00000000 --- a/client/src/main/com/sinch/sdk/auth/adapters/VoiceApplicationAuthManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sinch.sdk.auth.adapters; - -// Voice and Verification are sharing same authentication mechanism -public class VoiceApplicationAuthManager extends VerificationApplicationAuthManager { - - public VoiceApplicationAuthManager(String key, String base64Secret) { - super(key, base64Secret); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java index e8c48736..64aa550d 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java @@ -1,7 +1,7 @@ package com.sinch.sdk.domains.verification.adapters; +import com.sinch.sdk.auth.adapters.ApplicationAuthManager; import com.sinch.sdk.auth.adapters.BasicAuthManager; -import com.sinch.sdk.auth.adapters.VerificationApplicationAuthManager; import com.sinch.sdk.core.exceptions.ApiAuthException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; @@ -46,7 +46,7 @@ public VerificationService(Configuration configuration, HttpClient httpClient) { private void setApplicationCredentials(String key, String secret) { AuthManager basicAuthManager = new BasicAuthManager(key, secret); - AuthManager applicationAuthManager = new VerificationApplicationAuthManager(key, secret); + AuthManager applicationAuthManager = new ApplicationAuthManager(key, secret); boolean useApplicationAuth = true; // to handle request from client we can only have "Basic" keyword behind the auth managers diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java index b2e8e5e7..7876a1c6 100644 --- a/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java +++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java @@ -1,6 +1,6 @@ package com.sinch.sdk.domains.voice.adapters; -import com.sinch.sdk.auth.adapters.VoiceApplicationAuthManager; +import com.sinch.sdk.auth.adapters.ApplicationAuthManager; import com.sinch.sdk.core.exceptions.ApiAuthException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; @@ -36,7 +36,7 @@ public VoiceService(Configuration configuration, HttpClient httpClient) { private void setApplicationCredentials(String key, String secret) { - AuthManager applicationAuthManager = new VoiceApplicationAuthManager(key, secret); + AuthManager applicationAuthManager = new ApplicationAuthManager(key, secret); clientAuthManagers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); clientAuthManagers.put(SECURITY_SCHEME_KEYWORD, applicationAuthManager); diff --git a/client/src/test/java/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManagerTest.java b/client/src/test/java/com/sinch/sdk/auth/adapters/ApplicationAuthManagerTest.java similarity index 93% rename from client/src/test/java/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManagerTest.java rename to client/src/test/java/com/sinch/sdk/auth/adapters/ApplicationAuthManagerTest.java index 49e62adb..fccb1631 100644 --- a/client/src/test/java/com/sinch/sdk/auth/adapters/VerificationApplicationAuthManagerTest.java +++ b/client/src/test/java/com/sinch/sdk/auth/adapters/ApplicationAuthManagerTest.java @@ -16,13 +16,13 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; -class VerificationApplicationAuthManagerTest { +class ApplicationAuthManagerTest { static final String KEY = "my-key-id"; static final String SECRET = Base64.getEncoder().encodeToString("my-key-secret".getBytes(StandardCharsets.UTF_8)); - AuthManager authManager = new VerificationApplicationAuthManager(KEY, SECRET); + AuthManager authManager = new ApplicationAuthManager(KEY, SECRET); @Test void getSchema() {