本文整理匯總了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;
}
示例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();
}
示例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();
}
示例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);
}
}
示例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");
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例12: buildContext
import org.apache.http.ssl.SSLContexts; //導入方法依賴的package包/類
/**
* @return reference to SSL Context
*/
private static SSLContext buildContext() {
return SSLContexts.createDefault();
}
示例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());
}