I want to use websocket in spring application for contact requests. I already have setup login page for users and I use spring security for that. My problem is following: how to securely send web socket messages to two different users.
I know that i can broadcast messages to every user subscribed to some topic with @SendTo()
and can broadcast message to one user only with something like
messagingTemplate
.convertAndSendToUser(principal.getName(), "/queue/requests", request);
because his username is stored in principal.
My problem is how to handle when we have to target 2 users from a request and make it secure so that you cant just listen to any channels from client side without being authorized.
Ideally I'm looking for something like
messagingTemplate
.convertAndSendToUser(request.getFromUser(), "/queue/requests", request)
messagingTemplate
.convertAndSendToUser(request.getToUser(), "/queue/requests", request)