Uncorp
Log In
Java & Full Stack3 min readUpdated 2026-11-11

Spring Security 6, JWT & OAuth2 in Microservices: Complete Stateless Authentication & RBAC Guide

Master the new lambda-based SecurityFilterChain in Spring Security 6, stateless JWT access/refresh token rotation, Redis token revocation, and API Gateway RBAC.

Naitik Tailor & Uncorp Engineering Faculty
Spring Security 6, JWT Authentication & OAuth2 Microservices Vector Illustration
TL;DR — Key Engineering & Career Takeaways
  • Spring Security 6 (in Spring Boot 3) completely removed the deprecated `WebSecurityConfigurerAdapter` in favor of a component-based, lambda-DSL `SecurityFilterChain` `@Bean`.
  • In a distributed microservice architecture, never store `HttpSession` state in memory (`SessionCreationPolicy.STATELESS`); validate short-lived signed JWT Access Tokens (15-min TTL) at the Spring Cloud API Gateway and propagate claims downstream.
  • To solve the classic interview question 'How do you log out or revoke a stateless JWT immediately?', pair short-lived access tokens with rotating Refresh Tokens and a lightweight Redis JTI denylist.

1. Under the Hood: How a Request Travels Through Spring Security 6

In almost every 2–6 YOE Java Backend interview, the panel will ask you to trace an HTTP request from Tomcat'sServlet container into your `@RestController`. Understanding the exact sequence of `DelegatingFilterProxy` → `FilterChainProxy` → `SecurityFilterChain` → `OncePerRequestFilter` → `SecurityContextHolder` separates real backend engineers from copy-paste coders.

Spring Security 6 Stateless JWT Request Lifecycle
[Incoming HTTP Request w/ `Authorization: Bearer <JWT>`]
   │
   ▼
[Servlet Container] ──► [DelegatingFilterProxy] ──► [SecurityFilterChain]
   │
   ├──► 1. [JwtAuthenticationFilter (extends OncePerRequestFilter)]
   │       • Extracts Bearer token, verifies HMAC-SHA256 / RSA signature & expiration
   │       • Checks Redis denylist (`SISMEMBER revoked_jtis <jti>`)
   │       • Populates `UsernamePasswordAuthenticationToken` into `SecurityContextHolder`
   ▼
[Method Security (@PreAuthorize("hasRole('ADMIN')"))] ──► [@RestController Endpoint]

2. Stateful Sessions vs Stateless JWT vs OAuth2 / OIDC: When to Use Which

Use this architectural matrix to justify your authentication design in System Design interviews:

Enterprise Authentication Patterns in Spring Boot 3
Auth PatternHow State Is StoredMicroservice ScalabilityBest Use Case
Stateful `JSESSIONID` CookieServer RAM or shared Redis session storeRequires sticky sessions or centralized Redis lookup on every callMonolithic server-rendered apps
Stateless JWT (Access + Refresh Token)Self-contained cryptographic JSON payload (`sub`, `roles`, `exp`, `jti`)Zero DB lookup needed to verify signature across 50+ microservicesReact SPA + Spring Boot Microservices
OAuth2 + OpenID Connect (Keycloak / Okta / Google)Delegated Authorization Server issues RS256-signed ID & Access tokensMicroservices act as OAuth2 Resource Servers verifying public JWKS keysEnterprise SSO, multi-application ecosystems & third-party integrations

3. Three Production JWT Security Mistakes to Avoid

Never ship a Spring Boot JWT implementation without checking these three production hardening rules:

  • 1. Never Store Sensitive PII or Passwords Inside JWT Claims: A JWT payload is Base64Url-encoded, NOT encrypted—anyone can decode it on `jwt.io`. Store only `userId`, `tenantId`, `roles`, and `exp`.
  • 2. Use Asymmetric Keys (RS256) Across Microservices: Sign tokens with a private key owned solely by the Auth Service, while downstream microservices verify tokens using the public key (`/oauth2/jwks`).
  • 3. Protect Refresh Tokens in `HttpOnly; Secure; SameSite=Strict` Cookies: Keep the 15-minute Access Token in memory and store the 7-day Refresh Token in an `HttpOnly` cookie so XSS scripts can never steal it.

Frequently Asked Questions

Why was WebSecurityConfigurerAdapter removed in Spring Security 6?

Spring moved away from inheritance-based configuration toward explicit component-based configuration. Defining a `@Bean public SecurityFilterChain filterChain(HttpSecurity http)` makes security rules modular, easier to test, and allows multiple Ordered filter chains for different API paths.

Do we implement Spring Security 6, JWT, and RBAC hands-on at Uncorp?

Yes—you build full stateless JWT authentication, role-based access control (`@PreAuthorize`), and API Gateway security in Uncorp's Java Backend and Java Full Stack with Gen AI programs.

Written & Reviewed By Uncorp Engineering Faculty

Naitik Tailor & Uncorp Engineering Faculty

Founder & Principal Engineering Mentors (12+ Yrs Enterprise Experience) · VIT CSE '21 · Symbiosis MBA '24 · Ex-Delhivery & Ex-Aditya Birla Capital

About Uncorp

Continue Reading in This Topic Cluster

All 73 Guides