spring-projects / spring-projects/spring-security
ScopedValue-based implementation of SecurityContextHolderStrategy
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Spring Framework provides an extensive support for virtual threads. Virtual thread guidelines, however, recommend to replace the ThreadLocal with ScopedValue while Spring Security is one of the systems which uses ThreadLocals extensively - its default implementation of SecurityContextHolderStrategy is ThreadLocal-based. Although it hasn't been officially announced, as of JDK 25 ScopedValue is no longer annotated with PreviewFeature.
Does it make sense to implement ScopedValue-based SecurityContextHolderStrategy - even though the SecurityContext or Authentication are not necessarily expensive reusable objects as the Oracle guidelines state?
This issue has been addressed more than a year ago in a Stack Overflow thread Spring Security Virtual Threads and ThreadLocal and in my answer to it. The small POC project, brought in the answer, offers some solution to this issue; this solution, non-systematic and ad-hoc, may, nevertheless, serve as a starting point of the discussion. The problems and ramifications of the solution are also discussed in a readme file of the project.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with SecurityContextHolderStrategy and the default ThreadLocal-based implementation; compare their context-lifetime assumptions with the ScopedValue guidance and the linked POC's README. Done means a repository-grounded decision on feasibility, ramifications, and the scope of a systematic strategy; no repository file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100