Java Code Examples for org.glassfish.jersey.SslConfigurator#newInstance()

The following examples show how to use org.glassfish.jersey.SslConfigurator#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRestClient.java    From hugegraph-common with Apache License 2.0 7 votes vote down vote up
private static Client wrapTrustConfig(String url, ClientConfig config) {
    SslConfigurator sslConfig = SslConfigurator.newInstance();
    String trustStoreFile = config.getProperty("trustStoreFile").toString();
    String trustStorePassword = config.getProperty("trustStorePassword")
                                      .toString();
    sslConfig.trustStoreFile(trustStoreFile)
             .trustStorePassword(trustStorePassword);
    sslConfig.securityProtocol("SSL");
    SSLContext context = sslConfig.createSSLContext();
    TrustManager[] trustAllManager = NoCheckTrustManager.create();
    try {
        context.init(null, trustAllManager, new SecureRandom());
    } catch (KeyManagementException e) {
        throw new ClientException("Failed to init security management", e);
    }
    return ClientBuilder.newBuilder()
                        .hostnameVerifier(new HostNameVerifier(url))
                        .sslContext(context)
                        .build();
}
 
Example 2
Source File: SchemaRegistryClient.java    From registry with Apache License 2.0 6 votes vote down vote up
protected SSLContext createSSLContext(Map<String, String> sslConfigurations) {
    SslConfigurator sslConfigurator = SslConfigurator.newInstance();
    if (sslConfigurations.containsKey(SSL_KEY_STORE_PATH)) {
        sslConfigurator.keyStoreType(sslConfigurations.get("keyStoreType"))
                       .keyStoreFile(sslConfigurations.get(SSL_KEY_STORE_PATH))
                       .keyStorePassword(sslConfigurations.get("keyStorePassword"))
                       .keyStoreProvider(sslConfigurations.get("keyStoreProvider"))
                       .keyManagerFactoryAlgorithm(sslConfigurations.get("keyManagerFactoryAlgorithm"))
                       .keyManagerFactoryProvider(sslConfigurations.get("keyManagerFactoryProvider"));
        if (sslConfigurations.containsKey(SSL_KEY_PASSWORD)) {
            sslConfigurator.keyPassword(sslConfigurations.get(SSL_KEY_PASSWORD));
        }
    }


    sslConfigurator.trustStoreType(sslConfigurations.get("trustStoreType"))
                   .trustStoreFile(sslConfigurations.get("trustStorePath"))
                   .trustStorePassword(sslConfigurations.get("trustStorePassword"))
                   .trustStoreProvider(sslConfigurations.get("trustStoreProvider"))
                   .trustManagerFactoryAlgorithm(sslConfigurations.get("trustManagerFactoryAlgorithm"))
                   .trustManagerFactoryProvider(sslConfigurations.get("trustManagerFactoryProvider"));

    sslConfigurator.securityProtocol(sslConfigurations.get("protocol"));

    return sslConfigurator.createSSLContext();
}
 
Example 3
Source File: SchemaRegistryClient.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected SSLContext createSSLContext(Map<String, String> sslConfigurations) {
    SslConfigurator sslConfigurator = SslConfigurator.newInstance();
    if (sslConfigurations.containsKey(SSL_KEY_STORE_PATH)) {
        sslConfigurator.keyStoreType(sslConfigurations.get("keyStoreType"))
                .keyStoreFile(sslConfigurations.get(SSL_KEY_STORE_PATH))
                .keyStorePassword(sslConfigurations.get("keyStorePassword"))
                .keyStoreProvider(sslConfigurations.get("keyStoreProvider"))
                .keyManagerFactoryAlgorithm(sslConfigurations.get("keyManagerFactoryAlgorithm"))
                .keyManagerFactoryProvider(sslConfigurations.get("keyManagerFactoryProvider"));
        if (sslConfigurations.containsKey(SSL_KEY_PASSWORD)) {
            sslConfigurator.keyPassword(sslConfigurations.get(SSL_KEY_PASSWORD));
        }
    }


    sslConfigurator.trustStoreType(sslConfigurations.get("trustStoreType"))
            .trustStoreFile(sslConfigurations.get("trustStorePath"))
            .trustStorePassword(sslConfigurations.get("trustStorePassword"))
            .trustStoreProvider(sslConfigurations.get("trustStoreProvider"))
            .trustManagerFactoryAlgorithm(sslConfigurations.get("trustManagerFactoryAlgorithm"))
            .trustManagerFactoryProvider(sslConfigurations.get("trustManagerFactoryProvider"));

    sslConfigurator.securityProtocol(sslConfigurations.get("protocol"));

    return sslConfigurator.createSSLContext();
}
 
Example 4
Source File: GeoServerRestClient.java    From geowave with Apache License 2.0 5 votes vote down vote up
private WebTarget getWebTarget() {
  if (webTarget == null) {
    String url = getConfig().getUrl();
    if (url != null) {
      url = url.trim().toLowerCase(Locale.ROOT);
      Client client = null;
      if (url.startsWith("http://")) {
        client = ClientBuilder.newClient();
      } else if (url.startsWith("https://")) {
        final SslConfigurator sslConfig = SslConfigurator.newInstance();
        if (getConfig().getGsConfigProperties() != null) {
          loadSSLConfigurations(sslConfig, getConfig().getGsConfigProperties());
        }
        final SSLContext sslContext = sslConfig.createSSLContext();

        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
        client = ClientBuilder.newBuilder().sslContext(sslContext).build();
      }
      if (client != null) {
        client.register(
            HttpAuthenticationFeature.basic(getConfig().getUser(), getConfig().getPass()));
        try {
          webTarget = client.target(new URI(url));
        } catch (final URISyntaxException e) {
          LOGGER.error("Unable to parse geoserver URL: " + url, e);
        }
      }
    }
  }

  return webTarget;
}