In a WebFlux application that uses Tomcat as the webserver, the reactor subscriber context is not currently propagated from WebFilters down to WebSocketHandlers. Therefore objects put into the subscriber context (such as the spring security context) by WebFilters are not available to WebSocketHandlers.
For comparison, when reactor-netty is used as the webserver, the reactor subscriber context is propagated from WebFilters to WebSocketHandlers properly.
I have a WebSocketHandler that needs to access the spring security context. Unfortunately, this is not currently possible when using tomcat as the webserver.
The disconnect occurs between TomcatRequestUpgradeStrategy
and StandardWebSocketHandlerAdapter
...
TomcatRequestUpgradeStrategy.upgrade
constructs aStandardWebSocketHandlerAdapter
and delegates to the container's websocket upgrade logic (see here). The context is lost at this point.- The container performs the websocket upgrade and calls into
StandardWebSocketHandlerAdapter.onOpen
. StandardWebSocketHandlerAdapter.onOpen
then delegates toWebSocketHandler.handle
(see here). I need access to items in the subscriber context within aWebSocketHandler
, but the context is empty.
To propagate the context, I believe TomcatRequestUpgradeStrategy.upgrade
could pass the active context to the StandardWebSocketHandlerAdapter
upon construction (during step 1 above).
Then StandardWebSocketHandlerAdapter.onOpen
could pass the context to the handler stream (during step 3 above).
Comment From: rstoyanchev
Sounds reasonable, will give it a try for 5.3.2.
Comment From: philsttr
Thanks Rossen!
If it's simple, I'd love a backport to 5.2.x too if possible.
Comment From: rstoyanchev
Sure, let's see how it works out.
Comment From: rstoyanchev
It turned out slightly more involved. We can consider a backport but since 5.2.13 is not planned to be released at the same time, I'd prefer to defer for now and see first if 5.3.3 causes any issues.