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


Java SSLContexts.createDefault方法代碼示例

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


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

示例1: setDefaultSSLSocketFactory

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * Sets a Safecharge's default  {@link LayeredConnectionSocketFactory} object to set connection properties,
 * such as supported SSL Protocols, hostname verifier, etc(needed to create a https connection).
 *
 * @return this object
 */
public SafechargeClientBuilder setDefaultSSLSocketFactory() {
    SSLContext sslContext = SSLContexts.createDefault();
    String[] javaSupportedProtocols = sslContext.getSupportedSSLParameters()
            .getProtocols();

    List<String> supportedProtocols = new ArrayList<>();
    for (String SERVER_SUPPORTED_SSL_PROTOCOL : SERVER_SUPPORTED_SSL_PROTOCOLS) {
        for (String javaSupportedProtocol : javaSupportedProtocols) {
            if (SERVER_SUPPORTED_SSL_PROTOCOL.equals(javaSupportedProtocol)) {
                supportedProtocols.add(SERVER_SUPPORTED_SSL_PROTOCOL);
            }
        }
    }

    if (!supportedProtocols.isEmpty()) {
        sslSocketFactory =
                new SSLConnectionSocketFactory(sslContext, supportedProtocols.toArray(new String[]{}), null, new DefaultHostnameVerifier());
    } else {
        throw new UnsupportedOperationException("Your Java version doesn't support any of the server supported SSL protocols: " + Arrays.toString(
                SERVER_SUPPORTED_SSL_PROTOCOLS));
    }
    return this;
}
 
開發者ID:SafeChargeInternational,項目名稱:safecharge-java,代碼行數:30,代碼來源:SafechargeClientBuilder.java

示例2: NestSession

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
public NestSession(String username, String password) throws LoginException {
	super();
	theLine = null;
	theBody = null;
	response = null;
	theUsername = new String(username);
	thePassword = new String(password);
	log.info("Starting Nest login...");
	retry = 0;
       // Trust own CA and all self-signed certs
       sslcontext = SSLContexts.createDefault();
       // Allow TLSv1 protocol only
       sslsf = new SSLConnectionSocketFactory(
               sslcontext,
               new String[] { "TLSv1" },
               null,
               SSLConnectionSocketFactory.getDefaultHostnameVerifier());
       globalConfig = RequestConfig.custom()
               .setCookieSpec(CookieSpecs.STANDARD)
               .build();
       
       _login();
}
 
開發者ID:bwssytems,項目名稱:nest-controller,代碼行數:24,代碼來源:NestSession.java

示例3: testSSLTrustVerification

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
@Test(expected=SSLException.class)
public void testSSLTrustVerification() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();
    // Use default SSL context
    final SSLContext defaultsslcontext = SSLContexts.createDefault();

    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(defaultsslcontext,
            NoopHostnameVerifier.INSTANCE);

    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    sslSocket.close();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestSSLSocketFactory.java

示例4: createHttpClient

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
private static CloseableHttpClient createHttpClient(String host, int port, String username, String password) {
    try {
        SSLContext sslContext = SSLContexts.createDefault();
        SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("https", sslConnectionSocketFactory)
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .build();
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(host, port, MANAGEMENT_REALM, AuthSchemes.DIGEST),
                new UsernamePasswordCredentials(username, password));
        PoolingHttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager(registry);
        HttpClientBuilder.create().setConnectionManager(connectionPool).build();
        return HttpClientBuilder.create()
                .setConnectionManager(connectionPool)
                .setRetryHandler(new StandardHttpRequestRetryHandler(5, true))
                .setDefaultCredentialsProvider(credsProvider).build();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:22,代碼來源:HttpGenericOperationUnitTestCase.java

示例5: main

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
public final static void main(String[] args) throws Exception {
    // KeyStore trustStore =
    // KeyStore.getInstance(KeyStore.getDefaultType());
    // FileInputStream instream = new FileInputStream(new
    // File("my.keystore"));
    // try {
    // trustStore.load(instream, "nopassword".toCharArray());
    // } finally {
    // instream.close();
    // }
    // // Trust own CA and all self-signed certs
    // SSLContext sslcontext =
    // SSLContexts.custom().loadTrustMaterial(trustStore, new
    // TrustSelfSignedStrategy())
    // .build();
    SSLContext sslcontext = SSLContexts.createDefault();
    // Allow TLSv1 protocol only
    SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null,
            SSLIOSessionStrategy.getDefaultHostnameVerifier());
    CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).build();
    try {
        httpclient.start();
        HttpGet request = new HttpGet("https://github.com/dzh");
        Future<HttpResponse> future = httpclient.execute(request, null);
        HttpResponse response = future.get();
        System.out.println("Response: " + response.getStatusLine());
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}
 
開發者ID:yunpian,項目名稱:yunpian-java-sdk,代碼行數:33,代碼來源:AsyncClientCustomSSL.java

示例6: buildHttpsClient

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * Create a new httpsClient
 * 
 * @return a new httpsClient
 */
