Skip to content

Commit

Permalink
[#5968] fix(server-common): The owner of the catalog is incorrect whe…
Browse files Browse the repository at this point in the history
…n using Basic Auth and Password is empty
  • Loading branch information
frankvicky committed Dec 27, 2024
1 parent 2d160d1 commit 9eced93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Principal authenticateToken(byte[] tokenData) {
try {
String[] userInformation =
new String(Base64.getDecoder().decode(credential), StandardCharsets.UTF_8).split(":");
if (userInformation.length != 2) {
if (userInformation.length < 1) {
return ANONYMOUS_PRINCIPAL;
}
return new UserPrincipal(userInformation[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ public void testAuthentication() {
.authenticateToken(
AuthConstants.AUTHORIZATION_BASIC_HEADER.getBytes(StandardCharsets.UTF_8))
.getName());
String credentials = "test-user:123";
String basicToken =
AuthConstants.AUTHORIZATION_BASIC_HEADER
+ Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals(
AuthConstants.ANONYMOUS_USER,
credentials.split(":")[0],
simpleAuthenticator
.authenticateToken(
(AuthConstants.AUTHORIZATION_BASIC_HEADER + "xx").getBytes(StandardCharsets.UTF_8))
.authenticateToken(basicToken.getBytes(StandardCharsets.UTF_8))
.getName());
Assertions.assertEquals(
"gravitino",
Expand Down

0 comments on commit 9eced93

Please sign in to comment.