spring-projects / spring-projects/spring-security

Use SecurityContextHolderStrategy

Open
#10,973 0 comments 2 reactions 1 assignee View on GitHub

@jzheaux is already working on this.

Since Jun 21, 2022.

type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

When components access the SecurityContext statically through SecurityContextHolder, this can create race conditions when there are multiple application contexts that want to specify the SecurityContextHolderStrategy. This is because in SecurityContextHolder there is one strategy per classloader instead of one per application context.

To address this, components could wire SecurityContextHolderStrategy from the application context. By default, they will still look up the strategy from SecurityContextHolder. Additionally, though, there will be the option to set the SecurityContextHolderStrategy on components that work with the SecurityContext.

One of the nice consequences of this is that applications will be able to publish a SecurityContextHolderStrategy bean in their application context, and the security filters and other components will use the custom one instead.

These changes are largely internal, though note that they present the opportunity for applications to autowire the SecurityContextHolderStrategy instead of accessing the SecurityContext statically.

  • #11059
  • #11060
  • #11061
  • #11444
  • #11886

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.