Skip to content

Instantly share code, notes, and snippets.

@mruv
Last active October 12, 2018 09:22
Show Gist options
  • Save mruv/71e086fda71cd2b86b9840ceee0c72e1 to your computer and use it in GitHub Desktop.
Save mruv/71e086fda71cd2b86b9840ceee0c72e1 to your computer and use it in GitHub Desktop.
@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