title: Spring websocket send to specific people
body: <p>I have added custom token based authentication for my spring-web app and extending the same for spring websocket as shown below</p>
  
  <pre><code>public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry config) {
          config.enableSimpleBroker("/topic", "/queue");
          config.setApplicationDestinationPrefixes("/app");
          config.setUserDestinationPrefix("/user");
      }
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint("/gs-guide-websocket").setAllowedOrigins("*").withSockJS();
      }
  
      @Override
        public void configureClientInboundChannel(ChannelRegistration registration) {
          registration.setInterceptors(new ChannelInterceptorAdapter() {
  
              @Override
              public Message&lt;?&gt; preSend(Message&lt;?&gt; message, MessageChannel channel) {
  
                  StompHeaderAccessor accessor =
                      MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
  
                  if (StompCommand.CONNECT.equals(accessor.getCommand())) {
                      String jwtToken = accessor.getFirstNativeHeader("Auth-Token");
                          if (!StringUtils.isEmpty(jwtToken)) {
                              Authentication auth = tokenService.retrieveUserAuthToken(jwtToken);
                              SecurityContextHolder.getContext().setAuthentication(auth);
                              accessor.setUser(auth);
                              //for Auth-Token '12345token' the user name is 'user1' as auth.getName() returns 'user1'
                          }
                  }
  
                  return message;
              }
          });
        }
  }
  </code></pre>
  
  <p>The client side code to connect to the socket is</p>
  
  <pre><code>var socket = new SockJS('http://localhost:8080/gs-guide-websocket');
      stompClient = Stomp.over(socket);
      stompClient.connect({'Auth-Token': '12345token'}, function (frame) {
          stompClient.subscribe('/user/queue/greetings', function (greeting) {
              alert(greeting.body);
          });
      });
  </code></pre>
  
  <p>And from my controller I am sending message as </p>
  
  <pre><code>messagingTemplate.convertAndSendToUser("user1", "/queue/greetings", "Hi User1");
  </code></pre>
  
  <p>For the auth token <code>12345token</code> the user name is <code>user1</code>. But when I send a message to <code>user1</code>, its not received at the client end. Is there anything I am missing with this?</p>