當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLContextBuilder.loadTrustMaterial方法代碼示例

本文整理匯總了Java中org.apache.http.ssl.SSLContextBuilder.loadTrustMaterial方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLContextBuilder.loadTrustMaterial方法的具體用法?Java SSLContextBuilder.loadTrustMaterial怎麽用?Java SSLContextBuilder.loadTrustMaterial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.ssl.SSLContextBuilder的用法示例。


在下文中一共展示了SSLContextBuilder.loadTrustMaterial方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public void init() {
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
		/* 配置同時支持 HTTP 和 HTPPS */
		Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
				.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
		/* 初始化連接管理器 */
		poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
		poolConnManager.setMaxTotal(maxTotal);
		poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
				.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
		httpClient = getConnection();
		log.info("HttpConnectionManager初始化完成...");
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:21,代碼來源:HttpConnectionManager.java

示例2: createAllTrustingClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private static HttpClient createAllTrustingClient() throws RestClientException {
	HttpClient httpclient = null;
	try {
		final SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial((TrustStrategy) (X509Certificate[] chain, String authType) -> true);
		final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
				builder.build());
		httpclient = HttpClients
				.custom()
				.setSSLSocketFactory(sslsf)
				.setMaxConnTotal(1000)
				.setMaxConnPerRoute(1000)
				.build();
	} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
		throw new RestClientException("Cannot create all SSL certificates trusting client", e);
	}
	return httpclient;
}
 
開發者ID:syndesisio,項目名稱:syndesis-qe,代碼行數:19,代碼來源:RestUtils.java

示例3: triggerHttpGetWithCustomSSL

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public static String triggerHttpGetWithCustomSSL(String requestUrl) {
	String result = null;
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
			public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
				return true;
			}
		});
		@SuppressWarnings("deprecation")
		HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), hostnameVerifier);

		CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

		HttpGet httpGet = new HttpGet("https://" + requestUrl);
		CloseableHttpResponse response = httpclient.execute(httpGet);
		try {
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				HttpEntity entity = response.getEntity();
				result = EntityUtils.toString(entity);
				log.debug("Received response: " + result);
			} else {
				log.error("Request not successful. StatusCode was " + response.getStatusLine().getStatusCode());
			}
		} finally {
			response.close();
		}
	} catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		log.error("Error executing the request.", e);
	}
	return result;
}
 
開發者ID:hotstepper13,項目名稱:alexa-gira-bridge,代碼行數:35,代碼來源:Util.java

示例4: init

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public void init()
{
  try
  {
    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    Unirest.setHttpClient(httpclient);
  }
  catch (Exception e)
  {
    System.out.println("Failed to start server: " + e.toString());
    e.printStackTrace();
  }
}
 
開發者ID:Malow,項目名稱:GladiatorManager,代碼行數:17,代碼來源:ServerConnection.java

示例5: buildHttpClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * This creates a HTTP client instance for connecting the IFTTT server.
 * 
 * @return the HTTP client instance
 */
private CloseableHttpClient buildHttpClient ()
{
    if ( configuration.isIftttIgnoreServerCertificate() ) {
        try {
            SSLContextBuilder builder = new SSLContextBuilder();
            builder.loadTrustMaterial(new TrustStrategy() {
                @Override
                public boolean isTrusted (X509Certificate[] chain_, String authType_) throws CertificateException
                {
                    return true;
                }
            });
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();
        }
        catch (Exception ex) {
            LOG.error(ex);
            // This should never happen, but we have to handle it
            throw new RuntimeException(ex);
        }
    }
    else {
        return HttpClients.createDefault();
    }
}
 
開發者ID:zazaz-de,項目名稱:iot-device-bosch-indego-controller,代碼行數:31,代碼來源:IftttIndegoAdapter.java

示例6: getHttpsClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private CloseableHttpClient getHttpsClient()
{
    try
    {
        RequestConfig config = RequestConfig.custom().setSocketTimeout( 5000 ).setConnectTimeout( 5000 ).build();

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial( null, ( TrustStrategy ) ( x509Certificates, s ) -> true );
        SSLConnectionSocketFactory sslSocketFactory =
                new SSLConnectionSocketFactory( sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE );

        return HttpClients.custom().setDefaultRequestConfig( config ).setSSLSocketFactory( sslSocketFactory )
                          .build();
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return HttpClients.createDefault();
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:22,代碼來源:RestServiceImpl.java

示例7: configureInsecureSSL

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * Allow SSL connections to utilize untrusted certificates
 * 
 * @param httpClientBuilder
 * @throws MojoExecutionException
 */
private void configureInsecureSSL(HttpClientBuilder httpClientBuilder) throws MojoExecutionException {
    try {
        SSLContextBuilder sslBuilder = new SSLContextBuilder();

        // Accept all Certificates
        sslBuilder.loadTrustMaterial(null, AcceptAllTrustStrategy.INSTANCE);

        SSLContext sslContext = sslBuilder.build();

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
                NoopHostnameVerifier.INSTANCE);
        httpClientBuilder.setSSLSocketFactory(sslsf);
    } catch (Exception e) {
        throw new MojoExecutionException("Error setting insecure SSL configuration", e);
    }
}
 
開發者ID:sabre1041,項目名稱:jenkinsfile-maven-plugin,代碼行數:23,代碼來源:ValidateJenkinsfileMojo.java

示例8: setTrustedKeystore

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public void setTrustedKeystore(final RestSettings.Keystore keystore) throws Exception {
    final SSLContextBuilder ssl = SSLContexts.custom();

    final String path = keystore.getPath();
    final String password = keystore.getPassword();

    final URL resource = HttpClientFactoryBean.class.getClassLoader().getResource(path);

    if (resource == null) {
        throw new FileNotFoundException(format("Keystore [%s] not found.", path));
    }

    try {
        ssl.loadTrustMaterial(resource, password == null ? null : password.toCharArray());
        builder.setSSLSocketFactory(new SSLConnectionSocketFactory(ssl.build(), getDefaultHostnameVerifier()));
    } catch (final Exception e) {
        LOG.error("Error loading keystore [{}]:", path, e); // log full exception, bean initialization code swallows it
        throw e;
    }
}
 
開發者ID:zalando-stups,項目名稱:put-it-to-rest,代碼行數:21,代碼來源:HttpClientFactoryBean.java

示例9: HttpPosterThread

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
HttpPosterThread(LinkedBlockingQueue<String> lbq, String url) throws Exception {
    this.lbq = lbq;
    this.url = url;

    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            builder.build());
    httpClient = HttpClients.custom().setSSLSocketFactory(
            sslsf).build();

    //httpClient = HttpClientBuilder.create().build();
    httpPost = new HttpPost(url);

    cntErr = 0;
}
 
