如何在HandshakeInterceptor中设置Principal

Pep*_*ter 5 spring-websocket

我正在使用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)

Mas*_*ode 4

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)