Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropwizard client deal with self signed certificate

Quite new with Dropwizard.

I found a lot of solution to deal with Jersey and ssl self signed certificate. Dropwizard version is 0.9.2

I have tried to set a SSLContext but I get

The method sslContext(SSLContext) is undefined for the type JerseyClientBuilder

Code:

   TrustManager[] certs = new TrustManager[]{
          new X509TrustManager() {
              @Override
              public X509Certificate[] getAcceptedIssuers() {
                  return null;
              }

              @Override
              public void checkServerTrusted(X509Certificate[] chain, String authType)
                      throws CertificateException {
              }

              @Override
              public void checkClientTrusted(X509Certificate[] chain, String authType)
                      throws CertificateException {
              }
          }
  };

  public static class TrustAllHostNameVerifier implements HostnameVerifier {

      public boolean verify(String hostname, SSLSession session) {
          return true;
      }

  }
  private Client getWebClient(AppConfiguration configuration, Environment env) {
      SSLContext ctx = SSLContext.getInstance("SSL");
      ctx.init(null, certs, new SecureRandom());
      Client client = new JerseyClientBuilder(env)
          .using(configuration.getJerseyClient())
          .sslContext(ctx)
          .build("MyClient");
      return client;
  }

The configuration part:

private JerseyClientConfiguration jerseyClient = new JerseyClientConfiguration();

public JerseyClientConfiguration getJerseyClient() {
    return jerseyClient;   
} 
like image 491
Ôrel Avatar asked Dec 31 '25 18:12

Ôrel


1 Answers

I have found a simple solution just using the configuration

jerseyClient:
  tls:
    verifyHostname: false
    trustSelfSignedCertificates: true
like image 75
Ôrel Avatar answered Jan 04 '26 23:01

Ôrel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!