1 package de.spring.stomp.handlers;
3 import java.security.Principal;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.springframework.http.server.ServerHttpRequest;
9 import org.springframework.web.socket.WebSocketHandler;
10 import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
13 * In some cases it may be useful to assign an identity to a WebSocket session even when
14 * the user has not been formally authenticated. For example, a mobile app might assign some
15 * identity to anonymous users, perhaps based on geographical location. The do that currently,
16 * an application can sub-class DefaultHandshakeHandler and override the determineUser method.
17 * The custom handshake handler can then be plugged in (see examples in
18 * Section 25.2.4, “Deployment Considerations”)
20 public class CustomHandshakeHandler extends DefaultHandshakeHandler {
21 private static final Logger LOGGER = LoggerFactory.getLogger(CustomHandshakeHandler.class);
24 protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
25 Map<String, Object> attributes) {
27 Principal principal = request.getPrincipal();
28 LOGGER.info("CustomHandshakeHandler: " + principal.getName());
30 return super.determineUser(request, wsHandler, attributes);