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


Java SSLContextBuilder類代碼示例

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


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

示例1: createSSLConnectionSocketFactory

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
private static SSLConnectionSocketFactory createSSLConnectionSocketFactory(Path path, char[] password, boolean strict, KeystoreType keystoreType) {
	try {
		SSLContextBuilder builder = SSLContexts.custom();
		if (path != null) {
			KeyStore trustStore = KeyStore.getInstance(keystoreType.name());
			try (InputStream is = Files.newInputStream(path)) {
				trustStore.load(is, password);
			}

			builder.loadTrustMaterial(trustStore);
		} else {
			builder.loadTrustMaterial(null, new TrustEverythingStrategy());
		}

		X509HostnameVerifier verifier;
		if (strict) {
			verifier = SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER;
		} else {
			verifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
		}

		return new SSLConnectionSocketFactory(builder.build(), new String[] {"TLSv1", "TLSv1.2"}, null, verifier);
	} catch (IOException | GeneralSecurityException ex) {
		throw new RuntimeException("Can't create SSL connection factory", ex);
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:27,代碼來源:HttpClient.java

示例2: getSSLSocketFactory

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

示例3: ignoreAuthenticateServer

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public AbstractRestTemplateClient ignoreAuthenticateServer() {
    //backward compatible with android httpclient 4.3.x
    if(restTemplate.getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
            X509HostnameVerifier verifier = ignoreSslWarning ? new AllowAllHostnameVerifier() : new BrowserCompatHostnameVerifier();
            SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, verifier);
            HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
            ((HttpComponentsClientHttpRequestFactory)restTemplate.getRequestFactory()).setHttpClient(httpClient);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Debug.error("the request factory " + restTemplate.getRequestFactory().getClass().getName() + " does not support ignoreAuthenticateServer");
    }
    return this;
}
 
開發者ID:Enterprise-Content-Management,項目名稱:documentum-rest-client-java,代碼行數:18,代碼來源:AbstractRestTemplateClient.java

示例4: getInstance

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public static SSLConnectionSocketFactory getInstance() {
    if (sslConnectionSocketFactory == null) {
        synchronized (ConnectionManagerFactory.class) {
            if (sslConnectionSocketFactory == null) {
                try{
                    SSLContextBuilder builder = new SSLContextBuilder();
                    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
                    sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build());
                }catch(Exception exception){
                    exception.getStackTrace();
                }
            }
        }
    }
    return sslConnectionSocketFactory;
}
 
開發者ID:DISSIDIA-986,項目名稱:EncDecAboutJava,代碼行數:17,代碼來源:SSLFactory.java

示例5: getSSLSocketFactory

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

示例6: createSslHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
private CloseableHttpClient createSslHttpClient() throws Exception {
    final SSLContextBuilder wsBuilder = new SSLContextBuilder();
    wsBuilder.loadTrustMaterial(null, new TrustStrategy() {
        @Override
        public boolean isTrusted(X509Certificate[] chain,
            String authType) throws CertificateException {
            return true;
        }
    });
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(wsBuilder.build(),
        new AllowAllHostnameVerifier());
    //This winds up using a PoolingHttpClientConnectionManager so need to pass the
    //RegistryBuilder
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder
        .<ConnectionSocketFactory> create().register("https", sslsf)
        .build();
    final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
    return HttpClients
        .custom()
        .setConnectionManager(cm)
        .build();

}
 
開發者ID:apache,項目名稱:tinkerpop,代碼行數:24,代碼來源:AbstractGremlinServerChannelizerIntegrateTest.java

示例7: DWServerConnection

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public DWServerConnection(DWSettingsProvider settingsProvider) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    this.settingsProvider = settingsProvider;

    // SSLContextFactory to allow all hosts. Without this an SSLException is thrown with self signed certs
    SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", socketFactory).build();

    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connectionManager.setMaxTotal(200);
    connectionManager.setDefaultMaxPerRoute(20);

    client = HttpClients.custom()
            .setConnectionManager(connectionManager)
            .build();

    context = new HttpClientContext();
    context.setCredentialsProvider(getCredientials());
}
 
開發者ID:nek4life,項目名稱:intellij-demandware,代碼行數:20,代碼來源:DWServerConnection.java

示例8: httpsCertAuth

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
/**
 * Produces a HTTPS client with client certificate-based authentication.
 *
 * @param keyStorePath
 *            Key store where client certificate is stored.
 * @param keyStorePassword
 *            Key store password.
 * @param keystoreType
 *            The type of key store.
 * @return
 * @throws RuntimeException
 */