開發者ID:david618,項目名稱:Simulator,代碼行數:17,代碼來源:HttpPosterThread.java

示例10: createInsecureSslFactory

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * This method creates an insecure SSL factory that will trust on self signed certificates.
 * For that we use {@link TrustSelfSignedStrategy}.
 */
protected SSLConnectionSocketFactory createInsecureSslFactory() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());
        SSLContext sc = builder.build();

        if (acceptAllKindsOfCertificates) {
            TrustManager[] trustAllCerts = new TrustManager[1];
            TrustManager tm = new TrustAllManager();
            trustAllCerts[0] = tm;
            sc.init(null, trustAllCerts, null);

            HostnameVerifier hostnameVerifier = createInsecureHostNameVerifier();
            return new SSLConnectionSocketFactory(sc, hostnameVerifier);
        }
        return new SSLConnectionSocketFactory(sc);
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        throw new ApacheCloudStackClientRuntimeException(e);
    }
}
 
開發者ID:Autonomiccs,項目名稱:apache-cloudstack-java-client,代碼行數:25,代碼來源:ApacheCloudStackClient.java

示例11: setTrustedKeystore

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public void setTrustedKeystore(final Keystore keystore) throws Exception {
    final SSLContextBuilder ssl = SSLContexts.custom();

    final String path = keystore.getPath();
    final String password = keystore.getPassword();

    final URL resource = HttpClientFactoryBean.class.getClassLoader().getResource(path);

    if (resource == null) {
        throw new FileNotFoundException(format("Keystore [%s] not found.", path));
    }

    try {
        ssl.loadTrustMaterial(resource, password == null ? null : password.toCharArray());
        builder.setSSLSocketFactory(new SSLConnectionSocketFactory(ssl.build(), getDefaultHostnameVerifier()));
    } catch (final Exception e) {
        LOG.error("Error loading keystore [{}]:", path, e); // log full exception, bean initialization code swallows it
        throw e;
    }
}
 
開發者ID:zalando,項目名稱:riptide,代碼行數:21,代碼來源:HttpClientFactoryBean.java

示例12: TankHttpClient4

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * no-arg constructor for client
 */
public TankHttpClient4() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
    } catch (Exception e) {
        LOG.error("Error setting accept all: " + e, e);
    }

    httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    requestConfig = RequestConfig.custom().setSocketTimeout(30000)
    		.setConnectTimeout(30000)
    		.setCircularRedirectsAllowed(true)
    		.setAuthenticationEnabled(true)
    		.setRedirectsEnabled(true)
    		.setCookieSpec(CookieSpecs.STANDARD)
            .setMaxRedirects(100).build();

    // Make sure the same context is used to execute logically related
    // requests
    context = HttpClientContext.create();
    context.setCredentialsProvider(new BasicCredentialsProvider());
    context.setCookieStore(new BasicCookieStore());
    context.setRequestConfig(requestConfig);
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:29,代碼來源:TankHttpClient4.java

示例13: getHttpClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private HttpClient getHttpClient() {
    CloseableHttpClient httpclient = null;

    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(keyStore, (TrustStrategy) (trustedCert, nameConstraints) -> true);

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
        httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        _logger.error("Failed to create HTTPClient: {}", e);
    }

    return httpclient;
}
 
開發者ID:hawkular,項目名稱:hawkular-client-java,代碼行數:17,代碼來源:RestFactory.java

示例14: getHttpClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
protected HttpClient getHttpClient(Map<String, Object> options) throws GeneralSecurityException {
    SocketConfig socketConfig = SocketConfig.custom()
            .setSoKeepAlive(true).build();

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    httpClientBuilder.setDefaultSocketConfig(socketConfig);
    httpClientBuilder.disableAuthCaching();
    httpClientBuilder.disableAutomaticRetries();

    if(options.containsKey("sslVerify") && !Boolean.parseBoolean(options.get("sslVerify").toString())) {
        log.debug("Disabling all SSL certificate verification.");
        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(null, new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                return true;
            }
        });

        httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
        httpClientBuilder.setSSLContext(sslContextBuilder.build());
    }

    return httpClientBuilder.build();
}
 
開發者ID:ohioit,項目名稱:rundeck-http-plugin,代碼行數:27,代碼來源:HttpWorkflowStepPlugin.java

示例15: getAuthenticatedClient

import org.apache.http.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public CloseableHttpClient getAuthenticatedClient() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                builder.build(), NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .setDefaultCredentialsProvider(getCredentialsProvider())
                .build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        Logger.getLogger(AuthHandler.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
開發者ID:Adobe-Consulting-Services,項目名稱:curly,代碼行數:17,代碼來源:AuthHandler.java


注:本文中的org.apache.http.ssl.SSLContextBuilder.loadTrustMaterial方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。