Skip to content

fix: Revert "fix(auth): JwtAuthFilter eager-401 with @PermitAll opt-out" - #5025

Merged
kunwp1 merged 1 commit into
mainfrom
revert-4903-refactor/jwt-filter-eager-401
May 11, 2026
Merged

kunwp1 merged 1 commit into
mainfrom
revert-4903-refactor/jwt-filter-eager-401

Conversation

@kunwp1

@kunwp1 kunwp1 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Reverts #4903 because it's causing a side-effect on the JWT authentication in ConfigService.

Any related issues, documentation, discussions?

Closes #5026
Email Discussion: https://lists.apache.org/thread/w5jmczrffxd5doc5hnss2zm7dbhnbhyy

How was this PR tested?

Run texera frontend in incognito mode (local cache cleared).

Was this PR authored or co-authored using generative AI tooling?

No.

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file common platform Non-amber Scala service paths labels May 11, 2026
@kunwp1 kunwp1 changed the title Revert "fix(auth): JwtAuthFilter eager-401 with @PermitAll opt-out" fix: Revert "fix(auth): JwtAuthFilter eager-401 with @PermitAll opt-out" May 11, 2026
@Yicong-Huang

Copy link
Copy Markdown
Contributor

@kunwp1 please fill the PR template. give it some context so we know why we revert it.

@codecov-commenter

codecov-commenter commented May 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.65%. Comparing base (14f8be4) to head (a25e9dc).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5025   +/-   ##
=========================================
  Coverage     42.64%   42.65%           
- Complexity     2188     2191    +3     
=========================================
  Files          1045     1045           
  Lines         39880    39876    -4     
  Branches       4205     4205           
=========================================
+ Hits          17006    17008    +2     
+ Misses        21814    21808    -6     
  Partials       1060     1060           
Flag Coverage Δ *Carryforward flag
access-control-service 39.53% <ø> (-0.35%) ⬇️
agent-service 33.72% <ø> (ø) Carriedforward from 14f8be4
amber 43.31% <ø> (+0.01%) ⬆️
computing-unit-managing-service 0.00% <ø> (ø)
config-service 0.00% <ø> (ø)
file-service 32.18% <ø> (+0.08%) ⬆️
frontend 33.85% <ø> (ø) Carriedforward from 14f8be4
python 88.90% <ø> (ø) Carriedforward from 14f8be4
workflow-compiling-service 47.72% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kunwp1
kunwp1 requested a review from Yicong-Huang May 11, 2026 20:55
@kunwp1
kunwp1 enabled auto-merge (squash) May 11, 2026 20:58

@Yicong-Huang Yicong-Huang left a comment

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.

Thanks. you can just link the email in related discussion as well.

@kunwp1
kunwp1 merged commit 62d4489 into main May 11, 2026
24 of 25 checks passed
@kunwp1
kunwp1 deleted the revert-4903-refactor/jwt-filter-eager-401 branch May 11, 2026 21:06
bobbai00 pushed a commit to bobbai00/texera that referenced this pull request Jun 1, 2026
…oints (apache#5305)

### What changes were proposed in this PR?

`config-service` no longer broadcasts the full GUI configuration to
anonymous callers. The four fields the frontend actually needs before
login (`localLogin`, `googleLogin`, `defaultLocalUser`,
`attributionEnabled`) move to a new `GET /api/config/pre-login`
(`@PermitAll`). `GET /api/config/gui` and `GET /api/config/user-system`
are now `@RolesAllowed("REGULAR", "ADMIN")` and only answer
authenticated traffic.

On the frontend, `GuiConfigService.load()` always fetches
`/config/pre-login` at `APP_INITIALIZER`. When a JWT is already in
`localStorage` (browser reload while logged in), it chains `/config/gui`
+ `/config/user-system` in the same await so the full config is in
memory before any post-login component mounts.
`UserService.handleAccessToken` does the same chaining on a fresh login
so `loginWithExistingToken` (which reads `config.env.inviteOnly`) runs
only after the authenticated config has resolved. Expired-token 403s on
the post-login fetch are caught so a stale `localStorage` token cannot
block bootstrap — that was the exact failure mode that caused apache#5025 to
revert the earlier eager-401 lockdown.

### Any related issues, documentation, discussions?

Closes apache#5304.

Related: apache#4901 (eager-401 from `JwtAuthFilter`), apache#5025 (revert that
broke `ConfigService` bootstrap last time we attempted a similar
lockdown), apache#5199 (re-applied `@RolesAllowed` enforcement on the
microservices, with `@PermitAll` opt-out for the two pre-login
endpoints).

