• SpringBoot+CXF下Https调用webservice跳过安全证书的配置


    最近项目中用到了webservice,需要在代码中使用https调用,结果报错了。日志提示:

    PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    经过不懈的百度,发现是需要安全证书,最后发现一个方法可以跳过证书,成功实现https的调用,现在分享给大家!

    import org.apache.cxf.configuration.jsse.TLSClientParameters;
    import org.apache.cxf.endpoint.Client;
    import org.apache.cxf.endpoint.ClientLifeCycleListener;
    import org.apache.cxf.transport.http.HTTPConduit;
    import org.springframework.context.annotation.Configuration;
    
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.X509TrustManager;
    import java.security.cert.CertificateException;
    import java.security.cert.X509Certificate;
    
    /**
     * CXF连接HTTPS跳过安全证书配置
     */
    @Configuration
    public class SkipSecurityAuthenticationListener implements ClientLifeCycleListener {
        @Override
        public void clientCreated(Client client) {
            if (client.getConduit() instanceof HTTPConduit) {
                HTTPConduit conduit = (HTTPConduit) client.getConduit();
    
                TLSClientParameters params = conduit.getTlsClientParameters();
    
                if (params == null) {
                    params = new TLSClientParameters();
                    conduit.setTlsClientParameters(params);
                }
    
                params.setTrustManagers(new TrustManager[] {
                        new TrustAllManager() });
    
                params.setDisableCNCheck(true);
            }
        }
    
        @Override
        public void clientDestroyed(Client client) {
            // Do Nothing
        }
    
    
    
        private class TrustAllManager implements X509TrustManager {
    
            @Override
            public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
    
            }
    
    
            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Do Nothing
            }
    
            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
    
        }
    
    }
  • 相关阅读:
    JS原始类型Number数字类型
    JS数据类型基础知识
    JS基础循环语句和跳转语句
    JS对象类型数组方法篇
    JS对象类型数组基础篇
    JS基础逻辑运算符
    IE6,IE7,FF等浏览器不兼容原因及解决办法(转)
    DML、DDL、DCL区别
    Asp.net(c#)GridView分页时用图片显示上一页,下一页
    P3P完成跨域COOKIE
  • 原文地址:https://www.cnblogs.com/noahpk/p/13992737.html
Copyright © 2020-2023  润新知