I'm creating a websocket + REST application in spring using the provided STOMP support.
I'm also using JWT authentication and doing what's said in http://docs.spring.io/spring-framework/reference/web/websocket/stomp/authentication-token-based.html
but when i access the @AuthenticationPrincipal in a @MessagingMapping handler, it's an empty object.
i tried setting the authentication in the SecurityContext too but it's always null. It works with regular REST endpoints though.
The handlers
@RestController
public class HelloWorldController {
@GetMapping("/greeting")
public String getMethodName(@AuthenticationPrincipal User user) {
return "HELLO " + user.getUsername(); // Works fine
}
@MessageMapping("/meeting")
public String hello(@Payload String name, @AuthenticationPrincipal User user) {
return "Hello, " + name + "! your email is " + user.getEmail(); // Hello, <name>! your email is null
}
}```
But im able to access the principal using the `SimpMessageHeaderAcessor` but i need to type cast twice in each message handler.
Is there a way to obtain the currently authenticated user in a `@MessageMapping` handler?