Skip to content

[#10960] feat(authentication): Wire basic authenticator module#10967

Open
lasdf1234 wants to merge 2 commits intoapache:mainfrom
lasdf1234:feat/local-authenticator-module-wiring
Open

[#10960] feat(authentication): Wire basic authenticator module#10967
lasdf1234 wants to merge 2 commits intoapache:mainfrom
lasdf1234:feat/local-authenticator-module-wiring

Conversation

@lasdf1234
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR wires the new authenticators:authenticator-basic module into the server authentication flow.

The changes include:

  • adding the new authenticators:authenticator-basic Gradle module
  • making the server module depend on authenticator-basic
  • introducing AuthenticatorType.BASIC
  • wiring gravitino.authenticators=basic to load org.apache.gravitino.auth.local.BasicAuthenticator
  • adding tests for authenticator factory wiring and Basic authentication header handling
  • returning 400 Bad Request for malformed Basic authorization headers and 401 Unauthorized for missing or invalid Basic authorization headers

Why are the changes needed?

This is the module wiring work for local authentication. It enables Gravitino to recognize and load the new Basic authenticator module when gravitino.authenticators=basic, which is the foundation for the follow-up local authentication tasks.

Fix: #10960

Does this PR introduce any user-facing change?

Yes.

  • Gravitino now recognizes basic as a valid value of gravitino.authenticators
  • malformed Basic authorization headers now return 400 Bad Request
  • missing or invalid Basic authorization headers now return 401 Unauthorized

How was this patch tested?

  • added TestAuthenticatorFactory to verify basic loads BasicAuthenticator
  • added TestBasicAuthenticator to verify Basic header error handling
  • updated TestAuthenticationFilter to verify BadRequestException maps to HTTP 400
  • ran:
    • ./gradlew --no-daemon :authenticators:authenticator-basic:build
    • ./gradlew --no-daemon :server-common:test --tests org.apache.gravitino.server.authentication.TestAuthenticationFilter
    • ./gradlew --no-daemon :server:test --tests org.apache.gravitino.server.authentication.TestAuthenticatorFactory
    • ./gradlew --no-daemon classes testClasses

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 4, 2026 14:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR wires a new authenticators:authenticator-basic Gradle module into Gravitino’s server authentication flow, adds AuthenticatorType.BASIC, and updates server-side HTTP status mapping so malformed Basic headers can return 400 Bad Request instead of being treated as internal errors.

Changes:

  • Adds the new authenticators:authenticator-basic module and wires it into the Gradle build (settings + server dependency).
  • Extends authenticator selection to recognize basic (AuthenticatorType.BASIC) and load org.apache.gravitino.auth.local.BasicAuthenticator.
  • Updates AuthenticationFilter to map BadRequestException to HTTP 400 and adds/updates tests around the new wiring and error mapping.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
settings.gradle.kts Includes the new authenticator-basic submodule in the Gradle build.
server/build.gradle.kts Adds a dependency from server to the new authenticator-basic module.
common/src/main/java/org/apache/gravitino/auth/AuthenticatorType.java Introduces AuthenticatorType.BASIC.
server-common/src/main/java/org/apache/gravitino/server/authentication/AuthenticatorFactory.java Maps basic to the Basic authenticator class name for reflective loading.
server-common/src/main/java/org/apache/gravitino/server/authentication/AuthenticationFilter.java Maps BadRequestException to HTTP 400 in auth error responses.
server-common/src/test/java/org/apache/gravitino/server/authentication/TestAuthenticationFilter.java Adds a regression test asserting BadRequestException maps to HTTP 400.
server/src/test/java/org/apache/gravitino/server/authentication/TestAuthenticatorFactory.java Adds a test verifying basic loads BasicAuthenticator.
authenticators/authenticator-basic/build.gradle.kts Defines the new module build, dependencies, and test env vars.
authenticators/authenticator-basic/src/main/java/org/apache/gravitino/auth/local/BasicAuthenticator.java Implements Basic auth header parsing and exception behavior.
authenticators/authenticator-basic/src/test/java/org/apache/gravitino/auth/local/TestBasicAuthenticator.java Adds unit tests for Basic header parsing/error handling.

Comment on lines +95 to +97
return tokenData != null
&& new String(tokenData, StandardCharsets.UTF_8)
.startsWith(AuthConstants.AUTHORIZATION_BASIC_HEADER);
Comment on lines +81 to +85

return new UserPrincipal(userName, authData);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e, "Malformed Basic authorization header: invalid base64");
}
Comment on lines +33 to +41
@Test
public void testAuthenticateTokenThrowsUnauthorizedWhenHeaderMissing() {
UnauthorizedException exception =
Assertions.assertThrows(
UnauthorizedException.class, () -> authenticator.authenticateToken(null));

Assertions.assertEquals("Empty token authorization header", exception.getMessage());
Assertions.assertEquals("Basic", exception.getChallenges().get(0));
}
@lasdf1234 lasdf1234 changed the title [#10960] feat(authentication): wire basic authenticator module [#10960] feat(authentication): Wire basic authenticator module May 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@roryqi roryqi left a comment

Choose a reason for hiding this comment

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

I don't think this should be the first pull request. Because this relies on built-in idp.

* under the License.
*/

plugins {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this module? It seems unrelated about this pull request. You didn't put any files in this module.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

May be 'Add password hashing support' should be the first sub task(#10961)? This sub-task is the most basic one, and it has accomplished the most basic functions of the authenticator-basic module.

If this sub task is the first sub task, I will adjust the sequence of the sub-tasks, and then you can review the code. How about that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should adjust the orders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask] Wire authenticator module

3 participants