List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE
NoopHostnameVerifier INSTANCE
To view the source code for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE.
Click Source Link
From source file:org.springframework.cloud.contract.wiremock.WireMockSpring.java
public static WireMockConfiguration options() { if (!initialized) { if (ClassUtils.isPresent("org.apache.http.conn.ssl.NoopHostnameVerifier", null)) { HttpsURLConnection.setDefaultHostnameVerifier(NoopHostnameVerifier.INSTANCE); try { HttpsURLConnection.setDefaultSSLSocketFactory(SSLContexts.custom() .loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE).build().getSocketFactory()); } catch (Exception e) { Assert.fail("Cannot install custom socket factory: [" + e.getMessage() + "]"); }/* w w w . j av a 2 s . c o m*/ } initialized = true; } WireMockConfiguration config = new WireMockConfiguration(); config.httpServerFactory(new SpringBootHttpServerFactory()); return config; }
From source file:se.curity.examples.http.UnsafeHttpClientSupplier.java
private static HttpClient create() { try {/*from w ww .jav a 2 s . c o m*/ SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); return HttpClients.custom().disableAuthCaching().disableAutomaticRetries().disableRedirectHandling() .setSSLSocketFactory(sslSocketFactory).build(); } catch (Exception e) { _logger.error("Unable to create Unsafe HTTP client supplier", e); throw new RuntimeException("Unable to initialize httpClient", e); } }
From source file:guru.nidi.loader.url.UrlLoader.java
public UrlLoader(String base, UrlFetcher fetcher, CloseableHttpClient httpClient) { this.base = base; this.fetcher = fetcher; this.client = httpClient == null ? HttpClientBuilder.create().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build() : httpClient;/*from ww w. j av a2s .c om*/ }
From source file:com.vmware.identity.rest.idm.client.test.integration.util.TestClientFactory.java
/** * Create an IdmClient with the given parameters. * * @param host address of the remote server * @param tenant name of the tenant/* ww w. j av a2 s. c om*/ * @param username username in UPN format * @param password password * @return IdmClient * @throws IOException * @throws ClientException * @throws ClientProtocolException * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static IdmClient createClient(String host, String tenant, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, ClientException, IOException { HostRetriever hostRetriever = new SimpleHostRetriever(host, true); IdmClient client = new IdmClient(hostRetriever, NoopHostnameVerifier.INSTANCE, new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build()); String token = TokenFactory.getAccessToken(host, tenant, username, password); client.setToken(new AccessToken(token, AccessToken.Type.JWT)); return client; }
From source file:com.vmware.directory.rest.client.test.integration.util.TestClientFactory.java
/** * Create an VmdirClient with the given parameters. * * @param host address of the remote server * @param tenant name of the tenant/* w w w .jav a2 s . co m*/ * @param username username in UPN format * @param password password * @return IdmClient * @throws IOException * @throws ClientException * @throws ClientProtocolException * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static VmdirClient createClient(String host, String tenant, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, ClientException, IOException { HostRetriever hostRetriever = new SimpleHostRetriever(host, true); VmdirClient client = new VmdirClient(hostRetriever, NoopHostnameVerifier.INSTANCE, new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build()); String token = TokenFactory.getAccessToken(host, tenant, username, password); client.setToken(new AccessToken(token, AccessToken.Type.JWT)); return client; }
From source file:org.geosamples.utilities.HTTPClient.java
/** * This method relaxes SSL constraints because geosamples does not yet * provide certificate.//from w ww . j a va 2 s .c o m * * @see <a href="http://literatejava.com/networks/ignore-ssl-certificate-errors-apache-httpclient-4-4/">Tom's Blog</a> * @return CloseableHttpClient * @throws java.security.NoSuchAlgorithmException * @throws java.security.KeyStoreException * @throws java.security.KeyManagementException */ public static CloseableHttpClient clientWithNoSecurityValidation() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); // setup a Trust Strategy that allows all certificates. SSLContext sslContext = null; sslContext = new SSLContextBuilder().loadTrustMaterial(null, (X509Certificate[] arg0, String arg1) -> true) .build(); clientBuilder.setSSLContext(sslContext); // don't check Hostnames, either. HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; // here's the special part: // -- need to create an SSL Socket Factory, to use our weakened "trust strategy"; // -- and create a Registry, to register it. // SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); // now, we create connection-manager using our Registry. // -- allows multi-threaded use PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); clientBuilder.setConnectionManager(connMgr); CloseableHttpClient httpClient = clientBuilder.build(); return httpClient; }
From source file:com.mirth.connect.connectors.ws.DefaultWebServiceConfiguration.java
@Override public void configureConnectorDeploy(Connector connector) throws Exception { if (connector instanceof WebServiceDispatcher) { sslContext = SSLContexts.createSystemDefault(); enabledProtocols = MirthSSLUtil// ww w . j a v a2 s . c o m .getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()); enabledCipherSuites = MirthSSLUtil .getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, enabledProtocols, enabledCipherSuites, NoopHostnameVerifier.INSTANCE); ((WebServiceDispatcher) connector).getSocketFactoryRegistry().register("https", sslConnectionSocketFactory); } }
From source file:com.consol.citrus.samples.todolist.config.SoapClientSslConfig.java
@Bean public HttpClient httpClient() { try {//from w ww.ja v a 2s . c o m SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(), new TrustSelfSignedStrategy()) .build(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, NoopHostnameVerifier.INSTANCE); return HttpClients.custom().setSSLSocketFactory(sslSocketFactory) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor()).build(); } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new BeanCreationException("Failed to create http client for ssl connection", e); } }
From source file:com.consol.citrus.samples.todolist.config.HttpClientSslConfig.java
@Bean public HttpClient httpClient() { try {/*from w ww .j a v a2 s .c om*/ SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(), new TrustSelfSignedStrategy()) .build(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, NoopHostnameVerifier.INSTANCE); return HttpClients.custom().setSSLSocketFactory(sslSocketFactory) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new BeanCreationException("Failed to create http client for ssl connection", e); } }
From source file:com.cloud.utils.rest.HttpClientHelper.java
private static Registry<ConnectionSocketFactory> createSocketFactoryConfigration() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { Registry<ConnectionSocketFactory> socketFactoryRegistry; final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustSelfSignedStrategy()).build(); final SSLConnectionSocketFactory cnnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register(HTTPS, cnnectionSocketFactory).build(); return socketFactoryRegistry; }