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


Java TrustStrategy類代碼示例

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


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

示例1: createAllTrustingClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的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

示例2: createSecurityRestTemplate

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
/**
 * Creates the security rest template.
 *
 * @throws KeyManagementException the key management exception
 * @throws NoSuchAlgorithmException the no such algorithm exception
 * @throws KeyStoreException the key store exception
 */
private void createSecurityRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException{
	TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
	SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
	        .loadTrustMaterial(null, acceptingTrustStrategy)
	        .build();
	SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
	
	HttpComponentsClientHttpRequestFactory requestFactory =
	        new HttpComponentsClientHttpRequestFactory();
	
	 HttpClient httpClient = HttpClientBuilder.create()
               .disableCookieManagement()
               .useSystemProperties()
               .setSSLSocketFactory(csf)
               .build();
	requestFactory.setHttpClient(httpClient);
	this.restTemplate = new RestTemplate(requestFactory);
}
 
開發者ID:ac-silva,項目名稱:desafio-pagarme,代碼行數:26,代碼來源:Client.java

示例3: getSSLSocketFactory

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
/**
 * 獲取LayeredConnectionSocketFactory 使用ssl單向認證
 * 
 * @date 2015年7月17日
 * @return
 */
private LayeredConnectionSocketFactory getSSLSocketFactory() {
	try {
		SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {

			// 信任所有
			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
				return true;
			}
		}).build();

		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
				SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		return sslsf;
	} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		logger.error(e.getMessage(), e);
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:25,代碼來源:HttpUtils.java

示例4: getCustomClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
/**
 * custom http client for server with SSL errors
 *
 * @return
 */
public final CloseableHttpClient getCustomClient() {
    try {
        HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
                (TrustStrategy) (X509Certificate[] arg0, String arg1) -> true).build();
        builder.setSSLContext(sslContext);
        HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory)
                .build();
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        builder.setConnectionManager(connMgr);
        return builder.build();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return getSystemClient();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:26,代碼來源:AbstractHttpClient.java

示例5: buildClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
@SuppressWarnings("deprecation")
static CloseableHttpClient buildClient(boolean ignoreSSL) throws Exception {
  SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {

    public boolean isTrusted(
        final X509Certificate[] chain, String authType) throws CertificateException {
      // Oh, I am easy...
      return true;
    }

  });
  if (ignoreSSL) {
    return HttpClients.custom().setSSLSocketFactory(sslsf).build();
  } else {
    return HttpClients.createDefault();
  }
}
 
開發者ID:dcos-labs,項目名稱:dcos-maven-plugin,代碼行數:18,代碼來源:DcosPluginHelper.java

示例6: createSSLClientDefault

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
private CloseableHttpClient createSSLClientDefault() {
	try {
		SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
			// 信任所有
			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
				if (cert != null) {
					for (X509Certificate chainCert : chain) {
						if (chainCert.equals(cert)) {
							return true;
						}
					}
					return false;
				}
				return true;
			}
		}).build();
		SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslContext);
		return HttpClients.custom().setSSLSocketFactory(factory).build();
	} catch (GeneralSecurityException e) {
		logger.error(String.format("SSL connection create Fail : %s", e.getMessage()));
	}
	return HttpClients.createDefault();
}
 
開發者ID:PinaeOS,項目名稱:pumbaa,代碼行數:24,代碼來源:HttpClientUtils.java

示例7: buildSSLConnectionSocketFactory

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
private SSLConnectionSocketFactory buildSSLConnectionSocketFactory() {
  try {
    SSLContext sslcontext = SSLContexts.custom()
      //忽略掉對服務器端證書的校驗
      .loadTrustMaterial(new TrustStrategy() {
        @Override
        public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
          return true;
        }
      }).build();

    return new SSLConnectionSocketFactory(
      sslcontext,
      new String[]{"TLSv1"},
      null,
      SSLConnectionSocketFactory.getDefaultHostnameVerifier());
  } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
    this.log.error(e.getMessage(), e);
  }

  return null;
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools,代碼行數:23,代碼來源:DefaultApacheHttpClientBuilder.java

