Securing a Spring messaging based websocket service

血红的双手。 提交于 2019-12-08 16:49:27

I understand your pain, i spend two days trying to understand the spring security mess concerning WebSocket.

Websocket dont officially support a way to authenticate, however, spring-security does (more or less).

I would advice you to authenticate at WebSocket level, not at HTTP, most of JavaScripts library for WebSocket (and stomp) don't sends headers along with the HTTP handshake.

You'll find a detailed guide on how to authenticate at the WebSocket level here. In the above example, i used Websocket Headers values to authenticate my clients, you can put your cookie value in these headers, or replace the cookie by localstorage.

Using this method you'll have access to the Principal in your controllers, this should solve the SendToUser issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!