增加resttemplate的https功能
This commit is contained in:
parent
0801addf03
commit
3533ae4c32
@ -16,16 +16,15 @@ import java.security.cert.X509Certificate;
|
|||||||
* @Date: 2022/3/28 17:34
|
* @Date: 2022/3/28 17:34
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
* TLS的三个作用:
|
* TLS的三个作用:
|
||||||
* (1)身份认证
|
* (1)身份认证
|
||||||
* 通过证书认证来确认对方的身份,防止中间人攻击
|
* 通过证书认证来确认对方的身份,防止中间人攻击
|
||||||
* (2)数据私密性
|
* (2)数据私密性
|
||||||
* 使用对称性密钥加密传输的数据,由于密钥只有客户端/服务端有,其他人无法窥探。
|
* 使用对称性密钥加密传输的数据,由于密钥只有客户端/服务端有,其他人无法窥探。
|
||||||
* (3)数据完整性
|
* (3)数据完整性
|
||||||
* 使用摘要算法对报文进行计算,收到消息后校验该值防止数据被篡改或丢失。
|
* 使用摘要算法对报文进行计算,收到消息后校验该值防止数据被篡改或丢失。
|
||||||
*
|
* <p>
|
||||||
* 使用RestTemplate进行HTTPS请求访问:
|
* 使用RestTemplate进行HTTPS请求访问:
|
||||||
* private static RestTemplate restTemplate = new RestTemplate(new HttpsClientRequestFactory());
|
* private static RestTemplate restTemplate = new RestTemplate(new HttpsClientRequestFactory());
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class HttpsClientRequestFactory extends SimpleClientHttpRequestFactory {
|
public class HttpsClientRequestFactory extends SimpleClientHttpRequestFactory {
|
||||||
|
|
||||||
@ -129,7 +128,6 @@ public class HttpsClientRequestFactory extends SimpleClientHttpRequestFactory {
|
|||||||
if (!(socket instanceof SSLSocket)) {
|
if (!(socket instanceof SSLSocket)) {
|
||||||
throw new RuntimeException("An instance of SSLSocket is expected");
|
throw new RuntimeException("An instance of SSLSocket is expected");
|
||||||
}
|
}
|
||||||
//((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.2"});
|
|
||||||
((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"});
|
((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"});
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user