首页 > 解决方案 > 使用 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 {
}

标签: javahttpscertificateaxis2

解决方案


“不受信任的服务器证书链”意味着您的客户端不信任试图建立连接的服务器证书。为了正确配置启用 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.

通常是需要信任服务器证书链来建立连接的客户端,因为服务器可以在匿名模式下运行,而不需要从对等方请求客户端证书。


推荐阅读