-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
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.upgradeconstructs aStandardWebSocketHandlerAdapterand 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.onOpenthen 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).