### How was this PR tested?

Added unit tests covering pre-login / gui / user-system access with and
without a valid Bearer token, the orchestrator's branching on a stored
token, the 403 fallback, and the `UserService.handleAccessToken`
ordering guarantee.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.7

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Yicong-Huang added a commit that referenced this pull request Jun 6, 2026
…WTs (#5392)

### What changes were proposed in this PR?

Adds `UnauthorizedHttpInterceptor` that watches every HTTP response:
when the server returns 401 to a request that carried an `Authorization`
header, it routes the logout through `UserService.logout()` (which
clears the JWT and broadcasts `userChanged(undefined)` so header /
dashboard / in-memory state stay in sync), surfaces a "session expired"
notification, and routes to `/about` with `returnUrl`. 401 responses to
anonymous or auth-endpoint requests pass through unchanged so a 401 on a
public endpoint never wipes a freshly-stored token, and a wrong-password
401 on `/auth/login` cannot kick an already-authenticated user out.

Two adversarial-review findings (caught during self-review, fixed in
commit 2):

1. **Auth-endpoint allowlist.** `JwtModule` blanket-attaches
`Authorization` to every request, including `POST /api/auth/login`. A
wrong-password 401 there carries the user's existing token and would be
misread as "session invalid", kicking an already-authenticated user out
the moment they fat-finger a re-login. Allowlist regex
`\/auth\/(login|register|refresh|google\/login)` short-circuits the
interceptor for these URLs.

2. **Concurrent 401 dedup.** A burst of 8-10 parallel dashboard
requests, all 401'd by a server-side revoke, would fire 8 toasts and 8
`router.navigate` calls. Routing the logout through
`UserService.logout()` (which flips `isLogin()` from true to false)
gives natural dedup: only the first 401 sees `isLogin() === true` and
fires side effects; the rest of the burst short-circuits. The flag
re-arms automatically after a successful re-login.

Flips `JwtModule.forRoot`'s `skipWhenExpired` from `false` to `true`, so
a stale `localStorage` token is no longer auto-appended to public
pre-login endpoints (`/api/config/gui`, `/api/config/user-system`). That
auto-append is the exact mechanism that caused the revert of #4903 in
#5025 — without it, an expired token reaches public endpoints, gets
rejected, and breaks the login page before the user can re-authenticate.

`UserService` is resolved lazily via `Injector` inside `catchError`
because it transitively depends on `HttpClient`, and direct injection
would form a DI cycle through the interceptor chain.

### Any related issues, documentation, discussions?

Closes #5391. Prerequisite for a re-attempt of #4901 (whose first try,
#4903, was reverted by #5025 because of #5026). Discussion:
https://lists.apache.org/thread/w5jmczrffxd5doc5hnss2zm7dbhnbhyy

### How was this PR tested?

Added `unauthorized-http-interceptor.service.spec.ts` with 12 cases
covering: 401 with Authorization → logout + notify + navigate; 401
without Authorization → no-op; non-401 with Authorization → no-op; root
path → omits `returnUrl`; auth-endpoint URLs (login / register / refresh
/ google/login, with and without query strings) → no-op; over-broad URL
match guard (`recent-logins` still logs out); concurrent 401 burst →
exactly one side-effect set; re-arms after re-login.
Tested manually as well.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit 749798d)

