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:cn.wanghaomiao.seimi.http.hc.HttpClientCMPBox.java
public HttpClientCMPBox() { SSLContextBuilder builder = new SSLContextBuilder(); try {//from ww w. jav a2 s . co m builder.loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { @Override public void verify(String host, SSLSocket ssl) throws IOException { } @Override public void verify(String host, X509Certificate cert) throws SSLException { } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build(); poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registry); poolingHttpClientConnectionManager.setMaxTotal(500); poolingHttpClientConnectionManager.setDefaultMaxPerRoute(1000); } catch (Exception e) { Logger logger = LoggerFactory.getLogger(getClass()); logger.error("init fail,err={}", e.getMessage(), 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; }
From source file:com.ibm.connectors.splunklog.SplunkHttpConnection.java
public void createHttpClient() { PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory(); SSLContext sslContext = SSLContexts.createSystemDefault(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create().register("http", sf) .register("https", sslsf).build(); this.cm = new PoolingHttpClientConnectionManager(r); }
From source file:io.pivotal.xd.chaoslemur.infrastructure.StandardDirectorUtils.java
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host, 25555), new UsernamePasswordCredentials(username, password)); SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS() .build();/* w w w.ja va2s. co m*/ SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling() .setDefaultCredentialsProvider(credentialsProvider).setSSLSocketFactory(connectionFactory).build(); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient)); restTemplate.getInterceptors().addAll(interceptors); return restTemplate; }
From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java
@Bean @Qualifier("hgmRestTemplate") public RestTemplate getHgmHttpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS() .build();/*from w w w .j a v a 2 s. c o m*/ SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword())); HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory) .setDefaultCredentialsProvider(credentialsProvider).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); return new RestTemplate(requestFactory); }
From source file:ch.sourcepond.maven.plugin.jenkins.it.utils.HttpsServerStartupBarrier.java
@Override protected CloseableHttpClient createClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, URISyntaxException { final URL url = getClass().getResource(KEYSTORE_NAME); // Trust own CA and all self-signed certs final SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new File(url.toURI()), TEST_PASSWORD.toCharArray(), new TrustSelfSignedStrategy()).build(); // Allow TLSv1 protocol only final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); final CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); return httpclient; }
From source file:com.naver.timetable.bo.HttpClientBO.java
public String getHttpBody(String url, String method, List<NameValuePair> param) { HttpClient httpClient = null;/*from w ww . j av a 2s .c o m*/ HttpResponse httpResponse = null; HttpRequestBase httpRequest; try { if (StringUtils.upperCase(method).equals("POST")) { httpRequest = new HttpPost(url); ((HttpPost) httpRequest).setEntity(new UrlEncodedFormEntity(param)); } else { httpRequest = new HttpGet(url); } TrustManager[] trustManagers = new TrustManager[1]; trustManagers[0] = new DefaultTrustManager(); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(new KeyManager[0], trustManagers, new SecureRandom()); SSLContext.setDefault(sslContext); sslContext.init(null, trustManagers, null); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); // httpClient = HttpClientBuilder.create().build(); httpResponse = httpClient.execute(httpRequest); return EntityUtils.toString(httpResponse.getEntity()); } catch (ClientProtocolException e) { LOG.error("Client protocol error : ", e); } catch (IOException e) { LOG.error("IO error : ", e); } catch (KeyManagementException e) { LOG.error("IO error : ", e); } catch (NoSuchAlgorithmException e) { LOG.error("IO error : ", e); } finally { // ? HttpClientUtils.closeQuietly(httpResponse); HttpClientUtils.closeQuietly(httpClient); } return null; }
From source file:com.adobe.ags.curly.ConnectionManager.java
private void createNewConnectionManager() { try {/* w ww .j av a2s .c om*/ SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build(); connectionManager = new PoolingHttpClientConnectionManager(r); connectionManager.setValidateAfterInactivity(500); sharedContext = ThreadLocal.withInitial(HttpClientContext::new); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.threatconnect.app.playbooks.db.tcapi.ConnectionUtil.java
/** * Adds the ability to trust self signed certificates for this HttpClientBuilder * /*from w ww. j av a 2 s .co m*/ * @param httpClientBuilder * the HttpClientBuilder to apply these settings to */ public static void trustSelfSignedCerts(final HttpClientBuilder httpClientBuilder) { logger.debug("Trusting self-signed certs."); try { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { // allow all return true; } }); httpClientBuilder.setSSLSocketFactory(sslsf); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { logger.error("Error adding SSLSocketFactory to HttpClientBuilder", ex); } }
From source file:nl.eveoh.mytimetable.apiclient.service.MyTimetableHttpClientBuilderImpl.java
private SSLConnectionSocketFactory createSslSocketFactory(Configuration configuration) { X509HostnameVerifier verifier; if (configuration.isApiSslCnCheck()) { verifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; } else {/* www . ja va2s . c o m*/ verifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; } return new SSLConnectionSocketFactory(SSLContexts.createSystemDefault(), verifier); }