当前位置: 首页>>代码示例>>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;未经允许,请勿转载。