Repository navigation
Export SecurityContext from SecurityContextRepository - #20114
Open
havefunatcode wants to merge 1 commit into
Open
havefunatcode wants to merge 1 commit into
havefunatcode wants to merge 1 commit into
Conversation
exportTestSecurityContext() only copied TestSecurityContextHolder, so requests authenticated with with(user(..)) or formLogin() exported an empty SecurityContext. When TestSecurityContextHolder has no Authentication, load the SecurityContext from the SecurityContextRepository used by the request and export it if it has an Authentication. A populated TestSecurityContextHolder still wins, and an empty result from the repository (for example NullSecurityContextRepository) keeps the previous behavior. Closes spring-projectsgh-10766 Signed-off-by: Lee Taeho <dlxogh439@gmail.com>
This branch has not been deployed
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.
exportTestSecurityContext() only copied the TestSecurityContextHolder, so a request authenticated with with(user("bob")) or formLogin() exported an empty SecurityContext.
Now, when the TestSecurityContextHolder has no Authentication, the handler loads the SecurityContext from the SecurityContextRepository of the request (via WebTestUtils) and exports it if it has an Authentication.
Cases from the issue:
Tested with new cases in SecurityMockMvcResultHandlersTests and a new SecurityMockMvcResultHandlersNullSecurityContextRepositoryTests. The two repository cases (with(user(..)) and formLogin()) fail without the change. Ran ./gradlew :spring-security-test:check and :spring-security-test:javadoc.
This targets 7.0.x since it's a bug fix. The touched files are the same on main.
Closes gh-10766