-
Notifications
You must be signed in to change notification settings - Fork 356
Retrieving Authentication Information of Reactive Application in JDBC Auditing #2029
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
Comments
There's no context propagation imperative and reactive flows. Imperative binds its context to You would need to build context propagation yourself where you capture security details from the |
Thanks! Totally makes sense if you think about it. I came up with ReactiveSecurityContextHolder.getContext().flatMap { securityContext ->
Mono.fromCallable { thingRepository.save(thing) }
.doOnSubscribe { SecurityContextHolder.getContext().authentication = securityContext.authentication }
.doFinally { SecurityContextHolder.clearContext() }
.subscribeOn(Schedulers.boundedElastic())
} and @Bean
fun auditorAware(): AuditorAware<String> = AuditorAware {
Optional.of(SecurityContextHolder.getContext())
.map { it.authentication.name }
} This seems to work. Is this what you had in mind as well? |
Yes, exactly. Please keep in mind that depending on Coroutines threads might still change so that is a rather fragile setup. If it works, then go for it. Can I close this ticket or may I assist you with something else? |
Could you elaborate a little if/when this will become an issue for us? Do you know if there is any other work in progress to bridge JDBC and webflux? Looks like r2dbc is not getting much attention sadly :-( Otherwise thank you very much and yes, I think this can be closed then. |
I'm totally unfamiliar with the Coroutine threading model. I can well imagine that when there are other reactive or async components involved that bring their own threads, you might run into thread switches without noticing it. There's automatic context propagation (see spring-projects/spring-boot#34201) that might help with propagating contextual values across imperative and reactive patterns.
This is a consequence of Broadcom now owning our team and companies investing less into OSS. A lot of folks have been let go and so we need to narrow our focus. Also, there isn't much contribution into R2DBC drivers from other folks. |
Currently we're trying to migrate our R2DBC application to JDBC because the MSSQL driver seems to be completely unusable. Right now everything looks fine except user auditing information. It seems the the security context information is simply missing if you try to access the
ReactiveSecurityContextHolder
from aAuditorAware
implementation which@EnableJdbcAuditing
seem to require.To wrap our blocking calls we use this simple pattern
and our JDBC configuration looks like
We've had a look at the reactor context and it seems that it is properly filled in our code but missing in the
AuditorAware
. Do you have any suggestions how we can bridge blocking auditing with reactive security?The text was updated successfully, but these errors were encountered: