【问题标题】:Equivalent of org.apache.axis.components.net.SunFakeTrustSocketFactory for wsimport等效于 wsimport 的 org.apache.axis.components.net.SunFakeTrustSocketFactory
【发布时间】:2015-08-18 15:50:16
【问题描述】:

当我使用 Apache Axis 生成 Web 服务客户端存根时,我通过调用以下方法使用客户端存根在我的代码中禁用服务器证书信任检查

AxisProperties.setProperty("axis.socketSecureFactory",
     "org.apache.axis.components.net.SunFakeTrustSocketFactory");

如何禁用通过运行wsimport 生成的客户端存根的信任检查?

我在运行一些测试代码时使用它。

【问题讨论】:

    标签: java web-services jax-ws axis wsimport


    【解决方案1】:

    该课程中发生的所有事情都是提供虚假的trust store manager,即trusts anything。知道了这一点,您可以使用this article 并将一些东西放在一起。

    1. 首先是easy trust manager

      public class EasyTrustManager implements X509TrustManager {
        public void checkClientTrusted(X509Certificate[] chain, String authType) {
              //do nothing
        }
      
        public void checkServerTrusted(X509Certificate[] chain, String authType) {
             //do nothing
        }
      
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
             return null;
        }
      }
      
    2. 然后将您的信任管理器提供给SSLContext 的实例,就像axis was doing 一样:

      SSLContext sCtxt = SSLContext.getInstance("SSL"); 
      sCtxt.init(null, new TrustManager[]{new EasyTrustManager()}, new java.security.SecureRandom()); 
      
    3. 通过调用HttpsURLConnection#setDefaultSSLSocketFactory 来设置自定义上下文,因为您的所有Web 服务调用都基于HttpsURLConnection 的底层实例。此调用将通过SSLContext#getContext所有 https 调用

      设置上下文
      HttpsURLConnection.setDefaultSSLSocketFactory(sCtxt.getSocketFactory());  
      

    【讨论】:

    • 必须编辑您的 EasyTrustManager 才能使其编译。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 2017-06-20
    • 2019-05-04
    相关资源
    最近更新 更多