本文整理匯總了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}
示例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 );
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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();
}
}