Repository navigation
refactor(auth): align JWT claim parsing across microservices and amber - #4896
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4896 +/- ##
============================================
+ Coverage 42.38% 42.41% +0.03%
- Complexity 2154 2155 +1
============================================
Files 954 954
Lines 34694 34675 -19
Branches 3629 3629
============================================
+ Hits 14705 14709 +4
+ Misses 19083 19060 -23
Partials 906 906
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Why are we dropping googleAvatar? Are you sure it's not being used? |
Contributor
Nvm, it's not used on the backend. |
Yicong-Huang
marked this pull request as draft
May 4, 2026 04:22
aglinxinyuan
approved these changes
May 4, 2026
Two parsing paths drifted apart:
- common/auth/JwtParser (used by JwtAuthFilter in 4 microservices and
by a couple of amber resources directly) read 5 claims and dropped
googleAvatar even though JwtAuth.jwtClaims writes it into every
issued token.
- amber/.../UserAuthenticator (used by amber's toastshaman-based
filter) read those 5 plus comment + accountCreation, neither of
which the issuer ever writes — so they were always null in real
tokens. It also dropped googleAvatar.
Two JwtConsumer instances were also built with byte-identical builder
chains (same secret, same clock-skew/exp/sub config) — pure copies in
JwtParser and JwtAuth.
Consolidate:
1. Extract JwtParser.claimsToSessionUser(JwtClaims): SessionUser as
the single source of truth for "verified claims -> SessionUser".
Reads the full set the issuer writes, including googleAvatar.
2. JwtParser.parseToken now reuses JwtAuth.jwtConsumer instead of
building its own. The codebase has exactly one JwtConsumer left.
3. UserAuthenticator.authenticate becomes a 1-line delegate to
claimsToSessionUser, dropping the dead comment / accountCreation
reads.
Robustness: jose4j returns Long after JSON round-trip but setClaim on
in-memory JwtClaims keeps Integer; widen userId via
getClaimValue("userId", classOf[Number]).intValue() so directly-built
claims and parsed claims behave the same.
Tests: 4-case JwtParserSpec covers the populated/null field surface
and a JwtAuth.jwtToken -> JwtParser.parseToken round-trip.
Closes apache#4895
JwtParserSpec gains 8 cases for the verification life cycle: - token signed with wrong secret (signature mismatch) - expired beyond clock-skew window - missing subject claim - missing exp claim (consumer requires it) - expired within the 30s clock-skew window (still accepted) - expired past the clock-skew window (rejected) - tampered signature segment - tampered payload segment Plus a "life cycle" suite covering distinct-user round-trip and re-parse stability. UserAuthenticatorSpec (new, 3 cases) covers the amber-side adapter end-to-end: real JwtAuth.jwtToken -> JwtAuth.jwtConsumer.process -> UserAuthenticator.authenticate, plus missing-required-claim paths that exercise the catch in the adapter.
Yicong-Huang
force-pushed
the
refactor/align-jwt-parser
branch
from
May 4, 2026 04:33
f69afaa to
59f95fa
Compare
Yicong-Huang
marked this pull request as ready for review
May 4, 2026 04:43
Yicong-Huang
enabled auto-merge (squash)
May 4, 2026 04:43
yangzhang75
pushed a commit
to yangzhang75/texera
that referenced
this pull request
Jun 22, 2026
apache#4896) ### What changes were proposed in this PR? Two JWT parsing paths drifted apart, and the codebase had two `JwtConsumer` instances built with byte-identical config: - `common/auth/JwtParser` (microservices) read 5 claims and dropped `googleAvatar` — even though `JwtAuth.jwtClaims` writes it on every token. - `amber/.../UserAuthenticator` read those 5 plus `comment`, `accountCreation` — neither of which the issuer ever writes, so always `null` in real tokens. Also dropped `googleAvatar`. Consolidate into a single `JwtParser.claimsToSessionUser(JwtClaims): SessionUser` in `common/auth`. Make `JwtParser.parseToken` reuse `JwtAuth.jwtConsumer` (one consumer instance left in the codebase). Rewrite `UserAuthenticator.authenticate` as a 1-line delegate so amber and the microservices produce identical `SessionUser` objects from the same token. `UserAuthenticator` itself stays in amber — it's a Dropwizard 1.3 `Authenticator[JwtContext, SessionUser]` adapter for the toastshaman library. Once amber's Dropwizard upgrade unblocks the move to the common `JwtAuthFilter`, this whole adapter goes away. Side robustness fix: jose4j returns `Long` for integer claims after JSON round-trip but `setClaim` keeps `Integer` in memory. Widening `userId` via `getClaimValue("userId", classOf[Number]).intValue()` makes directly-built and parsed claims behave the same. ### Any related issues, documentation, discussions? Closes apache#4895 ### How was this PR tested? `JwtParserSpec` (new, 4 cases): asserts every issued claim is populated (including `googleAvatar`), the non-issued `User` slots stay `null`, an end-to-end round-trip via `JwtAuth.jwtToken -> JwtParser.parseToken` reconstructs the user, and a structurally invalid token returns empty. `sbt Auth/test` 11/11 green; `AccessControlService`, `ConfigService`, `FileService`, `ComputingUnitManagingService`, `WorkflowExecutionService` all compile clean; `Auth/scalafmtCheckAll` and `Auth/scalafixAll --check` clean. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Two JWT parsing paths drifted apart, and the codebase had two
JwtConsumerinstances built with byte-identical config:common/auth/JwtParser(microservices) read 5 claims and droppedgoogleAvatar— even thoughJwtAuth.jwtClaimswrites it on every token.amber/.../UserAuthenticatorread those 5 pluscomment,accountCreation— neither of which the issuer ever writes, so alwaysnullin real tokens. Also droppedgoogleAvatar.Consolidate into a single
JwtParser.claimsToSessionUser(JwtClaims): SessionUserincommon/auth. MakeJwtParser.parseTokenreuseJwtAuth.jwtConsumer(one consumer instance left in the codebase). RewriteUserAuthenticator.authenticateas a 1-line delegate so amber and the microservices produce identicalSessionUserobjects from the same token.UserAuthenticatoritself stays in amber — it's a Dropwizard 1.3Authenticator[JwtContext, SessionUser]adapter for the toastshaman library. Once amber's Dropwizard upgrade unblocks the move to the commonJwtAuthFilter, this whole adapter goes away.Side robustness fix: jose4j returns
Longfor integer claims after JSON round-trip butsetClaimkeepsIntegerin memory. WideninguserIdviagetClaimValue("userId", classOf[Number]).intValue()makes directly-built and parsed claims behave the same.Any related issues, documentation, discussions?
Closes #4895
How was this PR tested?
JwtParserSpec(new, 4 cases): asserts every issued claim is populated (includinggoogleAvatar), the non-issuedUserslots staynull, an end-to-end round-trip viaJwtAuth.jwtToken -> JwtParser.parseTokenreconstructs the user, and a structurally invalid token returns empty.sbt Auth/test11/11 green;AccessControlService,ConfigService,FileService,ComputingUnitManagingService,WorkflowExecutionServiceall compile clean;Auth/scalafmtCheckAllandAuth/scalafixAll --checkclean.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.7)