Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Spring
Springhard

Spring Security context — why can auth break in async code?

Tags
#spring-security#securitycontext#threadlocal#async
Back to categoryPractice quiz

Answer

SecurityContext is often stored in a ThreadLocal. When you switch threads (async/executor), the new thread may not have that context, so auth info is missing. You must propagate context explicitly or use supported async security integration.

Related questions

Spring
`@Async` methods: how do they work and what are common pitfalls?
#spring#async#executor
Spring
How does `@Async` work in Spring and what’s a common gotcha?
#async#executor#proxy
Spring
Spring Security — where do authentication/authorization happen?
#spring-security#filters#auth
Java
What does `ThreadLocal` do and what is a common pitfall?
#threadlocal#concurrency#thread-pool