List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier NoopHostnameVerifier
NoopHostnameVerifier
From source file:com.rootcloud.ejb.RootCloudBean.java
private CloseableHttpClient createHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()).build(); HostnameVerifier allowAllHosts = new NoopHostnameVerifier(); SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, allowAllHosts); return HttpClients.custom().setSSLSocketFactory(connectionFactory).build(); }
From source file:io.openvidu.test.e2e.utils.CustomHttpClient.java
public CustomHttpClient(String openviduUrl, String openviduSecret) { this.openviduUrl = openviduUrl.replaceFirst("/*$", ""); this.headerAuth = "Basic " + Base64.getEncoder().encodeToString(("OPENVIDUAPP:" + openviduSecret).getBytes()); SSLContext sslContext = null; try {//from w w w. j a v a 2 s. co m sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { Assert.fail("Error building custom HttpClient: " + e.getMessage()); } HttpClient unsafeHttpClient = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); Unirest.setHttpClient(unsafeHttpClient); }
From source file:tech.beshu.ror.httpclient.ApacheHttpCoreClient.java
private CloseableHttpAsyncClient getNonValidatedHttpClient() { try {/* w ww . j ava2 s . c o m*/ return HttpAsyncClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSSLContext(SSLContexts.custom() .loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true).build()) .build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { logger.error("cannot create non-validating Apache HTTP Core client.. ", e); return HttpAsyncClients.createDefault(); } }
From source file:org.jboss.as.test.http.util.TestHttpClientUtils.java
/** *@param credentialsProvider optional cred provider * @return client that doesn't verify https connections *//*from w w w. j a va 2 s. c o m*/ public static CloseableHttpClient getHttpsClient(CredentialsProvider credentialsProvider) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); ctx.init(null, new TrustManager[] { tm }, null); SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(ctx, new NoopHostnameVerifier()); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", sslConnectionFactory).build(); HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry); HttpClientBuilder builder = HttpClientBuilder.create().setSSLSocketFactory(sslConnectionFactory) .setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm); if (credentialsProvider != null) { builder.setDefaultCredentialsProvider(credentialsProvider); } return builder.build(); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.jasig.cas.util.http.SimpleHttpClientTests.java
private SSLConnectionSocketFactory getFriendlyToAllSSLSocketFactory() throws Exception { final TrustManager trm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; }// ww w . jav a 2 s . co m public void checkClientTrusted(final X509Certificate[] certs, final String authType) { } public void checkServerTrusted(final X509Certificate[] certs, final String authType) { } }; final SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, new TrustManager[] { trm }, null); return new SSLConnectionSocketFactory(sc, new NoopHostnameVerifier()); }
From source file:com.github.restdriver.clientdriver.integration.SecureClientDriverTest.java
@Test(expected = SSLHandshakeException.class) public void testConnectionFailsWithoutTrustMaterial() throws Exception { // Arrange//from www. j a v a2 s .c om KeyStore keyStore = getKeystore(); SecureClientDriver driver = new SecureClientDriver( new DefaultClientDriverJettyHandler(new DefaultRequestMatcher()), keyStore, "password", "certificate"); driver.addExpectation(onRequestTo("/test"), giveEmptyResponse()); // set the test certificate as trusted HttpClient client = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); HttpGet getter = new HttpGet(driver.getBaseUrl() + "/test"); // Act client.execute(getter); }
From source file:org.ow2.proactive.scheduling.api.graphql.service.AuthenticationService.java
@PostConstruct protected void init() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { schedulerLoginFetchUrl = createLoginFetchUrl(schedulerRestUrl); sessionCache = CacheBuilder.newBuilder().maximumSize(Integer.parseInt(sessionCacheMaxSize)) .expireAfterWrite(Integer.parseInt(sessionCacheExpireAfter), TimeUnit.MILLISECONDS) .build(new CacheLoader<String, String>() { @Override//from w w w . j av a2s. c om public String load(String sessionId) throws Exception { return getLoginFromSessionId(sessionId); } }); if (schedulerLoginFetchUrl.startsWith("https")) { CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build()).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(httpClient); restTemplate.setRequestFactory(requestFactory); } }
From source file:org.apache.juneau.rest.test.TestMicroservice.java
static SSLConnectionSocketFactory getSSLSocketFactory() throws Exception { SSLContext sslContext = SSLContext.getInstance("SSL"); TrustManager tm = new SimpleX509TrustManager(true); sslContext.init(null, new TrustManager[] { tm }, new SecureRandom()); return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); }
From source file:com.github.restdriver.clientdriver.integration.SecureClientDriverRuleTest.java
private HttpClient getClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { try {//from www. ja va 2 s . co m // set the test certificate as trusted SSLContext context = SSLContexts.custom() .loadTrustMaterial(getKeystore(), TrustSelfSignedStrategy.INSTANCE).build(); return HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).setSSLContext(context) .build(); } catch (Exception e) { throw new ClientDriverSetupException("Client could not be created.", e); } }
From source file:com.falcon.orca.actors.Generator.java
public Generator(final ActorRef collector, final String url, final HttpMethods method, final byte[] data, final List<Header> headers, final List<Cookie> cookies, final boolean isBodyDynamic, final boolean isUrlDynamic, final DynDataStore dataStore) throws URISyntaxException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { this.collector = collector; this.dataStore = dataStore; this.isBodyDynamic = isBodyDynamic; this.method = method; this.url = url; this.headers = headers; this.staticRequestData = data != null ? Arrays.copyOf(data, data.length) : new byte[0]; this.isUrlDynamic = isUrlDynamic; CookieStore cookieStore = new BasicCookieStore(); if (cookies != null) { cookies.forEach(cookieStore::addCookie); }/* www .j a v a 2 s .c o m*/ TrustStrategy trustStrategy = (x509Certificates, s) -> true; SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(null, trustStrategy).build(); this.client = HttpClientBuilder.create().setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); }