spring-projects / spring-projects/spring-security
SecurityContextHolderStrategy bean should be copied to SecurityContextHolder by default
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Now that applications can use a SecurityContextHolderStrategy bean, there's value in assisting applications with what may be a sizeable transition away from using SecurityContextHolder.
There are some cases where an application may not want to copy the SecurityContextHolderStrategy bean into SecurityContextHolder's static field:
- The application may not want to risk potential memory leaks from setting a bean to a static field
- The application uses more than one application context, each with a
SecurityContextHolderStrategy. Given that arrangement, it is undefined which bean will be set to the static field. - The application may want to discourage the use of static lookups.
- The application may otherwise need more control over deciding what goes into the static field.
Given the foundational nature of SecurityContextHolder in Spring Security, it's likely that applications for a time will want to assume the above risks. As such, this should be property-driven.
One way to do this is to introduce useSecurityContextHolder into @EnableWebSecurity. It would default to true.
If useSecurityContextHolder is true, then Spring Security will look for a SecurityContextHolderStrategy bean and call SecurityContextHolder.setSecurityContextHolderStrategy. If it's false, then no action will be taken.
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
Start by tracing @EnableWebSecurity configuration and the existing SecurityContextHolderStrategy bean handling, then inspect how SecurityContextHolder.setSecurityContextHolderStrategy is used. Done means a property on @EnableWebSecurity defaults to true, copies the strategy bean when enabled, and takes no action when disabled; the issue does not name specific files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100