From Flux to Flow, how to preserve the context?

Hi here!
I have to convert a Project Reactor Mono/Flux to a Kotlin Flow in a Spring Boot controller.
The problem is that Spring Boot puts the Security Context on the final reactive chain, which means in my case on the Flow. Given that the context propagates upstream and I originally had a Flux, the Flux does not have knowledge of that Security Context, which is a big problem for me.

That might not sound very clear, really confusing for me, here is a link to the corresponding Stack Overflow post, and to the sample project I created, showcasing the problem:

Thanks in advance for the help!

Are you considered Kotlin CoroutineContext?
It is pretty similar to ThreadContext.

Yes, coroutineContext[ReactorContext.Key] should contain the SecurityContext, but if I don’t suspend (i.e. if I return a Flow) it doesn’t seem to have it. And anyway even if it had it, I’m pretty sure it would not be in the context of the Flux.

Can you build a Flow that flowOn your context?

I don’t think it will help, Spring is already supposed to paste the context on my Flow, then I would need to transfer it from the Flow to the upstream Flux

Seems like I got a solution, see the Stackoverflow post!