Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#5968] fix(server-common): The owner of the catalog is incorrect when using Basic Auth and Password is empty (#6023)

TengYao Chi956ae6bd4cd6
diff --git a/server-common/src/main/java/org/apache/gravitino/server/authentication/SimpleAuthenticator.java b/server-common/src/main/java/org/apache/gravitino/server/authentication/SimpleAuthenticator.java
index 88ecebd91d..1ff2195f1c 100644
--- a/server-common/src/main/java/org/apache/gravitino/server/authentication/SimpleAuthenticator.java
+++ b/server-common/src/main/java/org/apache/gravitino/server/authentication/SimpleAuthenticator.java
@@ -59,7 +59,7 @@ class SimpleAuthenticator implements Authenticator {
try {
String[] userInformation =
new String(Base64.getDecoder().decode(credential), StandardCharsets.UTF_8).split(":");
- if (userInformation.length != 2) {
+ if (userInformation.length < 1 || userInformation[0].isEmpty()) {
return ANONYMOUS_PRINCIPAL;
}
return new UserPrincipal(userInformation[0]);
diff --git a/server-common/src/test/java/org/apache/gravitino/server/authentication/TestSimpleAuthenticator.java b/server-common/src/test/java/org/apache/gravitino/server/authentication/TestSimpleAuthenticator.java
index fd12e71d31..c98380b978 100644
--- a/server-common/src/test/java/org/apache/gravitino/server/authentication/TestSimpleAuthenticator.java
+++ b/server-common/src/test/java/org/apache/gravitino/server/authentication/TestSimpleAuthenticator.java
@@ -47,11 +47,34 @@ public class TestSimpleAuthenticator {
.authenticateToken(
AuthConstants.AUTHORIZATION_BASIC_HEADER.getBytes(StandardCharsets.UTF_8))
.getName());
+ String fullCredentials = "test-user:123";
+ String basicToken =
+ AuthConstants.AUTHORIZATION_BASIC_HEADER
+ + Base64.getEncoder().encodeToString(fullCredentials.getBytes(StandardCharsets.UTF_8));
+ Assertions.assertEquals(
+ fullCredentials.split(":")[0],
+ simpleAuthenticator
+ .authenticateToken(basicToken.getBytes(StandardCharsets.UTF_8))
+ .getName());
+ String credentialsOnlyHaveUsername = "test-user:";
+ basicToken =
+ AuthConstants.AUTHORIZATION_BASIC_HEADER
+ + Base64.getEncoder()
+ .encodeToString(credentialsOnlyHaveUsername.getBytes(StandardCharsets.UTF_8));
+ Assertions.assertEquals(
+ fullCredentials.split(":")[0],
+ simpleAuthenticator
+ .authenticateToken(basicToken.getBytes(StandardCharsets.UTF_8))
+ .getName());
+ String credentialsOnlyHavePassword = ":123";
+ basicToken =
+ AuthConstants.AUTHORIZATION_BASIC_HEADER
+ + Base64.getEncoder()
+ .encodeToString(credentialsOnlyHavePassword.getBytes(StandardCharsets.UTF_8));
Assertions.assertEquals(
AuthConstants.ANONYMOUS_USER,
simpleAuthenticator
- .authenticateToken(
- (AuthConstants.AUTHORIZATION_BASIC_HEADER + "xx").getBytes(StandardCharsets.UTF_8))
+ .authenticateToken(basicToken.getBytes(StandardCharsets.UTF_8))
.getName());
Assertions.assertEquals(
"gravitino",