A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

SSO for Spring WebFlux — Reactive Authentication and Authorization

SSO for Spring WebFlux — Reactive Authentication and Authorization

Reactive applications introduce new challenges for SSO. Spring WebFlux does not use thread-local security context like MVC, so you must handle authentication and authorization differently.


1️⃣ Reactive context vs thread-local

In Spring MVC:

  • SecurityContextHolder uses thread-local storage
  • Filters populate authentication before reaching controllers

In WebFlux:

  • No thread-local — reactive chains pass context via Reactor Context
  • Logging or accessing SecurityContextHolder.getContext() outside the reactive chain often returns null

Debug tip: Always log authentication inside Mono/Flux using deferContextual.


2️⃣ Integrating Keycloak with WebFlux

Use keycloak-spring-boot-starter with spring-security-webflux dependencies.

Key steps:

  1. Configure reactive security adapter
  2. Set SecurityWebFilterChain bean
  3. Map Keycloak roles to reactive authorities

Example:



@Bean

public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {

    http

        .authorizeExchange()

        .pathMatchers("/public/**").permitAll()

        .anyExchange().authenticated()

        .and()

        .oauth2Login();

    return http.build();

}


3️⃣ Common WebFlux SSO issues

  • Null authentication in reactive chain — occurs if context not propagated
  • Roles not applied — must extract from JWT/IdP claims
  • Redirect loops — check redirect-uri configuration
  • Token expiration — same as MVC, but refresh must be reactive

4️⃣ Logging and debugging

Always log inside the reactive chain:



Mono handleRequest(ServerWebExchange exchange) {

    return ReactiveSecurityContextHolder.getContext()

        .doOnNext(ctx -> {

            Authentication auth = ctx.getAuthentication();

            log.info("User={}, authorities={}", 

                     auth.getName(), auth.getAuthorities());

        })

        .then();

}

This ensures you see the **real authentication state** per request.


5️⃣ Authorization in WebFlux

Use hasRole() or hasAuthority() in ServerHttpSecurity rules:



http.authorizeExchange()

    .pathMatchers("/admin/**").hasRole("ADMIN")

    .anyExchange().authenticated();

Remember: roles must be correctly mapped from Keycloak claims.


6️⃣ Systematic WebFlux SSO debugging workflow

  1. Check Keycloak logs for token issuance
  2. Verify token reaches your WebFlux app
  3. Log authentication inside reactive chain
  4. Validate roles/authorities
  5. Check redirect URIs for login/logout flows
  6. Enable DEBUG logging for org.keycloak.adapters and org.springframework.security

Final thoughts

  • Reactive SSO requires understanding the context propagation
  • WebFlux apps need different logging than MVC
  • Once you log correctly and map roles, SSO works seamlessly
  • Use the systematic workflow for every authentication issue

Series complete

You have now learned:

  • SSO concepts and protocols
  • Integrating Keycloak with Spring Boot (MVC)
  • Debugging SSO authentication issues
  • Handling SSO in Spring WebFlux applications

Part of the Spring Boot SSO Series

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments

Popular Posts

2026 Begins: Choosing to Stay on the Path as a Blogger

Health Checks and Scaling Strategies for Next.js in Kubernetes