content: package com.alibaba.tesla.authproxy.component.okhttp;
  
  import okhttp3.OkHttpClient;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  import javax.net.ssl.SSLContext;
  import javax.net.ssl.SSLSocketFactory;
  import javax.net.ssl.TrustManager;
  import javax.net.ssl.X509TrustManager;
  import java.security.KeyManagementException;
  import java.security.NoSuchAlgorithmException;
  import java.security.cert.CertificateException;
  
  /**
   * OkHttp Client
   *
   * @author yaoxing.gyx@alibaba-inc.com
   */
  @Configuration
  public class OkHttpConfig {
  
      private static final TrustManager[] trustAllCerts = new TrustManager[]{
              new X509TrustManager() {
                  @Override
                  public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
                          throws CertificateException {
                  }
  
                  @Override
                  public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType)
                          throws CertificateException {
                  }
  
                  @Override
                  public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                      return new java.security.cert.X509Certificate[]{};
                  }
              }
      };
      private static final SSLContext trustAllSslContext;
      static {
          try {
              trustAllSslContext = SSLContext.getInstance("SSL");
              trustAllSslContext.init(null, trustAllCerts, new java.security.SecureRandom());
          } catch (NoSuchAlgorithmException | KeyManagementException e) {
              throw new RuntimeException(e);
          }
      }
      private static final SSLSocketFactory trustAllSslSocketFactory = trustAllSslContext.getSocketFactory();
  
      @Bean
      public OkHttpClient okHttpClient() {
          OkHttpClient.Builder builder = new OkHttpClient.Builder();
          builder.sslSocketFactory(trustAllSslSocketFactory, (X509TrustManager) trustAllCerts[0]);
          builder.hostnameVerifier((hostname, session) -> true);
          return builder.build();
      }
  
  }
  