-
Notifications
You must be signed in to change notification settings - Fork 6.2k
SecurityContextHolderThreadLocalAccessor should not share SecurityContext instance across threads #18210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.5.x
Are you sure you want to change the base?
SecurityContextHolderThreadLocalAccessor should not share SecurityContext instance across threads #18210
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| * {@link java.util.ServiceLoader} mechanism when context-propagation is on the classpath. | ||
| * | ||
| * @author Steve Riesenberg | ||
| * @author Tadaya Tsuyukubo | ||
| * @since 6.5 | ||
| * @see io.micrometer.context.ContextRegistry | ||
| */ | ||
|
|
@@ -52,7 +53,9 @@ public SecurityContext getValue() { | |
| @Override | ||
| public void setValue(SecurityContext securityContext) { | ||
| Assert.notNull(securityContext, "securityContext cannot be null"); | ||
| SecurityContextHolder.setContext(securityContext); | ||
| SecurityContext newContext = SecurityContextHolder.createEmptyContext(); | ||
| newContext.setAuthentication(securityContext.getAuthentication()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring projects use |
||
| SecurityContextHolder.setContext(newContext); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question : Can we apply singleton concept here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole point of this PR is not to share the
SecurityContext, so making it a singleton defeats the purpose.