[英]Why can I subscribe to destination but I don't receive any messages for that user with Spring WebSocket STOMP (with Spring Security and Keycloak)?
[英]Spring websocket with stomp security - every user can subscribe to any other users queue?
我创建了一个使用Spring 4的websockets机制的简单应用程序。在我的应用程序中使用了activemq代理。
在我的简单测试中,我为名为“ Alejando”的用户(用户/ alejandro / queue / greetings)创建了10条消息
当我使用“ Alejando”登录并订阅该队列时:
stompClient.subscribe('/user/alejandro/queue/greetings', function(greeting){
showGreeting(JSON.parse(greeting.body).content);
});
实际上,我确实收到了有关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();
}
}
检查这个类似的问题 :您必须使用Spring Security通过HTTP对用户进行身份验证,然后使用SimpMessageTemplate.convertAndSendToUser()方法将消息发送给用户。
您可以采取两种选择。
参见org.springframework.messaging.simp.user软件包源码
默认用户前缀为“ / user /”。 您可以使用config.setUserDestinationPrefix()进行更改
2.重写两个方法并从ChannelInterceptor处理它
方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.