Created
July 2, 2019 13:29
-
-
Save K0NRAD/ad7d8011b3438c6070e023d4d1eaf5dc to your computer and use it in GitHub Desktop.
RestTemplate keycloak Admin API insecure
This file contains hidden or 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
@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