10

I'm trying to learn more about Spring-Websocket in combination with Spring-Security and was trying out the examples from the Spring Documentation.

After creating my class WebSecurityConfig and extending from AbstractWebSocketMessageBrokerConfigurer I was informed that AbstractWebSocketMessageBrokerConfigurer is deprecated.

I tried to find out if there is an alternative to use Spring-Security with Spring-Websocket but couldn't find something on that.

So, my question is should I still use AbstractWebSocketMessageBrokerConfigurer or is there an alternative way to combine Spring-Security with Spring-Websocket?

This is the example I implemented to my test project. It seems to working thine, but shouldn't be there an alternative from Spring before making AbstractWebSocketMessageBrokerConfigurer deprecated?

@Configuration
public class WebSocketSecurityConfig extends AbstractWebSocketMessageBrokerConfigurer {

        protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
                messages.simpDestMatchers("/user/*").authenticated();
        }
}
Constantin Beer
  • 5,447
  • 6
  • 25
  • 43

1 Answers1

28

Please, read JavaDocs of that deprecated class:

 * @deprecated as of 5.0 in favor of simply using {@link WebSocketMessageBrokerConfigurer}
 * which has default methods, made possible by a Java 8 baseline.
 */
@Deprecated
public abstract class AbstractWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 4
    Do you see this in your IDE? In IntelliJ I just have the `/** @deprecated */` comment. But after your answer I looked again in the Spring Docs and really embarrassed that I overlooked the comment under the `Deprecated`. – Constantin Beer Sep 18 '19 at 15:50
  • 6
    Well, I always have source code attached to the project, so when I see a deprecating warning, I jump into source code to determine the reason and alternatives. All thanks to Open Source nature of Spring! – Artem Bilan Sep 18 '19 at 15:52
  • You can download the source of decompiled classes by using "Download Sources" option in IntelliJ when you open the class. It contains the Javadoc comments. – VishnuVS Feb 27 '23 at 09:23