我正在使用Spring的WebSockets的非常薄的实现.WebSocketSession有方法getPrincipal(),但是如何在HandshakeInterceptor中设置它?
我想把Principal放在的方法是:
public boolean beforeHandshake(final ServerHttpRequest request, final ServerHttpResponse response, final WebSocketHandler wsHandler,
final Map<String, Object> attributes) throws Exception {
Principal = getPrincipal();
// Now where to set the principal so it is available in WebSocketSession?
}
Run Code Online (Sandbox Code Playgroud)
registry.addEndpoint("/hello")
.setHandshakeHandler(new DefaultHandshakeHandler() {
@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
//Here you can set and return principal that is used by websocket session.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1601 次 |
| 最近记录: |