private CloseableHttpClient buildHttpsClient() {
	// Trust all SSL certificates the host trusts
	// TODO insecure, use custom keystore instead!
	SSLContext sslContext = SSLContexts.createDefault();

	// Allow TLSv1 protocol only
	SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null,
			SSLConnectionSocketFactory.getDefaultHostnameVerifier());

	// Create and return httpsClient
	return HttpClients.custom().setSSLSocketFactory(sslSF).build();
}
 
開發者ID:marzn,項目名稱:telegrambot-japi,代碼行數:18,代碼來源:Bot.java

示例7: sslContext

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
@Override
public SSLContext sslContext() {
	return SSLContexts.createDefault();
}
 
開發者ID:bitsofinfo,項目名稱:hazelcast-docker-swarm-discovery-spi,代碼行數:5,代碼來源:SkipVerifyDockerCertificatesStore.java

示例8: init

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * Initialization method.  This takes in the configuration and sets up the underlying
 * http client appropriately.
 * @param configuration The user defined configuration.
 */
@Override
public void init(final Configuration configuration) {
    // Save reference to configuration
    this.configuration = configuration;

    // Create default SSLContext
    final SSLContext sslcontext = SSLContexts.createDefault();

    // Allow TLSv1 protocol only
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
        sslcontext,
        new String[] { "TLSv1" },
        null,
        SSLConnectionSocketFactory.getDefaultHostnameVerifier()
    );

    // Setup client builder
    final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    clientBuilder
        // Pardot disconnects requests after 120 seconds.
        .setConnectionTimeToLive(130, TimeUnit.SECONDS)
        .setSSLSocketFactory(sslsf);

    // Define our RequestConfigBuilder
    final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();

    // If we have a configured proxy host
    if (configuration.getProxyHost() != null) {
        // Define proxy host
        final HttpHost proxyHost = new HttpHost(
            configuration.getProxyHost(),
            configuration.getProxyPort(),
            configuration.getProxyScheme()
        );

        // If we have proxy auth enabled
        if (configuration.getProxyUsername() != null) {
            // Create credential provider
            final CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(
                new AuthScope(configuration.getProxyHost(), configuration.getProxyPort()),
                new UsernamePasswordCredentials(configuration.getProxyUsername(), configuration.getProxyPassword())
            );

            // Attach Credentials provider to client builder.
            clientBuilder.setDefaultCredentialsProvider(credsProvider);
        }

        // Attach Proxy to request config builder
        requestConfigBuilder.setProxy(proxyHost);
    }

    // Attach default request config
    clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());

    // build http client
    httpClient = clientBuilder.build();
}
 
開發者ID:Crim,項目名稱:pardot-java-client,代碼行數:64,代碼來源:HttpClientRestClient.java

示例9: getCloseableHttpClient

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
private static CloseableHttpClient getCloseableHttpClient() {
    SSLContext sslcontext = SSLContexts.createDefault();
    SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
            new String[]{HttpConstant.TLS_VERSION}, null,
            SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    return HttpClients.custom().setSSLSocketFactory(factory).build();
}
 
開發者ID:laohans,項目名稱:swallow-core,代碼行數:8,代碼來源:HttpsUtils.java

示例10: createConnectionSocketFactory

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
private static Registry<ConnectionSocketFactory> createConnectionSocketFactory() {
  HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault());
  ConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext != null ? sslContext :
      SSLContexts.createDefault(), hostnameVerifier);

  return RegistryBuilder.<ConnectionSocketFactory>create()
      .register("http", PlainConnectionSocketFactory.getSocketFactory())
      .register("https", sslSocketFactory)
      .build();
}
 
開發者ID:sedmelluq,項目名稱:lavaplayer,代碼行數:11,代碼來源:HttpClientTools.java

示例11: createSslContext

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * Create SSL context and initialize it using specific trust manager.
 *
 * @param trustManager trust manager
 * @return initialized SSL context
 * @throws GeneralSecurityException on security error
 */
public static SSLContext createSslContext(TrustManager trustManager)
  throws GeneralSecurityException {
  EwsX509TrustManager x509TrustManager = new EwsX509TrustManager(null, trustManager);
  SSLContext sslContext = SSLContexts.createDefault();
  sslContext.init(
    null,
    new TrustManager[] { x509TrustManager },
    null
  );
  return sslContext;
}
 
開發者ID:OfficeDev,項目名稱:ews-java-api,代碼行數:19,代碼來源:EwsSSLProtocolSocketFactory.java

示例12: buildContext

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * @return reference to SSL Context
 */
private static SSLContext buildContext() {
    return SSLContexts.createDefault();
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:7,代碼來源:CloudApiSSLConnectionSocketFactory.java

示例13: getSocketFactory

import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
 * Obtains default SSL socket factory with an SSL context based on the standard JSSE
 * trust material ({@code cacerts} file in the security properties directory).
 * System properties are not taken into consideration.
 *
 * @return default SSL socket factory
 */
public static SSLConnectionSocketFactory getSocketFactory() throws SSLInitializationException {
    return new SSLConnectionSocketFactory(SSLContexts.createDefault(), getDefaultHostnameVerifier());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:SSLConnectionSocketFactory.java


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