示例8: createHttpClientWithDisabledSSLCheck

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
private CloseableHttpClient createHttpClientWithDisabledSSLCheck(){
    SSLContext sslcontext = null;
       try {
           sslcontext = SSLContexts.custom()
                   .loadTrustMaterial(null, new TrustStrategy(){

                       @Override
                       public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                           return true;
                       }
                       
                   })
                   .build();
       } catch (Exception e) {
           throw new RuntimeException("SSL Context can not be created.", e);
       }

       SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
       return HttpClients.custom()
                        .setSSLSocketFactory(sslsf)
                        .build();
}
 
開發者ID:automate-website,項目名稱:manager-api-client,代碼行數:23,代碼來源:RestTemplate.java

示例9: createSSLSocketFactory

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
private SSLSocketFactory createSSLSocketFactory(boolean useKeyStoreToConnect, String keyStorePath,
                                                String keyStorePassword) throws Exception {

    //Only load KeyStore when it's needed to connect to IP, SSLContext is fine with KeyStore being null otherwise.
    KeyStore trustStore = null;
    if (useKeyStoreToConnect) {
        trustStore = KeyStoreLoader.loadKeyStore(keyStorePath, keyStorePassword);
    }

    SSLContext sslContext = SSLContexts.custom()
            .useSSL()
            .loadTrustMaterial(trustStore, new TrustStrategy() {
                //Always trust
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
            })
            .loadKeyMaterial(trustStore, keyStorePassword.toCharArray())
            .setSecureRandom(new java.security.SecureRandom())
            .build();

    return sslContext.getSocketFactory();
}
 
開發者ID:Microsoft,項目名稱:Availability-Monitor-for-Kafka,代碼行數:25,代碼來源:Producer.java

示例10: getHttpsClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的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

示例11: getSSLAcceptingClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
/**
 * Creates {@link HttpClient} that trusts any SSL certificate
 *
 * @return prepared HTTP client
 */
protected HttpClient getSSLAcceptingClient() {
	final TrustStrategy trustAllStrategy = (final X509Certificate[] chain, final String authType) -> true;
	try {
		final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, trustAllStrategy).build();

		sslContext.init(null, getTrustManager(), new SecureRandom());
		final SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
				new NoopHostnameVerifier());

		return HttpClients.custom().setSSLSocketFactory(connectionSocketFactory).build();
	} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException error) {
		ConsoleUtils.printError(error.getMessage());
		throw new IllegalStateException(ErrorMessage.CANNOT_CREATE_SSL_SOCKET, error);
	}
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:21,代碼來源:AbstractHACCommunicationManager.java

示例12: getHttpClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的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

示例13: getHttpClient

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的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

示例14: getSSLSocketFactory

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
private SSLConnectionSocketFactory getSSLSocketFactory() {
    KeyStore trustStore;
    try {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        TrustStrategy trustStrategy = new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }

        };

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
        sslContextBuilder.useTLS();
        SSLContext sslContext = sslContextBuilder.build();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
        return sslSocketFactory;
    } catch (GeneralSecurityException | IOException e) {
        System.err.println("SSL Error : " + e.getMessage());
    }
    return null;
}
 
開發者ID:Esri,項目名稱:performance-test-harness-for-geoevent,代碼行數:25,代碼來源:GeoEventProvisioner.java

示例15: test1

import org.apache.http.conn.ssl.TrustStrategy; //導入依賴的package包/類
public void test1() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException{
	// ## SHOULD FIRE OVER-PERMISSIVE HOSTNAME VERIFIER
	CloseableHttpClient httpClient = HttpClients.custom().
			setHostnameVerifier(new AllowAllHostnameVerifier()).
			setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
				// ## SHOULD FIRE OVER-PERMISSIVE TRUST MANAGER
				@Override
				public boolean isTrusted(X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
					return true;
				}
			}).build()).build();
	HttpGet httpget = new HttpGet("https://www.google.com/");
	CloseableHttpResponse response = httpClient.execute(httpget);
	try {
		System.out.println(response.toString());
	} finally {
		response.close();
	}
}
 
開發者ID:GDSSecurity,項目名稱:JSSE_Fortify_SCA_Rules,代碼行數:20,代碼來源:ApacheHTTPClientFluentExample.java


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