When processing a websocket request in a controller
SecurityContextHolder.getContext().getAuthentication()
returns null. But I need to know which user is making the request.
What was tried so far:
Google pointed me towards solutions implementing ChannelInterceptor, but in all its methods getAuthentication() also returns null. So there is nothing to carry over somehow. How to retrieve the current logged in user in a websocket controller
In an implementation of onApplicationEvent(SessionSubscribeEvent) or onApplicationEvent(SessionConnectEvent) on the websocket controller the getAuthentication() returns null.
I found that in an implementation of HandshakeInterceptor the getAuthentication() returns a Principal. What can that information be made available in an STOMP Websocket controller method? The methods do not have access to a thread bound request. (No thread-bound request found exception) when using:
RequestContextHolder.currentRequestAttributes().getSessionId()
And the sessionId that can be injected (8 characters) does not match the session id of the normal requests (32 characters): How to get Session Id in Spring WebSocketStompClient?
@Header("simpSessionId") String sessionId