clientBuilder.hostnameVerifier(hostnameVerifier);
/** * A helper method for creating clients. The client will be created using * the given configuration and security context. Additionally, the client * will be automatically configured for JSON serialization/deserialization. * * @param config client configuration * @param ctx security context, which may be null for non-secure client * creation * @return a Client instance */ private static Client createClientHelper(final ClientConfig config, final SSLContext ctx) { ClientBuilder clientBuilder = ClientBuilder.newBuilder(); if (config != null) { clientBuilder = clientBuilder.withConfig(config); } if (ctx != null) { // Apache http DefaultHostnameVerifier that checks subject alternative names against the hostname of the URI clientBuilder = clientBuilder.sslContext(ctx).hostnameVerifier(new DefaultHostnameVerifier()); } clientBuilder = clientBuilder.register(ObjectMapperResolver.class).register(JacksonJaxbJsonProvider.class); return clientBuilder.build(); }
clientBuilder.hostnameVerifier(hostnameVerifier);
/** * Registers the hostname verifier. * * @param hostnameVerifier the hostname verifier * @return the builder instance */ public ClientBuilderConfigurer hostnameVerifier(HostnameVerifier hostnameVerifier) { builder().hostnameVerifier(hostnameVerifier); return this; }
ClientBuilder builder = ClientBuilder.newBuilder(); builder.sslContext(ConnectionFactory.getSslContext()); builder.hostnameVerifier(ConnectionFactory.getHostnameVerifier()); client = builder.build(); String baseURI = acsUser.getSelectedService().getWebserviceBaseUrl(); WebTarget webTarget = client.target(baseURI);
protected void configureSecurityContext(ClientBuilder builder) { if (armInsecure) { try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { new TrustAllManager() }, new java.security.SecureRandom()); builder.hostnameVerifier(new DummyHostnameVerifier()).sslContext(sslcontext); } catch (KeyManagementException | NoSuchAlgorithmException e) { throw new RuntimeException(e); } } }
public static <T> ClientWrapper<T> httpsInstance(Class<T> resultClass) { try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts(), new java.security.SecureRandom()); Client client = ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier(acceptAnyHost()).build(); return new ClientWrapper(client, resultClass); } catch (NoSuchAlgorithmException | KeyManagementException ex) { throw new IllegalStateException(ex); } }
private void setTrustStore(ClientBuilder clientBuilder, DACConfig dacConfig) throws IOException, GeneralSecurityException { Optional<KeyStore> trustStore = Optional.empty(); if (checkCertificates) { trustStore = new SSLConfigurator(dacConfig.getConfig(), DremioConfig.WEB_SSL_PREFIX, "web").getTrustStore(); if (trustStore.isPresent()) { clientBuilder.trustStore(trustStore.get()); } } else { SSLContext sslContext = SSLHelper.newAllTrustingSSLContext("SSL"); HostnameVerifier verifier = SSLHelper.newAllValidHostnameVerifier(); clientBuilder.hostnameVerifier(verifier); clientBuilder.sslContext(sslContext); } }
public static <T> ClientWrapper<T> httpsInstance(KeyStore keystore, KeyStore truststore, String password, HostnameVerifier hostnameVerifier, Class<T> resultClass) { Client client = ClientBuilder.newBuilder().trustStore(truststore).keyStore(keystore, password.toCharArray()). hostnameVerifier(hostnameVerifier).build(); return new ClientWrapper(client, resultClass); }
protected Client createApiClient() { ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig); if (ignoreCertificateErrors) { clientBuilder.sslContext(openSslContext).hostnameVerifier(openHostnameVerifier); } apiClient = clientBuilder.build(); return (apiClient); }
protected Client createApiClient() { ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig); if (ignoreCertificateErrors) { clientBuilder.sslContext(openSslContext).hostnameVerifier(openHostnameVerifier); } apiClient = clientBuilder.build(); return (apiClient); }
JaxRSInvoker(Destination destination) { super(destination); client = isSSL(destination.getLocation()) ? clientBuilder.hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }).sslContext(getSSLContext(destination)).build() : clientBuilder.build(); }
public ResourceInvocationHandler( String baseUrl, Configuration configuration ) { this( baseUrl, ClientBuilder.newBuilder().withConfig( configuration ) .sslContext( ClientHelper.createSSLContext() ) .hostnameVerifier( ClientHelper.createHostNameVerifier() ) .build() ); }
/** * Google should always have a valid SSL. Test this. */ @Test public void testHttpsConnectionToGoogle() throws Exception { final Client client = ClientBuilder .newBuilder() .hostnameVerifier( DisableSslCertificateCheckUtil.NULL_HOSTNAME_VERIFIER) .sslContext( DisableSslCertificateCheckUtil .buildUnsecureSslContext()).build(); client.target( "https://accounts.google.com/.well-known/openid-configuration") .request().get(); }
public InstanceProviderClient(String url, SSLContext sslContext, HostnameVerifier hostnameVerifier, int connectTimeout, int readTimeout) { final ClientConfig config = new ClientConfig() .property(ClientProperties.CONNECT_TIMEOUT, connectTimeout) .property(ClientProperties.READ_TIMEOUT, readTimeout) .connectorProvider(new ApacheConnectorProvider()); ClientBuilder builder = ClientBuilder.newBuilder(); if (sslContext != null) { builder = builder.sslContext(sslContext); } client = builder.hostnameVerifier(hostnameVerifier) .withConfig(config) .build(); base = client.target(url); }
/** * Creates a HTTPS Jersey REST {@link Client} configured to not authenticate * to the server. * <p/> * The created {@link Client} is configured to trust all server certificates * and approve all host names. (This is similar to using the * <code>--insecure</code> flag in <code>curl</code>.) * * @return The created {@link Client}. */ public static Client httpsNoAuth() { return ClientBuilder.newBuilder().sslContext(SslUtils.trustAllCertsSslContext()) .hostnameVerifier(SslUtils.allowAllHostNames()).register(GsonMessageBodyReader.class) .register(GsonMessageBodyWriter.class).build(); }
@Test public void testGetBookSslContext() throws Exception { ClientBuilder builder = ClientBuilder.newBuilder(); SSLContext sslContext = createSSLContext(); builder.sslContext(sslContext); builder.hostnameVerifier(new AllowAllHostnameVerifier()); Client client = builder.build(); WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123"); Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class); assertEquals(123, b.getId()); }
private HttpClient(HttpContext context) { ClientBuilder builder = ClientBuilder.newBuilder() .property(SET_METHOD_WORKAROUND, true) .property(SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) .register(MultiPartFeature.class) .register(logAny()) .sslContext(context.isHttpSslVerify() ? getDefaultContext() : emptyContext()); if (!context.isHttpSslVerify()) { builder.hostnameVerifier(trustAll()); } this.client = builder.build(); this.context = context; }
private HttpClient(HttpContext context) { ClientBuilder builder = ClientBuilder.newBuilder() .property(SET_METHOD_WORKAROUND, true) .property(SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) .register(MultiPartFeature.class) .register(logAny()) .sslContext(context.isHttpSslVerify() ? getDefaultContext() : emptyContext()); if (!context.isHttpSslVerify()) { builder.hostnameVerifier(trustAll()); } this.client = builder.build(); this.context = context; }
@Override protected Client createJerseyClient() throws Exception { SslConfigurator sslConfig = SslConfigurator.newInstance() .trustStoreFile(getResourcePath("bookie.truststore.jks")); SSLContext sslContext = sslConfig.createSSLContext(); return ClientBuilder.newBuilder().sslContext(sslContext) .hostnameVerifier((s1, s2) -> true) .build(); }