我創建了一個使用彈簧4的websockets機制的簡單應用程序。 我在我的應用程序中使用了一個activemq代理。春天websocket與跺腳安全 - 每個用戶可以訂閱任何其他用戶的隊列?
在我簡單的測試,我的一個名爲「Alejando」用戶創建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();
}
}
但是,沒有按真的沒有幫助。當你使用'SimpMessageTemplate.convertAndSendToUser'時,如果你看看代碼,它實際上只是前綴'/ user/{username}',然後使用'SimpMessageTemplate.convertAndSend'方法。它實際上並沒有解決安全問題。 – Nitroware
是的,它的確如此:這是一個特殊的隊列,用戶的唯一sessionId被附加到目標並被代理透明地刪除。嘗試並驗證只有發起用戶能夠接收發送到那裏的消息:所有其他客戶不是。 –
看看我的例子中的更多細節和代碼在這裏:也許我失去了一些東西http://stackoverflow.com/questions/25004081/springmvc-websockets-messaging-user-authentication-with-spring-security |如果你是對的,我只會將我的問題作爲重複來解決。 – Nitroware