Introduce Scoped Value-based SecurityContextHolderStrategy#19468
Open
eager-zh wants to merge 1 commit into
Open
Introduce Scoped Value-based SecurityContextHolderStrategy#19468eager-zh wants to merge 1 commit into
eager-zh wants to merge 1 commit into
Conversation
- Change Gradle configuration to allow access to ScopedValue class - Suppress warnings on the usage of Subject.doAs - Introduce ScopedSecurityContextHolderStrategy - Introduce ScopedSecurityContextHolderFilter Closes spring-projectsgh-19259 Signed-off-by: Igor Zhuk <igorzhuk8@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes gh-19259.
The implementation of Scoped Value-based
SecurityContextHolderStrategy, henceforth Strategy, is rather straightforward:a
ScopedValueinstance holds a reference toSecurityContextsimilar to that ofThreadLocal;SecurityContextHolderis changed to be able to be configured with newSecurityContextHolderStrategy;a newly introduced
ScopedSecurityContextHolderFilterorchestrates the usage of new Strategy, invoking upstack/downstream Security Filters in a Filter Chain with theScopedValueinstance bound toSecurityContextfor the current thread;SecurityContextConfigureris changed to replaceSecurityContextHolderFilterwithScopedSecurityContextHolderFilterif current, globally configured Strategy is Scoped Value-based one;it was unnecessary, IMHO, to alter XML-based configuration as custom Strategy can be set for a particular Filter Chain by
security-context-holder-strategy-refattribute ofhttpXML element.What is not that straightforward is the configuration of Java compiler to be able to access Java 25 features,
ScopedValueclass in this case. For that purpose, Java compiler option--releasewas replaced with--sourceand--targetoptions injava-toolchain.gradle; it also turned out to be necessary to set JVM target to 17 for Kotlin test compilation intest-compile-target-jdk25.gradle. As a result of these changes, the project now builds, usesScopedValue, and still can run under JVM 17.It is impossible to replace
Subject.doAscalls with its Java 18 replacementSubject.callAsdue to the requirement of compatibility with Java 17, and the correspondent deprecation warnings are suppressed.