您的位置:首页 > 理论基础 > 计算机网络

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

2017-12-21 10:25 1016 查看
本人在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sso
相关文章推荐