spring-projects / spring-projects/spring-security

ScopedValue-based implementation of SecurityContextHolderStrategy

Open
#19,259 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.