List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier NoopHostnameVerifier
NoopHostnameVerifier
From source file:org.springframework.cloud.config.server.support.HttpClientSupport.java
public static HttpClientBuilder builder(HttpEnvironmentRepositoryProperties environmentProperties) throws GeneralSecurityException { SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); HttpClientBuilder httpClientBuilder = HttpClients.custom(); if (environmentProperties.isSkipSslValidation()) { sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -> true); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); }/* ww w . j av a2 s. com*/ if (!CollectionUtils.isEmpty(environmentProperties.getProxy())) { ProxyHostProperties httpsProxy = environmentProperties.getProxy() .get(ProxyHostProperties.ProxyForScheme.HTTPS); ProxyHostProperties httpProxy = environmentProperties.getProxy() .get(ProxyHostProperties.ProxyForScheme.HTTP); httpClientBuilder.setRoutePlanner(new SchemeBasedRoutePlanner(httpsProxy, httpProxy)); httpClientBuilder .setDefaultCredentialsProvider(new ProxyHostCredentialsProvider(httpProxy, httpsProxy)); } else { httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())); httpClientBuilder.setDefaultCredentialsProvider(new SystemDefaultCredentialsProvider()); } int timeout = environmentProperties.getTimeout() * 1000; return httpClientBuilder.setSSLContext(sslContextBuilder.build()).setDefaultRequestConfig( RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build()); }
From source file:com.vmware.loginsightapi.util.NonValidatingSSLSocketFactory.java
/** * Default constructor//w w w . j av a2 s .c om */ public NonValidatingSSLSocketFactory() { // super(getSSLContext(), // SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); super(getSSLContext(), new NoopHostnameVerifier()); }
From source file:net.acesinc.data.json.generator.log.HttpPostLogger.java
public HttpPostLogger(Map<String, Object> props) throws NoSuchAlgorithmException { this.url = (String) props.get(URL_PROP_NAME); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(SSLContext.getDefault(), new NoopHostnameVerifier()); this.httpClient = HttpClientBuilder.create().setSSLSocketFactory(sf).build(); }
From source file:br.com.jbugbrasil.bot.telegram.api.httpclient.BotCloseableHttpClient.java
@Override public CloseableHttpClient get() { return HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setConnectionTimeToLive(70, TimeUnit.SECONDS).setMaxConnTotal(100).build(); }
From source file:com.vmware.loginsightapi.util.AsyncLogInsightConnectionStrategy.java
/** * Initializes and returns the httpClient with NoopHostnameVerifier * /*from www. j a va 2s .co m*/ * @return CloseableHttpAsyncClient */ @Override public CloseableHttpAsyncClient getHttpClient() { // Trust own CA and all self-signed certs SSLContext sslcontext = NonValidatingSSLSocketFactory.getSSLContext(); // Allow TLSv1 protocol only SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null, new NoopHostnameVerifier()); List<Header> headers = LogInsightClient.getDefaultHeaders(); asyncHttpClient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).setDefaultHeaders(headers) .build(); asyncHttpClient.start(); return asyncHttpClient; }
From source file:org.springframework.cloud.deployer.admin.shell.command.support.HttpClientUtils.java
/** * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}. * * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed * certificates./*from www . j a va 2s . co m*/ * * @param restTemplate Must not be null * @param username Can be null * @param password Can be null * @param skipSslValidation Use with caution! If true certificate warnings will be ignored. */ public static void prepareRestTemplate(RestTemplate restTemplate, String username, String password, boolean skipSslValidation) { Assert.notNull(restTemplate, "The provided RestTemplate must not be null."); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (StringUtils.hasText(username) && StringUtils.hasText(password)) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } if (skipSslValidation) { httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } final CloseableHttpClient httpClient = httpClientBuilder.build(); final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); restTemplate.setRequestFactory(requestFactory); }
From source file:org.jasig.cas.util.http.SimpleHttpClientTests.java
@Test public void verifyBypassedInvalidHttpsUrl() throws Exception { final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean(); clientFactory.setSslSocketFactory(getFriendlyToAllSSLSocketFactory()); clientFactory.setHostnameVerifier(new NoopHostnameVerifier()); clientFactory.setAcceptableCodes(new int[] { 200, 403 }); final SimpleHttpClient client = clientFactory.getObject(); assertTrue(client.isValidEndPoint("https://static.ak.connect.facebook.com")); }
From source file:com.github.restdriver.clientdriver.integration.SecureClientDriverTest.java
@Test public void testConnectionSucceedsWithGivenTrustMaterial() throws Exception { // Arrange/*from w w w . jav a 2 s . c o m*/ KeyStore keyStore = getKeystore(); SecureClientDriver driver = new SecureClientDriver( new DefaultClientDriverJettyHandler(new DefaultRequestMatcher()), 1111, keyStore, "password", "certificate"); driver.addExpectation(onRequestTo("/test"), giveEmptyResponse()); // set the test certificate as trusted SSLContext context = SSLContexts.custom().loadTrustMaterial(keyStore, TrustSelfSignedStrategy.INSTANCE) .build(); HttpClient client = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSSLContext(context).build(); HttpGet getter = new HttpGet(driver.getBaseUrl() + "/test"); // Act HttpResponse response = client.execute(getter); // Assert assertEquals(204, response.getStatusLine().getStatusCode()); driver.verify(); }
From source file:org.springframework.cloud.dataflow.shell.command.support.HttpClientUtils.java
/** * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}. * * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed * certificates.// ww w . jav a2 s .com * * @param restTemplate Must not be null * @param username Can be null * @param password Can be null * @param skipSslValidation Use with caution! If true certificate warnings will be ignored. */ public static void prepareRestTemplate(RestTemplate restTemplate, URI host, String username, String password, boolean skipSslValidation) { Assert.notNull(restTemplate, "The provided RestTemplate must not be null."); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (StringUtils.hasText(username) && StringUtils.hasText(password)) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } if (skipSslValidation) { httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } final CloseableHttpClient httpClient = httpClientBuilder.build(); final HttpHost targetHost = new HttpHost(host.getHost(), host.getPort(), host.getScheme()); final HttpComponentsClientHttpRequestFactory requestFactory = new PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory( httpClient, targetHost); restTemplate.setRequestFactory(requestFactory); }
From source file:jatoo.weather.openweathermap.JaTooWeatherOpenWeatherMap.java
@Override protected final String getJSONResponse(final String city) throws IOException { CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()) .build();/*from w w w . j a va2 s .co m*/ HttpGet request = new HttpGet(URL_CURRENT_WEATHER + "?appid=" + appid + "&id=" + city + "&units=metric"); CloseableHttpResponse response = client.execute(request); BufferedHttpEntity entity = new BufferedHttpEntity(response.getEntity()); return EntityUtils.toString(entity, "UTF-8"); }