Ant*_*eev 4 spring stomp websocket spring-messaging spring-websocket
我正在试验Spring 4 WebSocket STOMP应用程序.有没有办法在每个用户都有唯一会话ID的情况下回复单个未经身份验证的用户?现在我只能广播消息或直接发送给经过身份验证的用户.
@Controller
public class ProductController {
@MessageMapping("/products/{id}")
@SendTo("/topic") // This line makes return value to be broadcasted to every connected user.
public String getProduct(@DestinationVariable int id) {
return "Product " + id;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以为传入用户分配匿名身份.有两种方法可以做到这一点.
一,您可以配置DefaultHandshakeHandler
该覆盖的子类,determineUser
并为每个WebSocketSession分配某种身份.这需要4.0.1顺便提供(目前正在构建快照),将于2014年1月23日星期一发布.
第二,WebSocket会话将HttpServletRequest.getUserPrincipal
依赖于握手HTTP请求返回的值.你可以有一个servlet Filter包装HttpServletRequest并决定从该方法返回什么.或者,如果您正在使用具有AnonymousAuthenticationFilter的Spring Security,请覆盖其createAuthentication
方法.
归档时间: |
|
查看次数: |
4828 次 |
最近记录: |