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


Java DefaultHostnameVerifier類代碼示例

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


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

示例1: updateSslConfig

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
/**
 * @param httpConfig
 * @param config 
 */
@SuppressWarnings("nls")
private void updateSslConfig(Builder httpConfig, Map<String, String> config) {
    try {
        String clientKeystorePath = config.get("client-keystore");
        String clientKeystorePassword = config.get("client-keystore.password");
        String trustStorePath = config.get("trust-store");
        String trustStorePassword = config.get("trust-store.password");

        SSLContext sslContext = SSLContext.getInstance("TLS");
        Info kPathInfo = new Info(clientKeystorePath, clientKeystorePassword);
        Info tPathInfo = new Info(trustStorePath, trustStorePassword);
        sslContext.init(KeyStoreUtil.getKeyManagers(kPathInfo), KeyStoreUtil.getTrustManagers(tPathInfo), null);
        HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
        
        httpConfig.defaultSchemeForDiscoveredNodes("https");
        httpConfig.sslSocketFactory(sslSocketFactory); // for sync calls
        httpConfig.httpsIOSessionStrategy(httpsIOSessionStrategy); // for async calls

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:29,代碼來源:DefaultESClientFactory.java

示例2: setDefaultSSLSocketFactory

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

示例3: testHostnameVerification

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
@Test public void testHostnameVerification() throws Exception {
  AvaticaCommonsHttpClientImpl client = mock(AvaticaCommonsHttpClientImpl.class);
  // Call the real method
  when(client.getHostnameVerifier(nullable(HostnameVerification.class)))
      .thenCallRealMethod();

  // No verification should give the default (strict) verifier
  HostnameVerifier actualVerifier = client.getHostnameVerifier(null);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.STRICT);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof DefaultHostnameVerifier);

  actualVerifier = client.getHostnameVerifier(HostnameVerification.NONE);
  assertNotNull(actualVerifier);
  assertTrue(actualVerifier instanceof NoopHostnameVerifier);
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:20,代碼來源:AvaticaCommonsHttpClientImplTest.java

示例4: initHttpClient

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
private void initHttpClient() {
  ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
      .getApacheHttpClientBuilder();
  if (null == apacheHttpClientBuilder) {
    apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
  }

  apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
      .httpProxyPort(this.configStorage.getHttpProxyPort())
      .httpProxyUsername(this.configStorage.getHttpProxyUsername())
      .httpProxyPassword(this.configStorage.getHttpProxyPassword());

  if (this.configStorage.getSSLContext() != null) {
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
        this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
        new DefaultHostnameVerifier());
    apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
  }

  if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
    this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
  }

  this.httpClient = apacheHttpClientBuilder.build();
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:26,代碼來源:WxMpServiceImpl.java

示例5: testGetHostnameVerifier

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
@Test
public void testGetHostnameVerifier() {
  // Default
  HostnameVerifier verifier = SSLUtils.getHostnameVerifier(config);
  assertTrue(verifier instanceof DefaultHostnameVerifier);

  // Override
  config.setOverrideHostnameVerifier(new TestHostnameVerifier());
  verifier = SSLUtils.getHostnameVerifier(config);
  assertTrue(verifier instanceof TestHostnameVerifier);

  // Disabled
  config.setDisableSSLValidation(true);
  verifier = SSLUtils.getHostnameVerifier(config);
  assertTrue(verifier instanceof NoopHostnameVerifier);
}
 
開發者ID:cloudera,項目名稱:navigator-sdk,代碼行數:17,代碼來源:SSLUtilsTest.java

示例6: withSsl

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
/**
     * Adds Keystore for SSL
     *
     * @param keyStore     KeyStore input stream
     * @param keyStorePass KeyStore password
     * @return This builder
     */
    public final Builder withSsl(InputStream keyStore, String keyStorePass) {
        SSLContext sslcontext;
        try {
            sslcontext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(IOUtils.loadKeyStore(keyStore, keyStorePass), null)
                    .build();
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to load trust store", e);
        }

        /*
         * Unreal magic, but we can't use
* org.apache.http.conn.ssl.SSLConnectionSocketFactory
* .BROWSER_COMPATIBLE_HOSTNAME_VERIFIER here due to some problems
* related to classloaders. Initialize host name verifier explicitly
*/
        SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(
                sslcontext,
                new DefaultHostnameVerifier());
        httpClientBuilder.setSSLStrategy(sslSessionStrategy);

        return this;
    }
 
開發者ID:avarabyeu,項目名稱:restendpoint,代碼行數:30,代碼來源:RestEndpoints.java

示例7: updateSslConfig

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
/**
 * @param httpConfig
 */
@SuppressWarnings("nls")
private void updateSslConfig(Builder httpConfig) {
    try {
        String clientKeystorePath = getConfig().get("client-keystore");
        String clientKeystorePassword = getConfig().get("client-keystore.password");
        String trustStorePath = getConfig().get("trust-store");
        String trustStorePassword = getConfig().get("trust-store.password");

        SSLContext sslContext = SSLContext.getInstance("TLS");
        Info kPathInfo = new Info(clientKeystorePath, clientKeystorePassword);
        Info tPathInfo = new Info(trustStorePath, trustStorePassword);
        sslContext.init(KeyStoreUtil.getKeyManagers(kPathInfo), KeyStoreUtil.getTrustManagers(tPathInfo), null);
        HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
        
        httpConfig.defaultSchemeForDiscoveredNodes("https");
        httpConfig.sslSocketFactory(sslSocketFactory); // for sync calls
        httpConfig.httpsIOSessionStrategy(httpsIOSessionStrategy); // for async calls

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:28,代碼來源:DefaultEsClientFactory.java

示例8: hostnameVerifier

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
@ConditionalOnMissingBean(name = "hostnameVerifier")
@Bean
public HostnameVerifier hostnameVerifier() {
    if (casProperties.getHttpClient().getHostNameVerifier().equalsIgnoreCase("none")) {
        return NoopHostnameVerifier.INSTANCE;
    }
    return new DefaultHostnameVerifier();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:9,代碼來源:CasCoreHttpConfiguration.java

示例9: executeWithKey

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
private String executeWithKey(String url, String requestStr) throws WxErrorException {
  try {
    SSLContext sslContext = getConfig().getSslContext();
    if (null == sslContext) {
      throw new IllegalArgumentException("請先初始化配置類(即WxMpConfigStorage的實現類)中的SSLContext!");
    }

    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null,
      new DefaultHostnameVerifier());

    HttpPost httpPost = new HttpPost(url);
    if (this.wxMpService.getHttpProxy() != null) {
      httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
    }

    try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
      httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
      try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
        String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
        this.log.debug("\n[URL]:  {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result);
        return result;
      }
    } finally {
      httpPost.releaseConnection();
    }
  } catch (Exception e) {
    this.log.error("\n[URL]:  {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
    throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:31,代碼來源:WxMpPayServiceImpl.java

示例10: get

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
public static CloseableHttpClient get(SSLContext ssl, CookieStore cookieStore, boolean hostVerificationEnabled) {
    RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();

    HttpClientBuilder builder = HttpClients.custom().setSSLContext(ssl).setDefaultCookieStore(cookieStore)
            .setDefaultRequestConfig(defaultRequestConfig);
    if (hostVerificationEnabled) {
        builder.setSSLHostnameVerifier(new DefaultHostnameVerifier());
    } else {
        builder.setSSLHostnameVerifier(new NoopHostnameVerifier());
    }
    return builder.build();
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:13,代碼來源:HttpClient.java

示例11: initializeFactory

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
/**
 * Creates a new SSLConnectionSocketFactory with the behavior described in
 * {@link #getFactory(String)}. Instead of returning, this method registers
 * the factory instance to the <code>factoriesByHost<code> map, as well as
 * registering its <code>ExtraCertManager</code> to the
 * <code>certManagersByHost</code> map. The cert manager registration is
 * important in order to detect and purge trusted certificates on a per-host
 * basis.
 * 
 * @param host
 * @param burpExtender
 * @throws IOException
 * @throws GeneralSecurityException
 */
private static void initializeFactory(String host, BurpExtender burpExtender) throws IOException, GeneralSecurityException {
	// set up the certificate management
	File managedKeyStoreFile = getTrustStoreForHost(host);
	ExtraCertManager certManager = new SingleExtraCertManager(managedKeyStoreFile, "u9lwIfUpaN");

	// get the default hostname verifier that gets used by the modified one
	// and the invalid cert dialog
	HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();

	
	InvalidCertificateStrategy invalidCertStrat = new InvalidCertificateDialogStrategy(defaultHostnameVerifier, host, burpExtender);

	/*
	 * Set up a composite trust manager that uses the default trust manager
	 * before delegating to the "reloadable" trust manager that allows users
	 * to accept invalid certificates.
	 */
	List<X509TrustManager> trustManagersForComposite = new LinkedList<>();
	X509TrustManager systemTrustManager = getDefaultTrustManager();
	ReloadableX509TrustManager customTrustManager = new ReloadableX509TrustManager(certManager, invalidCertStrat);
	trustManagersForComposite.add(systemTrustManager);
	trustManagersForComposite.add(customTrustManager);
	X509TrustManager trustManager = new CompositeX509TrustManager(trustManagersForComposite);

	// setup the SSLContext using the custom trust manager
	SSLContext sslContext = SSLContext.getInstance("TLS");
	sslContext.init(null, new TrustManager[] { trustManager }, null);
	// the actual hostname verifier that will be used with the socket
	// factory
	Set<String> allowedHosts = new HashSet<>();
	allowedHosts.add(host);
	HostnameVerifier modifiedHostnameVerifier = new HostnameVerifierWithExceptions(defaultHostnameVerifier, allowedHosts);
	
	SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslContext, modifiedHostnameVerifier);
	// Register the `factory` and the `customTrustManager` under the given
	// `host`
	factoriesByHost.put(host, factory);
	customTrustByHost.put(host, customTrustManager);
}
 
開發者ID:codedx,項目名稱:burp-extension,代碼行數:54,代碼來源:SSLConnectionSocketFactoryFactory.java

示例12: createConnectionSocketFactory

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

示例13: getHostnameVerifier

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
/**
 * If SSL validation is disabled then return a HostnameVerifier that accepts
 * everything. Otherwise, return the override HostnameVerifier in the config
 * if specified, or return a new DefaultHostnameVerifier
 *
 * @param config
 */
public static HostnameVerifier getHostnameVerifier(ClientConfig config) {
  if (config.isDisableSSLValidation()) {
    return new NoopHostnameVerifier();
  }
  if (config.getOverrideHostnameVerifier() == null) {
    return new DefaultHostnameVerifier();
  } else {
    return config.getOverrideHostnameVerifier();
  }
}
 
開發者ID:cloudera,項目名稱:navigator-sdk,代碼行數:18,代碼來源:SSLUtils.java

示例14: initialize

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
private HttpAsyncClientBuilder initialize() {
    try {
        final PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(
            new DefaultConnectingIOReactor( IOReactorConfig.custom()
                .setConnectTimeout( connectTimeout )
                .setSoTimeout( readTimeout )
                .build() ),
            RegistryBuilder.<SchemeIOSessionStrategy>create()
                .register( "http", NoopIOSessionStrategy.INSTANCE )
                .register( "https",
                    new SSLIOSessionStrategy( certificateLocation != null ?
                        createSSLContext( certificateLocation, certificatePassword )
                        : SSLContexts.createDefault(),
                        split( System.getProperty( "https.protocols" ) ),
                        split( System.getProperty( "https.cipherSuites" ) ),
                        new DefaultHostnameVerifier( PublicSuffixMatcherLoader.getDefault() ) ) )
                .build() );

        connManager.setMaxTotal( maxConnTotal );
        connManager.setDefaultMaxPerRoute( maxConnPerRoute );

        return ( certificateLocation != null ?
            HttpAsyncClients.custom()
                .setSSLContext( createSSLContext( certificateLocation, certificatePassword ) )
            : HttpAsyncClients.custom() )
            .setMaxConnPerRoute( maxConnPerRoute )
            .setConnectionManager( connManager )
            .setMaxConnTotal( maxConnTotal )
            .setKeepAliveStrategy( DefaultConnectionKeepAliveStrategy.INSTANCE )
            .setDefaultRequestConfig( RequestConfig
                .custom()
                .setRedirectsEnabled( redirectsEnabled )
                .setCookieSpec( cookieSpec )
                .build() )
            .setDefaultCookieStore( basicCookieStore );
    } catch( IOReactorException e ) {
        throw new UncheckedIOException( e );
    }
}
 
開發者ID:oaplatform,項目名稱:oap,代碼行數:40,代碼來源:Client.java

示例15: BrickLinkClient

import org.apache.http.conn.ssl.DefaultHostnameVerifier; //導入依賴的package包/類
public BrickLinkClient(String consumerKey, String consumerSecret, String tokenValue, String tokenSecret) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
    super();
    consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    consumer.setTokenWithSecret(tokenValue, tokenSecret);
    SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, new DefaultHostnameVerifier());
    client = HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
 
開發者ID:kleini,項目名稱:bricklink,代碼行數:9,代碼來源:BrickLinkClient.java


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