hessian,SSO,CAS调用https不受信任之跳过证书验证(unable to find valid certification path to requested target )

来源:互联网 发布:mp288打印机清零软件 编辑:程序博客网 时间:2024/06/01 08:10

本人在CAS进行单点登录的时候出现了地址为https,单点不能访问系统,报错unable to find valid certification path to requested target,其最终原因是缺少安全证书时出现的异常。以下是找到的2种解决办法

解决办法一:

public class SslUtil {public static CloseableHttpClient SslHttpClientBuild() {Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", trustAllHttpsCertificates()).build();//创建ConnectionManager,添加Connection配置信息PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();return httpClient;}private static SSLConnectionSocketFactory trustAllHttpsCertificates() {SSLConnectionSocketFactory socketFactory = null;TrustManager[] trustAllCerts = new TrustManager[1];TrustManager tm = new miTM();trustAllCerts[0] = tm;SSLContext sc = null;try {sc = SSLContext.getInstance("TLS");//sc = SSLContext.getInstance("TLS")sc.init(null, trustAllCerts, null);socketFactory = new SSLConnectionSocketFactory(sc, NoopHostnameVerifier.INSTANCE);//HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());} catch (NoSuchAlgorithmException e) {e.printStackTrace();} catch (KeyManagementException e) {e.printStackTrace();}return socketFactory;}static class miTM implements TrustManager, X509TrustManager {public X509Certificate[] getAcceptedIssuers() {return null;}public void checkServerTrusted(X509Certificate[] certs, String authType) {//don't check}public void checkClientTrusted(X509Certificate[] certs, String authType) {//don't check}}}

解决办法二:

http://blog.csdn.net/faye0412/article/details/6883879




阅读全文
0 0
原创粉丝点击