List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory SSLConnectionSocketFactory
public SSLConnectionSocketFactory(final javax.net.ssl.SSLSocketFactory socketfactory, final X509HostnameVerifier hostnameVerifier)
From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpClientProvider.java
private static SSLConnectionSocketFactory buildSslSocketFactory() { return new SSLConnectionSocketFactory(buildSslContext(), NoopHostnameVerifier.INSTANCE); }
From source file:org.jenkinsci.plugins.kubernetesworkflowsteps.KubeStepExecution.java
private static CloseableHttpClient getClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (client == null) { synchronized (client_lock) { if (client == null) { SSLContextBuilder builder = SSLContexts.custom(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Collection<BasicHeader> headers = new ArrayList<BasicHeader>(); headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); headers.add(new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + env.get("BEARER_TOKEN"))); client = HttpClients.custom().setDefaultHeaders(headers).setSSLSocketFactory(sslsf).build(); }//from w ww. jav a 2 s. c o m } } return client; }
From source file:io.apicurio.hub.api.security.KeycloakLinkedAccountsProvider.java
@PostConstruct protected void postConstruct() { try {//from w ww . j a v a2 s .c o m if (config.isDisableKeycloakTrustManager()) { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()) .build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); } else { httpClient = HttpClients.createSystem(); } } catch (Exception e) { throw new RuntimeException(e); } }
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 ww . j a va 2 s . co 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.olat.core.commons.services.webdav.WebDAVConnection.java
public WebDAVConnection(String protocol, String host, int port) { this.protocol = protocol; this.host = host; this.port = port; SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(SSLContexts.createDefault(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpclient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore) .setDefaultCredentialsProvider(provider).setSSLSocketFactory(sslFactory).build(); }
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; }// w ww . j a v a 2 s. c o 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:sabina.integration.TestScenario.java
TestScenario(String backend, int port, boolean secure, boolean externalFiles) { this.port = port; this.backend = backend; this.secure = secure; this.externalFiles = externalFiles; SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(), ALLOW_ALL_HOSTNAME_VERIFIER); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", sslConnectionSocketFactory).build(); HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketFactoryRegistry, new ManagedHttpClientConnectionFactory()); RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.NETSCAPE).build(); cookieStore = new BasicCookieStore(); HttpClientContext context = HttpClientContext.create(); context.setCookieStore(cookieStore); this.httpClient = HttpClients.custom().setSchemePortResolver(h -> { Args.notNull(h, "HTTP host"); final int port1 = h.getPort(); if (port1 > 0) { return port1; }// w w w. j a v a 2s . c o m final String name = h.getSchemeName(); if (name.equalsIgnoreCase("http")) { return port1; } else if (name.equalsIgnoreCase("https")) { return port1; } else { throw new UnsupportedSchemeException("unsupported protocol: " + name); } }).setConnectionManager(connManager).setDefaultRequestConfig(globalConfig).build(); }
From source file:com.questdb.test.tools.HttpTestUtils.java
private static HttpClientBuilder createHttpClient_AcceptsUntrustedCerts() throws Exception { HttpClientBuilder b = HttpClientBuilder.create(); // setup a Trust Strategy that allows all certificates. ///* w ww. j ava 2 s. com*/ SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build(); b.setSSLContext(sslContext); // 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, new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); 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 b.setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)); return b; }
From source file:de.undercouch.gradle.tasks.download.internal.DefaultHttpClientFactory.java
private SSLConnectionSocketFactory getInsecureSSLSocketFactory() { if (insecureSSLSocketFactory == null) { SSLContext sc;//from w ww . jav a 2s. co m try { sc = SSLContext.getInstance("SSL"); sc.init(null, INSECURE_TRUST_MANAGERS, new SecureRandom()); insecureSSLSocketFactory = new SSLConnectionSocketFactory(sc, INSECURE_HOSTNAME_VERIFIER); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (KeyManagementException e) { throw new RuntimeException(e); } } return insecureSSLSocketFactory; }
From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.StandardDirectorUtils.java
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException { String directorUaaBearerToken = getBoshDirectorUaaToken(host, username, password); SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS() .build();//from www . j a va 2 s . c o m SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); Header auth = new BasicHeader("Authorization", String.format("Bearer %s", directorUaaBearerToken)); Header accept = new BasicHeader("Accept", "*/*"); List<Header> headers = new ArrayList<Header>(); headers.add(auth); headers.add(accept); HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().setDefaultHeaders(headers) .setSSLSocketFactory(connectionFactory).build(); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient)); restTemplate.getInterceptors().addAll(interceptors); return restTemplate; }