java - 使用 https 使用不同的 web 服务但只有一个使用证书身份验证后的 Axis2 问题
问题描述
我有一个 Java Web 应用程序,它使用不同的 WebServices。现在我必须使用一个需要双向身份验证的 WebService。我使用SSLClientAxisEngineConfig
实现(https://github.com/linhkuivanen/axistools)作为参数发送给我的扩展类org.apache.axis.client.Service
。有效。但前提是它是第一次使用一些Axis Client
. 之后,如果我使用不需要证书的“https”WebService,我会收到错误“不受信任的服务器证书链”。
如果我首先使用一个不需要证书身份验证的 Web 服务,当我尝试使用另一个需要身份验证的 Web 服务时,我会收到“握手失败”错误。
我假设Axis
有某种缓存可以重用第一个配置,但我无法找到解决问题的方法。
编辑:我解决了这个问题。wsdl2java
我使用(Axis2-1.7.8)生成了一个新的 Axis 客户端,而不是使用 Eclipse Web 服务客户端生成器。在使用 WebService 之前,我https
使用客户端证书和 cacerts 注册了一个新协议:
Protocol protocol = new Protocol("https", socketFactoryDinamico, 443);
Protocol.registerProtocol("https", protocol);
使用它后,我取消注册协议:
Protocol.unregisterProtocol("https");
在此之后,我可以毫无问题地使用其他 WebServices 而无需证书身份验证。
编辑2:
Eclipse 生成的类:
public class NfseWSServiceLocator extends org.apache.axis.client.Service implements NfseWSService {
}
public interface NfseWSService extends javax.xml.rpc.Service {
}
Axis2生成的类:
public class NfseWSServiceStub extends org.apache.axis2.client.Stub {
}
解决方案
“不受信任的服务器证书链”意味着您的客户端不信任试图建立连接的服务器证书。为了正确配置启用 HTTPS 的通信场景,通信双方必须相互信任。
RFC 5246定义了以下内容:
未知的_ca
A valid certificate chain or partial chain was received, but the
certificate was not accepted because the CA certificate could not
be located or couldn't be matched with a known, trusted CA. This
message is always fatal.
通常是需要信任服务器证书链来建立连接的客户端,因为服务器可以在匿名模式下运行,而不需要从对等方请求客户端证书。
推荐阅读
- python - 如何使用 ./ 运行方法而不是通过 Python3 调用
- reactjs - 在 setInterval 中反应 setState
- python - 裁剪图像并粘贴到与源相同的坐标中
- python - Python Pandas:在 lambda / TypeError 中使用映射函数:(“int() 参数必须是字符串、类似字节的对象或数字,而不是“列表””
- html - 在带有图像和文本的引导轮播中,我可以有在模式或新浏览器窗口中打开图像的链接吗?
- hibernate - hibernate - 即使在父记录之前删除子记录后,外键约束也会失败
- java - 如何将@RequestBody 有效负载映射到构建器类
- java - 将 Firebase Crashlytics 添加到 Android 时出现“重复类 javax.inject.*”构建错误
- javascript - Parcel 不适用于简单的 html 和 Ts 文件
- java - 按字段搜索不同类和不同列表 Java 8 Stream