2015-02-17 15 views
5

Używam bardzo cienkiej implementacji Spring WebSockets. WebSocketSession ma metodę getPrincipal(), ale jak mogę ustawić ją z poziomu HandshakeInterceptora?Jak ustawić głównego w HandshakeInterceptor

Sposób chciałbym umieścić w Principal jest:

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? 

} 
+0

Zobacz kodu źródłowego 'DefaultHandshakeHandler': jak robi się kontrakt z' RequestUpgradeStrategy'. I dalej każda implementacja 'RequestUpgradeStrategy'. –

Odpowiedz

2
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.    
} 
Powiązane problemy