Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Principal within a HandshakeInterceptor

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?

}
like image 669
Pepster Avatar asked Oct 19 '22 17:10

Pepster


1 Answers

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.            
}
like image 100
MasterCode Avatar answered Jan 04 '23 07:01

MasterCode