Dropwizard相当新。

我找到了很多解决方案来处理Jersey和ssl自签名证书。
Dropwizard版本为0.9.2

我试图设置一个SSLContext但我得到了

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


码:

   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;
  }


配置部分:

private JerseyClientConfiguration jerseyClient = new JerseyClientConfiguration();

public JerseyClientConfiguration getJerseyClient() {
    return jerseyClient;
}

最佳答案

我发现仅使用配置的简单解决方案

jerseyClient:
  tls:
    verifyHostname: false
    trustSelfSignedCertificates: true

关于ssl - Dropwizard客户处理自签名证书,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40078700/

10-16 14:25