public static Client httpsCertAuth(String keyStorePath, String keyStorePassword, SslKeyStoreType keystoreType)
        throws RuntimeException {

    SSLContext sslContext;
    try (InputStream keystoreFile = new FileInputStream(keyStorePath)) {
        KeyStore keystore = KeyStore.getInstance(keystoreType.name());
        keystore.load(keystoreFile, keyStorePassword.toCharArray());
        sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy())
                .loadKeyMaterial(keystore, keyStorePassword.toCharArray()).build();
    } catch (Exception e) {
        throw new RuntimeException("failed to set up an SSL context: " + e.getMessage(), e);
    }

    Client client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(allowAnyVerifier()).build();

    client.register(new LoggingFilter());
    return client;
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:31,代碼來源:RestClientUtils.java

示例9: createHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public CloseableHttpClient createHttpClient(boolean allowSelfSigned)
		throws IOException {
	CloseableHttpClient httpclient = null;

	if (allowSelfSigned) {
		try {
			SSLContextBuilder builder = new SSLContextBuilder();
			builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
			SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
					builder.build(),
					SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
			httpclient = HttpClients.custom().setSSLSocketFactory(sslsf)
					.setDefaultCookieStore(cookieStore).build();
		} catch (Exception e) {
			throw new IOException(e);
		}

	} else {
		httpclient = HttpClients.custom()
				.setDefaultCookieStore(cookieStore).build();
	}

	return httpclient;
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:25,代碼來源:HttpUtilsHolder.java

示例10: createBuilder

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
/**
 * Create a standard builder, firefox agent and ssl easy support.
 *
 * @return the builder.
 */
public static HttpClientBuilder createBuilder()
{
    try
    {
        return HttpClientBuilder
            .create()
            .setDefaultCookieStore( new BasicCookieStore() )
            .setUserAgent( "Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1" )
            .setSSLSocketFactory(
                new SSLConnectionSocketFactory(
                    new SSLContextBuilder()
                    .loadTrustMaterial( null ,
                                        new TrustSelfSignedStrategy() )
                    .build()
                )
            );
    }
    catch( final KeyManagementException |
                 KeyStoreException |
                 NoSuchAlgorithmException ex )
    {
        throw new RuntimeException( ex );
    }
}
 
開發者ID:fabienvauchelles,項目名稱:superpipes,代碼行數:30,代碼來源:HTTPhelper.java

示例11: buildSslContext

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
private SSLContext buildSslContext() {
    try {
        SSLContextBuilder contextBuilder = new SSLContextBuilder().
                useTLS().
                loadTrustMaterial(null, new TrustSelfSignedStrategy());

        return contextBuilder.build();
    } catch (GeneralSecurityException e) {
        throw new CloudOperationException(e);
    }
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:12,代碼來源:LoggregatorClient.java

示例12: buildSslContext

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
private javax.net.ssl.SSLContext buildSslContext() {
    try {
        return new SSLContextBuilder().useSSL().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
    } catch (GeneralSecurityException gse) {
        throw new RuntimeException("An error occurred setting up the SSLContext", gse);
    }
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:8,代碼來源:RestUtil.java

示例13: RestClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public RestClient(String baseUrl) throws Exception {
	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 [email protected]").setSSLSocketFactory(sslsf).build();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:8,代碼來源:RestClient.java

示例14: createUnsafeClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
public static HttpClient createUnsafeClient() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                builder.build());
        return HttpClients.custom()
                .setSSLSocketFactory(sslsf).build();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:13,代碼來源:UnsafeHttpsClient.java

示例15: createIgnoringCertificate

import org.apache.http.conn.ssl.SSLContextBuilder; //導入依賴的package包/類
/**
 * Ignore any validation about certificate. Use of this feature has security
 * consequences
 *
 * @return
 * @throws RestCallException
 */
public static CloseableHttpClient createIgnoringCertificate() throws RestCallException {
	try {
		CloseableHttpClient httpClient = HttpClients.custom().setHostnameVerifier(new AllowAllHostnameVerifier())
				.setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build()).build();

		return httpClient;
	} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
		throw new RestCallException();
	}
}
 
開發者ID:ccem-dev,項目名稱:otus-api,代碼行數:18,代碼來源:HttpClientFactory.java


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