如何以编程方式为 Tyrus WebSocket @ServerEndpoint 启用 WSS [英] How can I programmatically enable WSS for a Tyrus WebSocket @ServerEndpoint

查看:99
本文介绍了如何以编程方式为 Tyrus WebSocket @ServerEndpoint 启用 WSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个微服务,它有一个 REST 端点和一个 WebSocket 端点.

I have a microservice that has a REST endpoint and a WebSocket endpoint.

它连接 Grizzly 和 Tyrus,并使用 JAX-RS 过滤器和 ServerEndpointConfig.Configurator 通过 SSO 添加身份验证.我已使用 SSLContextConfigurator 和 SSLEngineConfigurator 以及(当前)自签名证书将 SSL 添加到 REST 端点.

It Spring-wires Grizzly and Tyrus, and adds in authentication via SSO using a JAX-RS filter and a ServerEndpointConfig.Configurator. I've added in SSL to the REST endpoint using SSLContextConfigurator and SSLEngineConfigurator and a (currently) self-signed certificate.

我看不到在 Tyrus 1.14 中对 org.glassfish.tyrus.server.Server 执行相同操作的方法.

I don't see a way to do the same for org.glassfish.tyrus.server.Server in Tyrus 1.14.

事实上,代码硬连线了协议名称,这让我怀疑这是否可能:

In fact, the code hardwires the protocol name, which makes me wonder if this is even possible:

LOGGER.info("WebSocket 注册的应用程序:URL 都以 ws://开头" + this.hostName + ":" + this.getPort());

这里有一个类似的问题但它需要将 WAR 文件部署到完整的 Glassfish 实例.我想以编程方式执行此操作.

There's a similar question here but it requires deploying a WAR file to a full-on Glassfish instance. I want to do this programmatically.

推荐答案

使用 https://stackoverflow.com/上的建议解决a/27239122/17641

<代码>listener = new NetworkListener("grizzly", "0.0.0.0", port);listener.setSecure(true);listener.setSSLEngineConfig(new SSLEngineConfigurator(getSslContextConfigurator()).setClientMode(false).setNeedClientAuth(false));

其中 getSslContextConfigurator 使用密钥库字节 [] 和密码构造一个 org.glassfish.grizzly.ssl.SSLContextConfigurator.

Where getSslContextConfigurator constructs a org.glassfish.grizzly.ssl.SSLContextConfigurator with a keystore byte[] and password.

这篇关于如何以编程方式为 Tyrus WebSocket @ServerEndpoint 启用 WSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