title: How To By-pass SSL Certificate Validation in spring-boot-admin?
body: <p>So I'm able to disable the SBA Admin server from validating SSL certs from the clients it tries to connect to - for SBA version 2.6.2 it is more or less outlined right from their documentation: <a href="https://codecentric.github.io/spring-boot-admin/current/#_using_mutual_tls" rel="nofollow noreferrer">https://codecentric.github.io/spring-boot-admin/current/#_using_mutual_tls</a></p>
  <p>Here is the complete configuration overriding bean:</p>
  <pre><code>package com.markham.mkmappadmin.config;
  
  import javax.net.ssl.SSLException;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.client.reactive.ClientHttpConnector;
  import org.springframework.http.client.reactive.ReactorClientHttpConnector;
  
  import io.netty.handler.ssl.SslContext;
  import io.netty.handler.ssl.SslContextBuilder;
  import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
  import reactor.netty.http.client.HttpClient;
  
  /**
   * Custom http client class which overrides Spring Boot Admin's server default client.&lt;br&gt;
   * The custom client will bypass any SSL Validation by configuring an instance of
   *  {@link InsecureTrustManagerFactory}
   * @author Hanif Rajabali
   * @see &lt;a href=&quot;https://codecentric.github.io/spring-boot-admin/current/#_using_mutual_tls&quot;&gt;Spring Boot Admin 2.6.2 Using Mutual TLS&lt;/a&gt;
   */
  @Configuration
  public class CustomHttpClientConfig {
  
      @Bean
      public ClientHttpConnector customHttpClient() throws SSLException {
          SslContext sslContext = SslContextBuilder
                .forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                .build();
          HttpClient httpClient = HttpClient.create().secure(
              ssl -&gt; ssl.sslContext(sslContext)
          );
          return new ReactorClientHttpConnector(httpClient);
      }
  
  }
  </code></pre>
  <p>What I still haven't figured out is how to disable it from the SBA client. I have a custom RestTemplate Config defined below, but the SBA client doesn't seem to be picking it up even though I see that the SBA client code is using the BlockingRegistrationClient i.e) RestTemplate</p>
  <pre><code>package com.markham.mkmemailerws.config;
  
  import java.security.KeyManagementException;
  import java.security.NoSuchAlgorithmException;
  import java.security.cert.X509Certificate;
  
  import javax.net.ssl.SSLContext;
  import javax.net.ssl.TrustManager;
  import javax.net.ssl.X509TrustManager;
  
  import org.apache.http.conn.ssl.NoopHostnameVerifier;
  import org.apache.http.impl.client.CloseableHttpClient;
  import org.apache.http.impl.client.HttpClients;
  import org.springframework.boot.web.client.RestTemplateBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
  import org.springframework.web.client.RestTemplate;
  
  /**
   * Need to explicitly build Spring Boot's auto configured
   * {@link #restTemplate(RestTemplateBuilder)}
   *
   * @author Hanif Rajabali
   *
   */
  @Configuration
  public class RestTemplateConfig {
  
  //   @Bean
  //   public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
  //      return restTemplateBuilder.build();
  //   }
  
  
      /**
       * The following will bypass ssl validation altogether. Not ideal.
       */
      @Bean
      public RestTemplate restTemplate(RestTemplateBuilder builder)
              throws NoSuchAlgorithmException, KeyManagementException {
  
          TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                  return new X509Certificate[0];
              }
  
              public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
              }
  
              public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
              }
          } };
          SSLContext sslContext = SSLContext.getInstance(&quot;SSL&quot;);
          sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
          CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext)
                  .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
          HttpComponentsClientHttpRequestFactory customRequestFactory = new HttpComponentsClientHttpRequestFactory();
          customRequestFactory.setHttpClient(httpClient);
          return builder.requestFactory(() -&gt; customRequestFactory).build();
      }
  }
  </code></pre>