5

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?

}
Pepster
  • 1,996
  • 1
  • 24
  • 41
  • See the source code of `DefaultHandshakeHandler`: how it gets deal with `RequestUpgradeStrategy`. And further any `RequestUpgradeStrategy` implementation. – Artem Bilan Mar 04 '15 at 15:44

1 Answers1

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.            
}
MasterCode
  • 975
  • 5
  • 21
  • 44