我正在使用 Spring 的 WebSockets 的一个非常精简的实现。 WebSocketSession 有 getPrincipal() 方法,但如何在 HandshakeInterceptor 中设置它?
我想将校长放入的方法是:
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?
}
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.
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)