Generated-by: Claude Code (Opus 4.7)
bobbai00 pushed a commit to bobbai00/texera that referenced this pull request Jun 6, 2026
…WTs (apache#5392)

### What changes were proposed in this PR?

Adds `UnauthorizedHttpInterceptor` that watches every HTTP response:
when the server returns 401 to a request that carried an `Authorization`
header, it routes the logout through `UserService.logout()` (which
clears the JWT and broadcasts `userChanged(undefined)` so header /
dashboard / in-memory state stay in sync), surfaces a "session expired"
notification, and routes to `/about` with `returnUrl`. 401 responses to
anonymous or auth-endpoint requests pass through unchanged so a 401 on a
public endpoint never wipes a freshly-stored token, and a wrong-password
401 on `/auth/login` cannot kick an already-authenticated user out.

Two adversarial-review findings (caught during self-review, fixed in
commit 2):

1. **Auth-endpoint allowlist.** `JwtModule` blanket-attaches
`Authorization` to every request, including `POST /api/auth/login`. A
wrong-password 401 there carries the user's existing token and would be
misread as "session invalid", kicking an already-authenticated user out
the moment they fat-finger a re-login. Allowlist regex
`\/auth\/(login|register|refresh|google\/login)` short-circuits the
interceptor for these URLs.

2. **Concurrent 401 dedup.** A burst of 8-10 parallel dashboard
requests, all 401'd by a server-side revoke, would fire 8 toasts and 8
`router.navigate` calls. Routing the logout through
`UserService.logout()` (which flips `isLogin()` from true to false)
gives natural dedup: only the first 401 sees `isLogin() === true` and
fires side effects; the rest of the burst short-circuits. The flag
re-arms automatically after a successful re-login.

Flips `JwtModule.forRoot`'s `skipWhenExpired` from `false` to `true`, so
a stale `localStorage` token is no longer auto-appended to public
pre-login endpoints (`/api/config/gui`, `/api/config/user-system`). That
auto-append is the exact mechanism that caused the revert of apache#4903 in
apache#5025 — without it, an expired token reaches public endpoints, gets
rejected, and breaks the login page before the user can re-authenticate.

`UserService` is resolved lazily via `Injector` inside `catchError`
because it transitively depends on `HttpClient`, and direct injection
would form a DI cycle through the interceptor chain.

### Any related issues, documentation, discussions?

Closes apache#5391. Prerequisite for a re-attempt of apache#4901 (whose first try,
apache#4903, was reverted by apache#5025 because of apache#5026). Discussion:
https://lists.apache.org/thread/w5jmczrffxd5doc5hnss2zm7dbhnbhyy

### How was this PR tested?

Added `unauthorized-http-interceptor.service.spec.ts` with 12 cases
covering: 401 with Authorization → logout + notify + navigate; 401
without Authorization → no-op; non-401 with Authorization → no-op; root
path → omits `returnUrl`; auth-endpoint URLs (login / register / refresh
/ google/login, with and without query strings) → no-op; over-broad URL
match guard (`recent-logins` still logs out); concurrent 401 burst →
exactly one side-effect set; re-arms after re-login.
Tested manually as well.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
github-merge-queue Bot pushed a commit that referenced this pull request Jun 6, 2026
### What changes were proposed in this PR?

Replaces the lazy pass-through behavior in `common/auth/JwtAuthFilter`
with an RFC 6750 eager 401 + `WWW-Authenticate` challenge. Missing
`Authorization` throws the bare `Bearer` challenge; an invalid token
throws `error="invalid_token"` so a well-behaved client can distinguish
"please log in" from "your stored token is invalid, discard it". Valid
tokens populate a `SecurityContext` exactly as before.

Endpoints that need to serve anonymous traffic opt out with `@PermitAll`
(JSR-250). This PR audits every resource method in the 5 microservices
and applies `@PermitAll` where the lazy filter previously made it
implicit:

- 5x `HealthCheckResource` (liveness probes)
- `AccessControlResource` `/auth/*` (routing proxy that authenticates
itself via `parseToken` in the resource body)
- `LiteLLMProxyResource` `/chat/*`, `LiteLLMModelsResource` `/models`
(preserve current "gated only by `guiWorkflowWorkspaceCopilotEnabled`"
behavior; whether these should require an authenticated user is a
separate hardening decision)
- `DatasetResource`: 5 endpoints with `/public-*` or `/publicVersion`
paths, plus `/{did}/cover` and `/{did}/cover-url` which already take
`@Auth Optional[SessionUser]` for opt-in user context

`UnauthorizedException` + `UnauthorizedExceptionMapper` carry the
`WWW-Authenticate` challenge to the JAX-RS edge. The exception extends
`RuntimeException` (not `WebApplicationException`) so unit tests can run
without a Jersey `RuntimeDelegate` on the classpath, and is constructed
with `writableStackTrace=false` to avoid `fillInStackTrace` cost on the
auth hot path.

### Any related issues, documentation, discussions?

Closes #4901. The earlier attempt at this fix, #4903, was reverted in
#5025 because expired tokens from `localStorage` were piggy-backed onto
`/api/config/gui` and broke the login page (#5026). PR #5392 has since
fixed the frontend to drop expired tokens client-side (`skipWhenExpired:
true`) and clear the session reactively on 401, so this PR can now ship
safely.

### How was this PR tested?

Added `JwtAuthFilterSpec` (header-missing / non-Bearer / invalid-token /
valid-token; method- and class-level `@PermitAll`; resource-info-absent
fallback) and `UnauthorizedExceptionMapperSpec`. Updated existing
service specs to expect 401 (from the filter) instead of 403 (from the
role filter) for missing-Authorization scenarios, and `*ServiceRunSpec`
mocks verify the new `UnauthorizedExceptionMapper` registration. `sbt
Auth/test` + 4 service specs all green; `sbt scalafmtCheckAll` clean.
Manually tested end-to-end against a running `config-service` build with
`curl` (missing / bad / valid tokens, `@PermitAll` healthcheck and
pre-login) and in the browser with a forged JWT in localStorage to
confirm the eager 401 path interoperates cleanly with PR #5392's 401
interceptor.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
Yicong-Huang added a commit that referenced this pull request Jun 6, 2026
### What changes were proposed in this PR?

Replaces the lazy pass-through behavior in `common/auth/JwtAuthFilter`
with an RFC 6750 eager 401 + `WWW-Authenticate` challenge. Missing
`Authorization` throws the bare `Bearer` challenge; an invalid token
throws `error="invalid_token"` so a well-behaved client can distinguish
"please log in" from "your stored token is invalid, discard it". Valid
tokens populate a `SecurityContext` exactly as before.

Endpoints that need to serve anonymous traffic opt out with `@PermitAll`
(JSR-250). This PR audits every resource method in the 5 microservices
and applies `@PermitAll` where the lazy filter previously made it
implicit:

- 5x `HealthCheckResource` (liveness probes)
- `AccessControlResource` `/auth/*` (routing proxy that authenticates
itself via `parseToken` in the resource body)
- `LiteLLMProxyResource` `/chat/*`, `LiteLLMModelsResource` `/models`
(preserve current "gated only by `guiWorkflowWorkspaceCopilotEnabled`"
behavior; whether these should require an authenticated user is a
separate hardening decision)
- `DatasetResource`: 5 endpoints with `/public-*` or `/publicVersion`
paths, plus `/{did}/cover` and `/{did}/cover-url` which already take
`@Auth Optional[SessionUser]` for opt-in user context

`UnauthorizedException` + `UnauthorizedExceptionMapper` carry the
`WWW-Authenticate` challenge to the JAX-RS edge. The exception extends
`RuntimeException` (not `WebApplicationException`) so unit tests can run
without a Jersey `RuntimeDelegate` on the classpath, and is constructed
with `writableStackTrace=false` to avoid `fillInStackTrace` cost on the
auth hot path.

### Any related issues, documentation, discussions?

Closes #4901. The earlier attempt at this fix, #4903, was reverted in
#5025 because expired tokens from `localStorage` were piggy-backed onto
`/api/config/gui` and broke the login page (#5026). PR #5392 has since
fixed the frontend to drop expired tokens client-side (`skipWhenExpired:
true`) and clear the session reactively on 401, so this PR can now ship
safely.

### How was this PR tested?

Added `JwtAuthFilterSpec` (header-missing / non-Bearer / invalid-token /
valid-token; method- and class-level `@PermitAll`; resource-info-absent
fallback) and `UnauthorizedExceptionMapperSpec`. Updated existing
service specs to expect 401 (from the filter) instead of 403 (from the
role filter) for missing-Authorization scenarios, and `*ServiceRunSpec`
mocks verify the new `UnauthorizedExceptionMapper` registration. `sbt
Auth/test` + 4 service specs all green; `sbt scalafmtCheckAll` clean.
Manually tested end-to-end against a running `config-service` build with
`curl` (missing / bad / valid tokens, `@PermitAll` healthcheck and
pre-login) and in the browser with a forged JWT in localStorage to
confirm the eager 401 path interoperates cleanly with PR #5392's 401
interceptor.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit 5c2eaa2)

Generated-by: Claude Code (Opus 4.7)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…ut" (apache#5025)

### What changes were proposed in this PR?

Reverts apache#4903 because it's causing a side-effect on the JWT
authentication in ConfigService.

### Any related issues, documentation, discussions?

Closes apache#5026 

### How was this PR tested?

Run texera frontend in incognito mode (local cache cleared).

### Was this PR authored or co-authored using generative AI tooling?

No.
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…oints (apache#5305)

### What changes were proposed in this PR?

`config-service` no longer broadcasts the full GUI configuration to
anonymous callers. The four fields the frontend actually needs before
login (`localLogin`, `googleLogin`, `defaultLocalUser`,
`attributionEnabled`) move to a new `GET /api/config/pre-login`
(`@PermitAll`). `GET /api/config/gui` and `GET /api/config/user-system`
are now `@RolesAllowed("REGULAR", "ADMIN")` and only answer
authenticated traffic.

On the frontend, `GuiConfigService.load()` always fetches
`/config/pre-login` at `APP_INITIALIZER`. When a JWT is already in
`localStorage` (browser reload while logged in), it chains `/config/gui`
+ `/config/user-system` in the same await so the full config is in
memory before any post-login component mounts.
`UserService.handleAccessToken` does the same chaining on a fresh login
so `loginWithExistingToken` (which reads `config.env.inviteOnly`) runs
only after the authenticated config has resolved. Expired-token 403s on
the post-login fetch are caught so a stale `localStorage` token cannot
block bootstrap — that was the exact failure mode that caused apache#5025 to
revert the earlier eager-401 lockdown.

### Any related issues, documentation, discussions?

Closes apache#5304.

Related: apache#4901 (eager-401 from `JwtAuthFilter`), apache#5025 (revert that
broke `ConfigService` bootstrap last time we attempted a similar
lockdown), apache#5199 (re-applied `@RolesAllowed` enforcement on the
microservices, with `@PermitAll` opt-out for the two pre-login
endpoints).

### How was this PR tested?

Added unit tests covering pre-login / gui / user-system access with and
without a valid Bearer token, the orchestrator's branching on a stored
token, the 403 fallback, and the `UserService.handleAccessToken`
ordering guarantee.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.7

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…WTs (apache#5392)

### What changes were proposed in this PR?

Adds `UnauthorizedHttpInterceptor` that watches every HTTP response:
when the server returns 401 to a request that carried an `Authorization`
header, it routes the logout through `UserService.logout()` (which
clears the JWT and broadcasts `userChanged(undefined)` so header /
dashboard / in-memory state stay in sync), surfaces a "session expired"
notification, and routes to `/about` with `returnUrl`. 401 responses to
anonymous or auth-endpoint requests pass through unchanged so a 401 on a
public endpoint never wipes a freshly-stored token, and a wrong-password
401 on `/auth/login` cannot kick an already-authenticated user out.

Two adversarial-review findings (caught during self-review, fixed in
commit 2):

1. **Auth-endpoint allowlist.** `JwtModule` blanket-attaches
`Authorization` to every request, including `POST /api/auth/login`. A
wrong-password 401 there carries the user's existing token and would be
misread as "session invalid", kicking an already-authenticated user out
the moment they fat-finger a re-login. Allowlist regex
`\/auth\/(login|register|refresh|google\/login)` short-circuits the
interceptor for these URLs.

2. **Concurrent 401 dedup.** A burst of 8-10 parallel dashboard
requests, all 401'd by a server-side revoke, would fire 8 toasts and 8
`router.navigate` calls. Routing the logout through
`UserService.logout()` (which flips `isLogin()` from true to false)
gives natural dedup: only the first 401 sees `isLogin() === true` and
fires side effects; the rest of the burst short-circuits. The flag
re-arms automatically after a successful re-login.

Flips `JwtModule.forRoot`'s `skipWhenExpired` from `false` to `true`, so
a stale `localStorage` token is no longer auto-appended to public
pre-login endpoints (`/api/config/gui`, `/api/config/user-system`). That
auto-append is the exact mechanism that caused the revert of apache#4903 in
apache#5025 — without it, an expired token reaches public endpoints, gets
rejected, and breaks the login page before the user can re-authenticate.

`UserService` is resolved lazily via `Injector` inside `catchError`
because it transitively depends on `HttpClient`, and direct injection
would form a DI cycle through the interceptor chain.

### Any related issues, documentation, discussions?

Closes apache#5391. Prerequisite for a re-attempt of apache#4901 (whose first try,
apache#4903, was reverted by apache#5025 because of apache#5026). Discussion:
https://lists.apache.org/thread/w5jmczrffxd5doc5hnss2zm7dbhnbhyy

### How was this PR tested?

Added `unauthorized-http-interceptor.service.spec.ts` with 12 cases
covering: 401 with Authorization → logout + notify + navigate; 401
without Authorization → no-op; non-401 with Authorization → no-op; root
path → omits `returnUrl`; auth-endpoint URLs (login / register / refresh
/ google/login, with and without query strings) → no-op; over-broad URL
match guard (`recent-logins` still logs out); concurrent 401 burst →
exactly one side-effect set; re-arms after re-login.
Tested manually as well.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…he#5404)

### What changes were proposed in this PR?

Replaces the lazy pass-through behavior in `common/auth/JwtAuthFilter`
with an RFC 6750 eager 401 + `WWW-Authenticate` challenge. Missing
`Authorization` throws the bare `Bearer` challenge; an invalid token
throws `error="invalid_token"` so a well-behaved client can distinguish
"please log in" from "your stored token is invalid, discard it". Valid
tokens populate a `SecurityContext` exactly as before.

Endpoints that need to serve anonymous traffic opt out with `@PermitAll`
(JSR-250). This PR audits every resource method in the 5 microservices
and applies `@PermitAll` where the lazy filter previously made it
implicit:

- 5x `HealthCheckResource` (liveness probes)
- `AccessControlResource` `/auth/*` (routing proxy that authenticates
itself via `parseToken` in the resource body)
- `LiteLLMProxyResource` `/chat/*`, `LiteLLMModelsResource` `/models`
(preserve current "gated only by `guiWorkflowWorkspaceCopilotEnabled`"
behavior; whether these should require an authenticated user is a
separate hardening decision)
- `DatasetResource`: 5 endpoints with `/public-*` or `/publicVersion`
paths, plus `/{did}/cover` and `/{did}/cover-url` which already take
`@Auth Optional[SessionUser]` for opt-in user context

`UnauthorizedException` + `UnauthorizedExceptionMapper` carry the
`WWW-Authenticate` challenge to the JAX-RS edge. The exception extends
`RuntimeException` (not `WebApplicationException`) so unit tests can run
without a Jersey `RuntimeDelegate` on the classpath, and is constructed
with `writableStackTrace=false` to avoid `fillInStackTrace` cost on the
auth hot path.

### Any related issues, documentation, discussions?

Closes apache#4901. The earlier attempt at this fix, apache#4903, was reverted in
apache#5025 because expired tokens from `localStorage` were piggy-backed onto
`/api/config/gui` and broke the login page (apache#5026). PR apache#5392 has since
fixed the frontend to drop expired tokens client-side (`skipWhenExpired:
true`) and clear the session reactively on 401, so this PR can now ship
safely.

### How was this PR tested?

Added `JwtAuthFilterSpec` (header-missing / non-Bearer / invalid-token /
valid-token; method- and class-level `@PermitAll`; resource-info-absent
fallback) and `UnauthorizedExceptionMapperSpec`. Updated existing
service specs to expect 401 (from the filter) instead of 403 (from the
role filter) for missing-Authorization scenarios, and `*ServiceRunSpec`
mocks verify the new `UnauthorizedExceptionMapper` registration. `sbt
Auth/test` + 4 service specs all green; `sbt scalafmtCheckAll` clean.
Manually tested end-to-end against a running `config-service` build with
`curl` (missing / bad / valid tokens, `@PermitAll` healthcheck and
pre-login) and in the browser with a forged JWT in localStorage to
confirm the eager 401 path interoperates cleanly with PR apache#5392's 401
interceptor.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common dependencies Pull requests that update a dependency file platform Non-amber Scala service paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with the JWT authentication in ConfigService in the main branch

3 participants