Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nit: Make function to build a Basic Authorization header publicly available (for internal use) #9578

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,13 @@ public HttpAuthentication build(Function<String, String> configSupplier) {
private static class BasicAuthentication implements HttpAuthentication {
private final Supplier<String> 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why expose an auth scheme that is deprecated in Nessie in public API? Maybe add an internal utility class for it?

this.headerSupplier = () -> header;
}

private BasicAuthentication(String username, Supplier<String> passwordSupplier) {
this.headerSupplier = () -> basicHeader(username, passwordSupplier.get());
this.headerSupplier = () -> basicAuthorizationHeader(username, passwordSupplier.get());
}

@Override
Expand All @@ -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;
}
}