2015-02-17 13 views
5

Spring'in WebSockets'larının çok ince bir uygulamasını kullanıyorum. WebSocketSession, getPrincipal() yöntemine sahiptir, ancak bunu bir HandshakeInterceptor içinden nasıl ayarlayabilirim?Bir HandshakeInterceptor içinde bir Principal nasıl ayarlanır

ben Müdürü koymak istiyorum yöntemdir:

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

DefaultHandshakeHandler' 'kaynak kodunu bakınız: o RequestUpgradeStrategy'' ile anlaşma nasıl olur. Ve ayrıca herhangi bir 'RequestUpgradeStrategy 'uygulaması. –

cevap

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.    
} 
İlgili konular