All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.baseinsight.plugin.springsecurity.websocket.WebSocketConfig Maven / Gradle / Ivy

The newest version!
package info.baseinsight.plugin.springsecurity.websocket;

/**
 * Created by @Author:xiaopeng on 2023/7/9.
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.StompWebSocketEndpointRegistration;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

import java.util.List;

@Component
@Configuration
@EnableConfigurationProperties({WebSocketProperties.class})
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Autowired
    WebSocketProperties webSocketProperties;
    @Value("${server.servlet.contextPath}")
    String contextPath="/";

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker(webSocketProperties.getTopicBroker(),webSocketProperties.getQueueBroker());
        config.setApplicationDestinationPrefixes(contextPath);
        config.setUserDestinationPrefix(webSocketProperties.getUserDestinationPrefix());
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        StompWebSocketEndpointRegistration stompWebSocketEndpointRegistration=registry.addEndpoint(webSocketProperties.getStompEndpoint());
        if(webSocketProperties.getAllowedOrigins()!=null){
            stompWebSocketEndpointRegistration.setAllowedOrigins(webSocketProperties.getAllowedOrigins());
        }
        stompWebSocketEndpointRegistration.withSockJS();
    }

    /*  @Override
      void configureWebSocketTransport(WebSocketTransportRegistration registry) {

      }

      @Override
      void configureClientInboundChannel(ChannelRegistration registration) {

      }

      @Override
      void configureClientOutboundChannel(ChannelRegistration registration) {

      }

      @Override
      void addArgumentResolvers(List argumentResolvers) {

      }

      @Override
      void addReturnValueHandlers(List returnValueHandlers) {

      }
  */
    @Override
    public boolean configureMessageConverters(List messageConverters) {
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy