package <%=packageName%>.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
import org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer;

@Configuration
public class WebsocketSecurityConfiguration extends AbstractSecurityWebSocketMessageBrokerConfigurer {

    @Override
    protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
        messages
            // message types other than MESSAGE and SUBSCRIBE
            .nullDestMatcher().authenticated()
            // matches any destination that starts with /rooms/
            .simpDestMatchers("/topic/**").authenticated()
            // (i.e. cannot send messages directly to /topic/, /queue/)
            // (i.e. cannot subscribe to /topic/messages/* to get messages sent to
            // /topic/messages-user<id>)
            .simpTypeMatchers(SimpMessageType.MESSAGE, SimpMessageType.SUBSCRIBE).denyAll()
            // catch all
            .anyMessage().denyAll();
    }

    /**
     * Disables CSRF for Websockets.
     */
    @Override
    protected boolean sameOriginDisabled() {
        return true;
    }
}

@@ -27,16 +27,162 @@
 onfig;%0A%0A
+%3C%25_ if (authenticationType == 'session' %7C%7C%C2%A0authenticationType == 'oauth2') %7B _%25%3E%0Aimport %3C%25=packageName%25%3E.security.AuthoritiesConstants;%0A%3C%25_ %7D _%25%3E%0A
 import o
@@ -925,16 +925,326 @@
 /rooms/%0A
+            %3C%25_ if (authenticationType == 'session' %7C%7C%C2%A0authenticationType == 'oauth2') %7B // ignoring authentiation check for authenticationType == 'xauth' since it does not work, see issue #2129 _%25%3E%0A            .simpDestMatchers(%22/topic/tracker%22).hasAuthority(AuthoritiesConstants.ADMIN)%0A            %3C%25_ %7D _%25%3E%0A
         

Fix security issue with tracking logged in users with websocket