Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringWebSocket具有stomp安全性-每个用户都可以订阅任何其他用户队列?_Java_Spring_Spring Security_Websocket_Stomp - Fatal编程技术网

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

Java SpringWebSocket具有stomp安全性-每个用户都可以订阅任何其他用户队列?,java,spring,spring-security,websocket,stomp,Java,Spring,Spring Security,Websocket,Stomp,我创建了一个使用Spring4的websockets机制的简单应用程序。 我在应用程序中使用activemq代理 在我的简单测试中,我为一个名为“Alejando”(user/alejandro/queue/greetings)的用户创建了10条消息 当我使用“Alejando”登录并订阅该队列时: stompClient.subscribe('/user/alejandro/queue/greetings', function(greeting){ sh

我创建了一个使用Spring4的websockets机制的简单应用程序。 我在应用程序中使用activemq代理

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

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

  stompClient.subscribe('/user/alejandro/queue/greetings', function(greeting){
                  showGreeting(JSON.parse(greeting.body).content);
  }); 
我确实收到了为亚历杭德罗传来的所有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();
}

}

选中此项:您必须使用Spring Security通过HTTP对用户进行身份验证,然后使用SimpMessageTemplate.convertAndSendToUser()方法向用户发送消息。

您可以选择两个选项

  • 只需从config.enableStomBrokerReplay中删除“/user/”。 Spring消息将自动添加前缀。

    convertAndSendToUser不适用于代理中继


  • 默认用户前缀为“/user/”。 您可以使用config.setUserDestinationPrefix()对其进行更改





    2.重写两个方法并从ChannelInterceptor处理它

    方法:
  • 配置ClientInBoundChannel

  • 配置ClientOutboundChannel
  • ,但这并没有真正的帮助。使用
    SimpMessageTemplate.convertAndSendToUser
    时,如果查看代码,它实际上只是在“/user/{username}”前面加前缀,然后使用
    SimpMessageTemplate.convertAndSend
    方法。它实际上没有解决安全问题。是的,确实如此:这是一个特殊队列,其中用户的唯一sessionId被附加到目标,并被代理透明地删除。尝试并验证只有原始用户能够接收发送到那里的消息:所有其他客户端都不能。在这里查看我的示例中的更多详细信息和代码:可能我遗漏了什么|如果你是对的,我将把我的问题复制为一个副本。好的,我在那里添加了一个答案,让我知道它是否解决了问题,如果是,请接受它!