【问题标题】:Spring STOMP configure mutual authentication wss/sslSpring STOMP 配置相互认证 wss/ssl
【发布时间】:2021-11-09 12:11:11
【问题描述】:

是否可以在 Spring Boot 中使用码头服务器在 Stomp 客户端/服务器中配置相互身份验证 wss?

我试过了,没有成功。

在客户端代码中,我尝试使用客户端中的用户属性设置 SSLContext。另一个在线示例仅使用 tomcat 属性。

@Service
@Slf4j
public class StompClient {

    @Value("${web-socket.server.endpoint}")
    private String URL;

    private WebSocketStompClient stompClient;

    private StompSession stompSession;

    private MutualAuthConfiguration mutualAuthConfiguration;


    @Autowired
    @Qualifier("MyStompSessionHandler")
    private StompSessionHandler sessionHandler;


    @Autowired
    public StompClient(MutualAuthConfiguration mutualAuthConfiguration) throws GeneralSecurityException, IOException {
        this.mutualAuthConfiguration = mutualAuthConfiguration;


        SSLContext sslContext = new SSLContextBuilder()
                .loadTrustMaterial(mutualAuthConfiguration.getTrustStore().getURL(), mutualAuthConfiguration.getTrustStorePassword().toCharArray())
                .loadKeyMaterial(mutualAuthConfiguration.getKeyStore().getURL(), mutualAuthConfiguration.getKeyStorePassword().toCharArray(), mutualAuthConfiguration.getKeyPassword().toCharArray())
                .build();

        StandardWebSocketClient wsClient = new StandardWebSocketClient();

      //FIXME is OK? i don't find correct properties for jetty.
        wsClient.getUserProperties().put("org.eclipse.jetty.server.SslConnectionFactory", sslContext);


        List<Transport> transports = new ArrayList<>(2);
        transports.add(new WebSocketTransport(wsClient));

        transports.add(new RestTemplateXhrTransport());



        WebSocketClient client = new SockJsClient(transports);

        stompClient = new WebSocketStompClient(client);
        stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    }



}

如何为 wss / ssl 配置服务器部分? 我没有找到任何配置信息

@Configuration
@EnableWebSocketMessageBroker
@Slf4j
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");

    }
  @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {

        registry.addEndpoint("/ws-test")
                .withSockJS()
                .setHeartbeatTime(1000).setWebSocketEnabled(true);
    }

【问题讨论】:

    标签: spring ssl stomp spring-websocket spring-messaging


    【解决方案1】:

    经过几次不成功的测试后,我切换到了这个库

    https://github.com/TooTallNate/Java-WebSocket

    这让我可以做我需要的一切。

    只有spring没有内置的问题。

    【讨论】:

      猜你喜欢
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 2018-01-11
      相关资源
      最近更新 更多