Last active
October 12, 2018 09:22
-
-
Save mruv/71e086fda71cd2b86b9840ceee0c72e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class RestTemplateSslConfig { | |
@Bean("httpsRestTemplate") | |
@Scope("singleton") | |
public RestTemplate httpsRestTemplate() | |
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { | |
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; | |
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom() | |
.loadTrustMaterial(null, acceptingTrustStrategy) | |
.build(); | |
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); | |
CloseableHttpClient httpClient = HttpClients.custom() | |
.setSSLSocketFactory(csf) | |
.build(); | |
HttpComponentsClientHttpRequestFactory requestFactory | |
= new HttpComponentsClientHttpRequestFactory(); | |
requestFactory.setHttpClient(httpClient); | |
return new RestTemplate(requestFactory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment