Skip to content
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

Provide Micrometer Context Propagation for SecurityContext #13123

Open
philsttr opened this issue May 2, 2023 · 5 comments
Open

Provide Micrometer Context Propagation for SecurityContext #13123

philsttr opened this issue May 2, 2023 · 5 comments
Labels
in: core An issue in spring-security-core type: enhancement A general enhancement

Comments

@philsttr
Copy link
Contributor

philsttr commented May 2, 2023

Add context propagation support via Micrometer Context Propagation for the SecurityContext, between SecurityContextHolder and ReactiveSecurityContextHolder.

This would allow applications to easily cross between the reactive <-> imperative border in either direction, and have the SecurityContext available on both sides.

Examples:

@philsttr philsttr added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels May 2, 2023
@jzheaux jzheaux removed their assignment May 8, 2023
@jzheaux jzheaux added in: core An issue in spring-security-core and removed status: waiting-for-triage An issue we've not yet triaged labels May 8, 2023
@jzheaux
Copy link
Contributor

jzheaux commented May 8, 2023

Hi, @philsttr, thanks for the suggestion.

Reading the links you provided, I gather that this will be done automatically when an application uses handle/tap and captureContext. I think this would be valuable to add to the documentation, but I'm not yet clear on what if any support Spring Security would need to add. Can you elaborate?

@philsttr
Copy link
Contributor Author

philsttr commented May 9, 2023

Hi @jzheaux,

Thanks for considering this feature.

In order to support context propagation of the Spring Security Context, Spring Security would need to:

  1. Provide an implementation of ThreadLocalAccessor that operates on the Spring Security Context.
  2. Register this implementation with micrometer context propagation. Micrometer context propagation can discover these implementations via Java's ServiceLoader (see ContextRegistry.loadThreadLocalAccessors()), or Spring Security could provide some other mechanism for registering it.

When micrometer context propagation needs to propagate context in either direction (e.g. handle/tap or captureContext), it will invoke all of the registered ThreadLocalAccessors to do so (see DefaultContextSnapshot).

@philsttr
Copy link
Contributor Author

philsttr commented Sep 28, 2023

@osi Spring Security stores a Mono<SecurityContext> in the subscriber context with key SecurityContext.class, but that accessor puts the SecurityContext into the subscriber context with key SecurityContext.class.getName(). So the one from spring-graphql can't just be copied into Spring Security, since it operates on a different key in the subscriber context.

@osi
Copy link

osi commented Sep 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants