Spring STOMP 配置相互认证 wss/ssl

标签 spring ssl stomp spring-websocket spring-messaging

是否可以在 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);
    }

最佳答案

经过几次不成功的测试后,我切换到了这个库
https://github.com/TooTallNate/Java-WebSocket
这让我可以做我需要的一切。
唯一没有内置在 spring 中的问题。

关于Spring STOMP 配置相互认证 wss/ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69175581/

相关文章:

java - 将 net.sf.ehcache.CacheManger 转换为 org.springframework.cache.CacheManager?

maven - Intellij Maven Repository 自签名证书,ssl 错误

java - 使用 JAVA 连接到 JIRA REST API 时握手失败

python - Twisted 是否有广泛使用的 STOMP 适配器?

java - 如何限制客户端连接到我的 stomp websocket 处理程序?

perl - 如何将事务与 Stomp 和 ActiveMQ(和 Perl)一起使用?

java - 不将数据保存到数据库中。 Hibernate和Spring的连接

spring - 仅在第一次调用时调查 HTTP 406 错误代码

java - spring mvc 中的 org.springframework.dao.QueryTimeoutException

c# - 树莓派 2(IoT) http客户端错误 : The certificate authority is invalid or incorrect c#