Refine search
SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( builder.build()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory( sslsf).build(); HttpGet httpGet = new HttpGet("https://some-server"); CloseableHttpResponse response = httpclient.execute(httpGet); try { System.out.println(response.getStatusLine()); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } finally { response.close(); }
try { sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); } catch (NoSuchAlgorithmException e) { log.error("Could not initialize the HttpClient for SSL connections"); .build(); return HttpClientBuilder.create() .setDefaultRequestConfig(config) .setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)) .setSSLSocketFactory(sslConnectionSocketFactory) .build();
/** * Create a {@link CloseableHttpClient} used to communicate with Azkaban server. * Derived class can configure different http client by overriding this method. * * @return A closeable http client. */ private CloseableHttpClient createHttpClient() throws AzkabanClientException { try { // SSLSocketFactory using custom TrustStrategy that ignores warnings about untrusted certificates // Self sign SSL SSLContextBuilder sslcb = new SSLContextBuilder(); sslcb.loadTrustMaterial(null, (TrustStrategy) new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcb.build()); HttpClientBuilder builder = HttpClientBuilder.create(); RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT) .setSocketTimeout(10000) .setConnectTimeout(10000) .setConnectionRequestTimeout(10000) .build(); builder.disableCookieManagement() .useSystemProperties() .setDefaultRequestConfig(requestConfig) .setConnectionManager(new BasicHttpClientConnectionManager()) .setSSLSocketFactory(sslsf); return builder.build(); } catch (Exception e) { throw new AzkabanClientException("HttpClient cannot be created", e); } }
SSLContextBuilder builder = new SSLContextBuilder(); try { builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)) .setSSLSocketFactory(socketFactory) .build();
new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()) ); builder.setDefaultCredentialsProvider(credsProvider); SSLContextBuilder sslBuilder = new SSLContextBuilder(); try { sslBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslBuilder.build()); builder.setSSLSocketFactory(sslsf); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { LOG.error("Failed to init socket factory {}", ex.getMessage(), ex); cm.setDefaultMaxPerRoute(configuration.getConnectionPoolSize()); cm.setMaxTotal(configuration.getConnectionPoolSize()); builder.setConnectionManager(cm); this.client = builder.build();
HttpClientBuilder cb = HttpClientBuilder.create(); SSLContextBuilder sslcb = new SSLContextBuilder(); sslcb.loadTrustMaterial(KeyStore.getInstance(KeyStore.getDefaultType()), new TrustSelfSignedStrategy()); cb.setSslcontext(sslcb.build()); CloseableHttpClient httpclient = cb.build();
final HttpClientBuilder builder = HttpClientBuilder.create(); sslbuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslbuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); builder.setSSLSocketFactory(sslsf); } catch (final Exception e) { LOG.log(Level.WARNING, "Couldn't init SSL strategy", e); builder.setConnectionManager(connection);
/** * Constructor that trusts ALL SSl certificates (NOTE : ONLY FOR DEV TESTING) if Mode == 1 or * Default if Mode == 0 */ public ConnectionBuilder(int mode) throws SSLException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (mode == 1) { SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); httpClient = HttpClients.custom().setSSLSocketFactory(factory).build(); } else { httpClient = HttpClients.createDefault(); } }
HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties(); builder.setProxy(proxyHost); ssbldr.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(ssbldr.build(),SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
private CloseableHttpClient createHttpClient() throws DaemonException { HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.disableRedirectHandling(); httpClientBuilder.setRetryHandler(restHttpRequestRetryHandler); if (useSSL) { try { builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new DaemonException(e); } httpClientBuilder.setSSLSocketFactory(sslsf); } httpClientBuilder.setConnectionTimeToLive(socketTimeout, TimeUnit.SECONDS); httpClientBuilder.setMaxConnTotal(connTotal).setMaxConnPerRoute(connTotal); httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom() .setSocketTimeout(socketTimeout * 1000) .setConnectTimeout(connectTimeout * 1000).build()); Proxy proxy = InitConfiguration.getProxy(); if (proxy != null && !InitConfiguration.getProxy().type().equals(Type.DIRECT)) { InetSocketAddress addressSocket = InetSocketAddress.class.cast(proxy.address()); httpClientBuilder.setProxy(new HttpHost(addressSocket.getHostName(), addressSocket.getPort())); } return httpClientBuilder.build(); }
SSLContextBuilder builder = new SSLContextBuilder(); try { builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); } catch (KeyStoreException e) { e.printStackTrace(); SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); cm.setMaxTotal(numConnections > 20 ? numConnections : 20); client = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(config).build();
SSLContextBuilder sslContextBuilder = SSLContextBuilder.create(); sslContextBuilder.useProtocol("TLSv1.2"); sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); httpClientBuilder.setSSLSocketFactory(new TlsCertificateAuthorityClientSocketFactory(sslContextBuilder.build(), caHostname, certificates)); try (CloseableHttpClient client = httpClientBuilder.build()) { JcaPKCS10CertificationRequest request = TlsHelper.generateCertificationRequest(dn, domainAlternativeNames, keyPair, signingAlgorithm); TlsCertificateAuthorityRequest tlsCertificateAuthorityRequest = new TlsCertificateAuthorityRequest(TlsHelper.calculateHMac(token, request.getPublicKey()),
try { final URL url = ServiceUtils.class.getClassLoader().getResource("servicebroker.truststore"); sslContext = SSLContexts.custom().loadTrustMaterial(url, "changeme".toCharArray(), new TrustSelfSignedStrategy()).build(); } catch (final Exception e) { LOG.error("Unable to configure SSL context!", e); final HttpClient client = HttpClientBuilder.create().setSSLContext(sslContext).build(); request.addHeader(HttpHeaders.ACCEPT, getAcceptedMimeTypes());
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(); 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; }
HttpClientBuilder builder = HttpClientBuilder.create(); KeyStore keyStore = initSSL(); SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(keyStore, new TrustSelfSignedStrategy()).useTLS().build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslConnectionFactory) .build(); PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(registry); ccm.setMaxTotal(100); ccm.setDefaultMaxPerRoute(5); builder.setConnectionManager(ccm); BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort(), name), new UsernamePasswordCredentials(username, password)); builder.setDefaultCredentialsProvider(credsProvider); RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder.setSocketTimeout(60000); builder.setDefaultRequestConfig(requestBuilder.build()); return new HttpContextRequestScopedApacheClientExecutor(builder.build());
public CmmnHttpActivityBehaviorImpl() { org.flowable.cmmn.engine.HttpClientConfig config = CommandContextUtil.getCmmnEngineConfiguration().getHttpClientConfig(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // https settings if (config.isDisableCertVerify()) { try { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); httpClientBuilder.setSSLSocketFactory( new SSLConnectionSocketFactory(builder.build(), new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } })); } catch (Exception e) { LOGGER.error("Could not configure HTTP client SSL self signed strategy", e); } } // request retry settings int retryCount = 0; if (config.getRequestRetryLimit() > 0) { retryCount = config.getRequestRetryLimit(); } httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(retryCount, false)); this.httpActivityExecutor = new HttpActivityExecutor(httpClientBuilder, new NopErrorPropagator(), CommandContextUtil.getCmmnEngineConfiguration().getObjectMapper()); }
private CloseableHttpClient getHttpClient() throws GeneralSecurityException, IOException { SSLContext context = null; if (!useKeystore && useTruststore) { LOG.info("SSL: Using only TrustStore for SSL connection"); context = SSLContexts.custom() .loadTrustMaterial(loadTrustStore(), new TrustSelfSignedStrategy()) .build(); return HttpClients.custom().setSSLContext(context).build(); } else if (useKeystore && useTruststore) { LOG.info("SSL: Using Keystore and TrustStore for SSL connection"); context = SSLContexts.custom() .loadKeyMaterial(loadKeyStore(), this.keystorepassword.toCharArray(), (aliases, socket) -> keystorealias) .loadTrustMaterial(loadTrustStore(), new TrustSelfSignedStrategy()) .build(); return HttpClients.custom().setSSLContext(context).build(); } else { return HttpClients.createDefault(); } }
protected void skipSslValidation() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); CloseableHttpClient httpClient = HttpClients.custom().setSslcontext(sslContext).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); this.setRequestFactory(requestFactory); }
public RestClient(String baseUrl) throws Exception { if (baseUrl == null) { this.baseUrl = "https://r2.localhost"; } else { this.baseUrl = baseUrl; } SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); this.httpclient = HttpClients.custom().setUserAgent("r2cloud/0.1 info@r2cloud.ru").setSSLSocketFactory(sslsf).build(); }
@Override public CloseableHttpClient getClient() { CloseableHttpClient httpClient = null; SSLConnectionSocketFactory sslsf = null; try { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); sslsf = new SSLConnectionSocketFactory( builder.build()); httpClient = HttpClients.custom() .setRedirectStrategy(new LaxRedirectStrategy()) .setSSLSocketFactory(sslsf) .build(); } catch (GeneralSecurityException e) { LOGGER.error("Error creating jks from certificates: ", e); throw new RuntimeException(e); } return httpClient; } }