Skip to content

Instantly share code, notes, and snippets.

@K0NRAD
Created July 2, 2019 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save K0NRAD/ad7d8011b3438c6070e023d4d1eaf5dc to your computer and use it in GitHub Desktop.
Save K0NRAD/ad7d8011b3438c6070e023d4d1eaf5dc to your computer and use it in GitHub Desktop.
RestTemplate keycloak Admin API insecure
@Bean
public RestTemplate keycloakAdminApiInsecure() {
try {
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 RestTemplateBuilder()
.rootUri(keycloakProperties.getAuthServerUrl())
.requestFactory(requestFactory)
.build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
throw new RuntimeException(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment