当前位置: 首页>>代码示例>>Java>>正文


Java AllowAllHostnameVerifier类代码示例

本文整理汇总了Java中org.apache.http.conn.ssl.AllowAllHostnameVerifier的典型用法代码示例。如果您正苦于以下问题:Java AllowAllHostnameVerifier类的具体用法?Java AllowAllHostnameVerifier怎么用?Java AllowAllHostnameVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AllowAllHostnameVerifier类属于org.apache.http.conn.ssl包,在下文中一共展示了AllowAllHostnameVerifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeGetRequest

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Override
public ResponseObject executeGetRequest(String url, int timeoutInMs) throws IOException {
  final HttpGet request = new HttpGet(url);
  setHeaders(request);
  setCookies(request);

  try (CloseableHttpClient httpClient =
      HttpClients.custom()
          .setHostnameVerifier(new AllowAllHostnameVerifier())
          .setSslcontext(trustAllSslContext())
          .setDefaultRequestConfig(buildRequestConfig(timeoutInMs))
          .build();
      CloseableHttpResponse response = httpClient.execute(request)) {
    Header[] headersArray = response.getAllHeaders();
    Map<String, List<String>> tmpHeaders = new HashMap<>();
    for (Header header : headersArray) {
      tmpHeaders.put(header.getName(), Collections.singletonList(header.getValue()));
    }
    return new ResponseObject(tmpHeaders, IOUtils.toByteArray(response.getEntity().getContent()));
  } catch (Exception e) {
    throw new IOException(String.format("Failed to connect to %s - %s", url, e.getMessage()), e);
  }
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:24,代码来源:TrustedHttpRequestExecutor.java

示例2: createRestTemplate

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
        new UsernamePasswordCredentials(username, password));

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

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());

    HttpClient httpClient = HttpClientBuilder.create()
        .disableRedirectHandling()
        .setDefaultCredentialsProvider(credentialsProvider)
        .setSSLSocketFactory(connectionFactory)
        .build();

    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
    restTemplate.getInterceptors().addAll(interceptors);

    return restTemplate;
}
 
开发者ID:strepsirrhini-army,项目名称:chaos-lemur,代码行数:24,代码来源:StandardDirectorUtils.java

示例3: getApacheSslBypassClient

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private CloseableHttpClient getApacheSslBypassClient() throws NoSuchAlgorithmException,
        KeyManagementException, KeyStoreException {
    return HttpClients.custom().
            setHostnameVerifier(new AllowAllHostnameVerifier()).
            setSslcontext(new SSLContextBuilder()
                                  .loadTrustMaterial(null, (arg0, arg1) -> true)
                                  .build()).build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:RestSBControllerImpl.java

示例4: getSchemeRegistry

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public static SchemeRegistry getSchemeRegistry() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
        SSLSocketFactory sf = new SSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));
        return registry;
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:While1true,项目名称:JSSample,代码行数:21,代码来源:HttpUtils.java

示例5: ignoreAuthenticateServer

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的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

示例6: createRequestFactory

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private ClientHttpRequestFactory createRequestFactory(String host, String username,
        String password) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
            new UsernamePasswordCredentials(username, password));

    SSLContext sslContext = null;
    try {
        sslContext = SSLContexts.custom()
                .loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        throw new DirectorException("Unable to configure ClientHttpRequestFactory", e);
    }

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());

    // disabling redirect handling is critical for the way BOSH uses 302's
    HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling()
            .setDefaultCredentialsProvider(credentialsProvider)
            .setSSLSocketFactory(connectionFactory).build();

    return new HttpComponentsClientHttpRequestFactory(httpClient);
}
 
开发者ID:davidehringer,项目名称:bosh-java-client,代码行数:25,代码来源:SpringDirectorClientBuilder.java

示例7: testSSLSystemProperties

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testSSLSystemProperties() {
  try {
    SSLTestConfig.setSSLSystemProperties();
    assertNotNull("HTTPS scheme could not be created using the javax.net.ssl.* system properties.", 
        HttpClientUtil.createClient(null).getConnectionManager().getSchemeRegistry().get("https"));
    
    System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
    assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
    
    System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true");
    assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
    
    System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "");
    assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
    
    System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "false");
    assertEquals(AllowAllHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
  } finally {
    SSLTestConfig.clearSSLSystemProperties();
    System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:HttpClientUtilTest.java

示例8: test1

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public void test1() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException{
	// ## SHOULD FIRE OVER-PERMISSIVE HOSTNAME VERIFIER
	CloseableHttpClient httpClient = HttpClients.custom().
			setHostnameVerifier(new AllowAllHostnameVerifier()).
			setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
				// ## SHOULD FIRE OVER-PERMISSIVE TRUST MANAGER
				@Override
				public boolean isTrusted(X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
					return true;
				}
			}).build()).build();
	HttpGet httpget = new HttpGet("https://www.google.com/");
	CloseableHttpResponse response = httpClient.execute(httpget);
	try {
		System.out.println(response.toString());
	} finally {
		response.close();
	}
}
 
开发者ID:GDSSecurity,项目名称:JSSE_Fortify_SCA_Rules,代码行数:20,代码来源:ApacheHTTPClientFluentExample.java

示例9: getHgmHttpsRestTemplate

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Bean
@Qualifier("hgmRestTemplate")
public RestTemplate getHgmHttpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException,
    KeyManagementException {
  SSLContext sslContext =
      SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
          .build();
  SSLConnectionSocketFactory connectionFactory =
      new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
  BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUsername(),
      configuration.getPassword()));

  HttpClient httpClient =
      HttpClientBuilder.create().setSSLSocketFactory(connectionFactory)
          .setDefaultCredentialsProvider(credentialsProvider).build();

  ClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  return new RestTemplate(requestFactory);
}
 
开发者ID:trustedanalytics,项目名称:hdfs-broker,代码行数:22,代码来源:HgmHttpsConfiguration.java

示例10: createSslHttpClient

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的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

示例11: init

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@PostConstruct
public void init() {
	try {
		HttpClientInfo httpci = this.commonConfig.createHttpClientInfo();

		http  = HttpClients.custom()
		        .setConnectionManager(httpci.getCm()).setDefaultRequestConfig(httpci.getGlobalConfig()).setHostnameVerifier(new AllowAllHostnameVerifier())
		        .build();
		

		URL uurl = new URL(commonConfig.getScaleConfig().getServiceConfiguration()
				.getUnisonURL());
		int port = uurl.getPort();
		
		HttpServletRequest request = (HttpServletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();
		this.login = request.getRemoteUser();
	} catch (Exception e) {
		logger.error("Could not initialize ScaleSession",e);
	}
	
}
 
开发者ID:TremoloSecurityRetired,项目名称:Scale,代码行数:23,代码来源:ScaleSession.java

示例12: setupClient

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("AllowAllHostnameVerifier")
private void setupClient(HttpURLConnection conn, boolean acceptAnyCertificate)
        throws CertificateException, UnrecoverableKeyException,
        NoSuchAlgorithmException, KeyStoreException,
        KeyManagementException, NoSuchProviderException,
        IOException {

    // bug caused by Lighttpd
    //conn.setRequestProperty("Expect", "100-continue");
    conn.setConnectTimeout(CONNECT_TIMEOUT);
    conn.setReadTimeout(READ_TIMEOUT);
    conn.setDoInput(true);
    if (conn instanceof HttpsURLConnection) {
        ((HttpsURLConnection) conn).setSSLSocketFactory(setupSSLSocketFactory(mContext,
            mPrivateKey, mCertificate, acceptAnyCertificate));
        if (acceptAnyCertificate)
            ((HttpsURLConnection) conn).setHostnameVerifier(new AllowAllHostnameVerifier());
    }
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:21,代码来源:ClientHTTPConnection.java

示例13: getHttpsClientTrustAll

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public HttpClient getHttpsClientTrustAll() {
    try {
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        }, new AllowAllHostnameVerifier());

        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, sf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
    	log.error("Failed to create TrustAll https client", ex);
        return new DefaultHttpClient();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:22,代码来源:HttpService.java

示例14: BuildHttpClient

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public DefaultHttpClient BuildHttpClient() throws UnknownHostException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {

        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain,
                    String authType) throws CertificateException {
                return true;
            }
        }, new AllowAllHostnameVerifier());
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry);
        //ClientConnectionManager ccm=new SingleClientConnManager(registry);
        DefaultHttpClient httpclient = new DefaultHttpClient(ccm);
        ccm.setMaxTotal(999);
        ccm.setDefaultMaxPerRoute(10);

        return httpclient;
    }
 
开发者ID:yhdelgado,项目名称:metharto,代码行数:22,代码来源:Conection.java

示例15: createClient

import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
protected HttpClient createClient() throws Exception {
    DefaultHttpClient result = new DefaultHttpClient();
    SchemeRegistry sr = result.getConnectionManager().getSchemeRegistry();
    
    SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {
        
        @Override
        public boolean isTrusted(X509Certificate[] arg0, String arg1)
                throws CertificateException {
            return true;
        }
    }, new AllowAllHostnameVerifier());
    
    Scheme httpsScheme2 = new Scheme("https", 443, sslsf);
    sr.register(httpsScheme2);
    
    return result;
}
 
开发者ID:52North,项目名称:Supervisor,代码行数:19,代码来源:JsonServiceCheck.java


注:本文中的org.apache.http.conn.ssl.AllowAllHostnameVerifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。