How to set a Principal within a HandshakeInterceptor

天大地大妈咪最大 提交于 2019-12-23 09:59:06

问题


I'm using a very thin implementation of Spring's WebSockets. WebSocketSession has the method getPrincipal(), but how can I set it from within a HandshakeInterceptor?

The method I would like to put the Principal in is:

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?

}

回答1:


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.            
}


来源:https://stackoverflow.com/questions/28567146/how-to-set-a-principal-within-a-handshakeinterceptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!