From d11b77a1e9c6ba3bf25f09ab58e5e79817a21aea Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Thu, 19 Sep 2024 20:21:28 +0200 Subject: [PATCH] Nit: Make function to build a Basic Authorization header publicly available (for internal use) --- .../auth/BasicAuthenticationProvider.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/api/client/src/main/java/org/projectnessie/client/auth/BasicAuthenticationProvider.java b/api/client/src/main/java/org/projectnessie/client/auth/BasicAuthenticationProvider.java index e324d22f9ca..f335552c59a 100644 --- a/api/client/src/main/java/org/projectnessie/client/auth/BasicAuthenticationProvider.java +++ b/api/client/src/main/java/org/projectnessie/client/auth/BasicAuthenticationProvider.java @@ -69,25 +69,13 @@ public HttpAuthentication build(Function configSupplier) { private static class BasicAuthentication implements HttpAuthentication { private final Supplier headerSupplier; - private static String basicHeader(String username, String password) { - if (username == null || password == null) { - throw new NullPointerException( - "username and password parameters must be present for auth type " + AUTH_TYPE_VALUE); - } - - String userPass = username + ':' + password; - byte[] encoded = Base64.getEncoder().encode(userPass.getBytes(StandardCharsets.UTF_8)); - String encodedString = new String(encoded, StandardCharsets.UTF_8); - return "Basic " + encodedString; - } - private BasicAuthentication(String username, String password) { - String header = basicHeader(username, password); + String header = basicAuthorizationHeader(username, password); this.headerSupplier = () -> header; } private BasicAuthentication(String username, Supplier passwordSupplier) { - this.headerSupplier = () -> basicHeader(username, passwordSupplier.get()); + this.headerSupplier = () -> basicAuthorizationHeader(username, passwordSupplier.get()); } @Override @@ -100,4 +88,16 @@ public void applyToHttpRequest(RequestContext context) { context.putHeader("Authorization", headerSupplier.get()); } } + + public static String basicAuthorizationHeader(String username, String password) { + if (username == null || password == null) { + throw new NullPointerException( + "username and password parameters must be present for auth type " + AUTH_TYPE_VALUE); + } + + String userPass = username + ':' + password; + byte[] encoded = Base64.getEncoder().encode(userPass.getBytes(StandardCharsets.UTF_8)); + String encodedString = new String(encoded, StandardCharsets.UTF_8); + return "Basic " + encodedString; + } }