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


Java SSLContexts類代碼示例

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


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

示例1: restTemplate

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
開發者ID:borysfan,項目名稱:websocket-poc,代碼行數:20,代碼來源:App.java

示例2: buildCertificateIgnoringSslContext

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
/**
 * Will create a certificate-ignoring {@link SSLContext}. Please use with utmost caution as it undermines security,
 * but may be useful in certain testing or development scenarios.
 *
 * @return The SSLContext
 */
public static SSLContext buildCertificateIgnoringSslContext() {
	try {
		return SSLContexts
			.custom()
			.loadTrustMaterial(new TrustStrategy() {
				@Override
				public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
					return true;
				}
			})
			.build();
	}
	catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		throw new IllegalStateException("Unexpected exception while building the certificate-ignoring SSLContext.", e);
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:23,代碼來源:HttpClientUtils.java

示例3: getSSLConnectionSocketFactory

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
private SSLConnectionSocketFactory getSSLConnectionSocketFactory() {
	// Trust own CA and all self-signed certificates
       SSLContext sslcontext = null;
	try {
		sslcontext = SSLContexts.custom()
		        .loadTrustMaterial(new File("sepa.jks"), "*sepa.jks*".toCharArray(),new TrustSelfSignedStrategy())
		        .build();
	} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException
			| IOException e1) {
		logger.error(e1.getMessage());
		return null;
	}
	
       // Allow TLSv1 protocol only
       SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
               sslcontext,
               new String[] { "TLSv1" },
               null,
               new SEPAHostnameVerifier());
       return 	sslsf;
}
 
開發者ID:vaimee,項目名稱:sepatools,代碼行數:22,代碼來源:SPARQL11SEProtocol.java

示例4: httpClient

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
private HttpClient httpClient(JiraConnectionProperties jiraConnectionProperties) {
	try {
		SSLContext sslContext = SSLContexts.custom()
			.loadTrustMaterial(
				jiraConnectionProperties.getSslTrustStore().getFile(),
				jiraConnectionProperties.getSslTrustStorePassword())
			.build();

		HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
		SSLSocketFactory socketFactory = sslContext.getSocketFactory();
		LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(socketFactory, hostnameVerifier);

		if (jiraConnectionProperties.getSshJumpHost() != null) {
			sshProxy = new SshProxy();
			sslSocketFactory = new SshTunnelSslSocketFactory(sshProxy, sslSocketFactory, jiraConnectionProperties.getSshJumpHost());
		}

		return HttpClientBuilder.create()
			.setSSLSocketFactory(sslSocketFactory)
			.build();
	} catch (GeneralSecurityException | IOException e) {
		throw new JiraSyncException("Failed to build custom http client", e);
	}
}
 
開發者ID:cronn-de,項目名稱:jira-sync,代碼行數:25,代碼來源:JiraServiceRestClient.java

示例5: 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

示例6: setSslContextFilePath

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
@Override
public void setSslContextFilePath(String filePath) {
  if (null == partnerId) {
    throw new IllegalArgumentException("請設置partnerId的值");
  }

  File file = new File(filePath);
  if (!file.exists()) {
    throw new RuntimeException("證書文件:【" + file.getPath() + "】不存在!");
  }

  try {
    FileInputStream inputStream = new FileInputStream(file);
    KeyStore keystore = KeyStore.getInstance("PKCS12");
    char[] partnerId2charArray = partnerId.toCharArray();
    keystore.load(inputStream, partnerId2charArray);
    this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
  } catch (Exception e) {
    throw new RuntimeException("證書文件有問題,請核實!", e);
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:22,代碼來源:WxMpInMemoryConfigStorage.java

示例7: 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

示例8: buildSSLConnectionSocketFactory

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

示例9: setupHttpsUnirest

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
public static void setupHttpsUnirest() {
    SSLContext sslcontext = null;
    try {
        sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        fail(e.toString());
    }

    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    });
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    Unirest.setHttpClient(httpclient);
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:18,代碼來源:TestUtils.java

示例10: getSSLAcceptingClient

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

示例11: setTrustedKeystore

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

示例12: createSSLHttpClient

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
/**
 * @return
 */
private HttpClient createSSLHttpClient() {

	final TrustStrategy acceptingTrustStrategy = new TrustStrategy() {

		@Override
		public boolean isTrusted(final X509Certificate[] arg0, final String arg1) throws CertificateException {
			return true;
		}
	};

	SSLContext sslContext = null;
	try {
		sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
	} catch (final Exception e) {
		System.out.println("Could not create SSLContext");
	}

	return HttpClientBuilder.create().setSSLContext(sslContext).build();
}
 
開發者ID:kevinsamyn,項目名稱:soccerama-pro-client,代碼行數:23,代碼來源:SocceramaAPIClient.java

示例13: 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

示例14: createSslCustomContext

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
protected static SSLContext createSslCustomContext() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException, NoSuchProviderException {
    // Load platform specific Trusted CA keystore
    logger.trace(() -> Arrays.toString(Security.getProviders()));
    KeyStore tks;
    switch (AppEnvironment.getInstance().getOsFamily()) {
        case WINDOWS:
            tks = KeyStore.getInstance("Windows-ROOT", "SunMSCAPI");
            tks.load(null, null);
            break;
        case OSX:
            tks = KeyStore.getInstance("KeychainStore", "Apple");
            tks.load(null, null);
            break;
        case LINUX:
        case UNSUPPORTED:
        default:
            tks = null;
            break;
    }
    return SSLContexts.custom().loadTrustMaterial(tks, null).build();
}
 
開發者ID:fthevenet,項目名稱:binjr,代碼行數:22,代碼來源:HttpDataAdapterBase.java

示例15: initClientSession

import org.apache.http.ssl.SSLContexts; //導入依賴的package包/類
public void initClientSession() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
	// Trust own CA and all self-signed certs
	SSLContext sslcontext = SSLContexts.custom()
			.loadTrustMaterial(TRUSTSTORE_FILE, TRUSTSTORE_PASS.toCharArray(),
					new TrustSelfSignedStrategy())
					.loadKeyMaterial(KEYSTORE_FILE, KEYSTORE_PASS.toCharArray(), KEYSTORE_PASS.toCharArray())
					.build();
	// Allow TLSv1 protocol only
	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
			sslcontext,
			new String[] { "TLSv1" },
			null,
			SSLConnectionSocketFactory.getDefaultHostnameVerifier());
	this.httpclient = HttpClients.custom()
			.setSSLSocketFactory(sslsf)
			.build();
}
 
開發者ID:paulobichara,項目名稱:cas4-x509-auth,代碼行數:18,代碼來源:ClientCustomSSL.java


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