具有stomp安全性的Spring websocket - 每个用户都可以订阅任何其他用户队列?

Urb*_*leg 6 java spring stomp spring-security websocket

我创建了一个使用弹簧4的websockets机制的简单应用程序.我在我的应用程序中使用activemq代理.

在我的简单测试中,我为名为"Alejando"的用户创建了10条消息(user/alejandro/queue/greetings)

当我使用"Alejando"登录并订阅该队列时:

  stompClient.subscribe('/user/alejandro/queue/greetings', function(greeting){
                  showGreeting(JSON.parse(greeting.body).content);
  }); 
Run Code Online (Sandbox Code Playgroud)

我确实收到了为alejandro征服的所有10条消息.

问题是,当我使用名为"evilBart"的其他用户登录并订阅alejandro队列时,我也会收到消息?

我该如何执行安全措施?我希望用户只能订阅自己的队列.

谢谢!

我的配置类:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableStompBrokerRelay("/queue/","/topic","/user/");     
    config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/hello").withSockJS();
}

}
Run Code Online (Sandbox Code Playgroud)

Ale*_*ini 1

检查这个类似的问题:您必须使用 Spring Security 通过 HTTP 对用户进行身份验证,然后使用 SimpMessageTemplate.convertAndSendToUser() 方法向用户发送消息。