CXF RESTful 客户端 - 如何信任所有证书?
我编写了 Jersey RESTful 客户端,它们使用 Dumb X509TrustManager 和 HostnameVerifier 来信任我们实验室系统上的所有 SSL 证书,以便更轻松地处理自签名证书。
ClientConfig config = new DefaultClientConfig();
SSLContext context = null;
try
{
context = SSLContext.getInstance("SSL");
context.init(null,
new TrustManager[] { new DumbX509TrustManager() },
null);
config.getProperties()
.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
new HTTPSProperties(this.getHostnameVerifier(),
context));
webClient = Client.create(config);
}
....
有没有办法让我使用 CXF 做类似的事情?
I have written Jersey RESTful clients that made use of a Dumb X509TrustManager and HostnameVerifier to trust all SSL certs on our lab systems to make it easier to deal with certs that are self-signed.
ClientConfig config = new DefaultClientConfig();
SSLContext context = null;
try
{
context = SSLContext.getInstance("SSL");
context.init(null,
new TrustManager[] { new DumbX509TrustManager() },
null);
config.getProperties()
.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
new HTTPSProperties(this.getHostnameVerifier(),
context));
webClient = Client.create(config);
}
....
Is there a way for me to do something similar using CXF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自 CXF 邮件列表。请注意,由于其他系统更新,我不必实现它,所以这是理论上的:
This is from the CXF mailing list. Note that I didn't have to implement it due to other system updates, so this is theoretical:
为了完成 sdoca 的答案,这里是一个使用哑 X509 信任管理器的实现:
其中 BlindTrustManager 定义如下:
检查此链接以更好地理解可能会很有用:
To complete the answer from sdoca, here is an implementation with a dumb X509 trust manager:
Where BlindTrustManager is defined as follows:
It may be useful to check this links for a better understanding: