forge-docs

0011. Stateless JWT Authentication

Status: Accepted Date: 2025-12-10 Context: Migrate from hybrid JWT plus sessions to fully stateless JWT authentication for horizontal scaling.

Context

The application initially used a hybrid authentication system:

This hybrid approach created several issues:

The system needed to support true horizontal scaling without session affinity requirements.


Decision

We will use fully stateless JWT-based authentication across all modules (backend services and frontend UI modules).

All authentication flows return JWT tokens that are:

Key Changes

  1. Removed Session Support:
    • Deleted security-web module
    • Removed SessionAuthenticationFilter ✅ (completed 2025-12-11)
    • Removed SessionAuthResource ✅ (completed 2025-12-11)
    • Removed CognitoFormLoginResource ✅ (completed 2025-12-11)
    • Removed SessionAttribute enum ✅ (completed 2025-12-11)
    • Removed PageProtectionRouteHandler
    • Removed session-related CORS configuration
  2. Unified Authentication Model:
    • Single @Secured annotation for all authentication
    • JWT tokens for all modules (backend and frontend)
    • Client-side token storage and management
    • Automatic token validation via JAX-RS filter
  3. Frontend Authentication:
    • Login returns JWT tokens (not session cookies)
    • Tokens stored in localStorage
    • JavaScript handles page protection
    • Automatic token refresh on expiration

Consequences

Positive:

Negative / Tradeoffs:


Implementation

Backend

All REST endpoints use @Secured annotation:

Frontend

JavaScript handles authentication:

Request Flow

All frontend requests route through BFF on port N: