javax.net.ssl.HttpsURLConnection.getHostnameVerifier()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中javax.net.ssl.HttpsURLConnection.getHostnameVerifier()方法的一些代码示例,展示了HttpsURLConnection.getHostnameVerifier()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.getHostnameVerifier()方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:getHostnameVerifier

HttpsURLConnection.getHostnameVerifier介绍

[英]Returns the hostname verifier used by this instance.
[中]返回此实例使用的主机名验证程序。

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Test
public void trustAllHosts() throws Exception {
 HttpsURLConnection connection = newHttpsConnection();
 HttpsTrust.INSTANCE.trust(connection);
 assertThat(connection.getHostnameVerifier()).isNotNull();
 assertThat(connection.getHostnameVerifier().verify("foo", null)).isTrue();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void singleHostnameVerifier() throws Exception {
 HttpsURLConnection connection1 = newHttpsConnection();
 HttpsTrust.INSTANCE.trust(connection1);
 HttpsURLConnection connection2 = newHttpsConnection();
 HttpsTrust.INSTANCE.trust(connection2);
 assertThat(connection1.getHostnameVerifier()).isSameAs(connection2.getHostnameVerifier());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testConfigureConnection() throws MalformedURLException, URISyntaxException {
  final Map<String, String> headers = new HashMap<String, String>();
  final HttpRequest request = new HttpRequest("POST", new URI("https://www.test.com"),
      headers,
      null);
  final HttpsURLConnection conn = new MockHttpURLConnection(new URL("https://www.test.com"));
  client.configureConnection(request, conn);
  assertEquals(conn.getConnectTimeout(), conf.getConnectionTimeout());
  assertEquals(conn.getReadTimeout(), conf.getSocketTimeout());
  assertSame(conn.getHostnameVerifier(), HttpsURLConnection.getDefaultHostnameVerifier());
  assertFalse(conn.getInstanceFollowRedirects());
  assertFalse("disable cache", conn.getUseCaches());
}

代码示例来源:origin: org.apache.wink/wink-client

private HostnameVerifier setupHostnameVerificationBypass(HttpsURLConnection connection) {
  HttpsURLConnection https = ((HttpsURLConnection)connection);
  HostnameVerifier hv = https.getHostnameVerifier();
  https.setHostnameVerifier(new HostnameVerifier() {
    public boolean verify(String urlHostName, SSLSession session) {
      logger
        .trace("Bypassing hostname verification: URL host is {}, SSLSession host is {}", urlHostName, //$NON-NLS-1$
            session.getPeerHost());
      return true;
    }
  });
  return hv;
}

代码示例来源:origin: stackoverflow.com

public URLConnection getTolerantClient(URL url) throws IOException {
  URLConnection conn = url.openConnection();
  if (!(conn instanceof HttpsURLConnection)) {
    /* not an https:// URL, nothing to do */
    return conn;
  }
  HttpsURLConnection httpsconn = (HttpsURLConnection)conn;
  final HostnameVerifier delegate = httpsconn.getHostnameVerifier();
  if(!(delegate instanceof MyVerifier)) {
    httpsconn.setHostnameVerifier(new MyVerifier(delegate));
  }
  return conn;
}

代码示例来源:origin: org.onap.aaf.cadi/cadi-core

public void setSocketFactoryOn(HttpsURLConnection hsuc) {
  hsuc.setSSLSocketFactory(scf);
  if(maskHV!=null && !maskHV.equals(hsuc.getHostnameVerifier())) {
    hsuc.setHostnameVerifier(maskHV);
  }
}

代码示例来源:origin: AgNO3/jcifs-ng

SSLSocketFactory ssf = null;
if ( this.connection instanceof HttpsURLConnection ) {
  hv = ( (HttpsURLConnection) this.connection ).getHostnameVerifier();
  ssf = ( (HttpsURLConnection) this.connection ).getSSLSocketFactory();

代码示例来源:origin: org.codelibs/jcifs

SSLSocketFactory ssf = null;
if ( this.connection instanceof HttpsURLConnection ) {
  hv = ( (HttpsURLConnection) this.connection ).getHostnameVerifier();
  ssf = ( (HttpsURLConnection) this.connection ).getSSLSocketFactory();

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testConnectionConfigurator() throws Exception {
 Configuration conf = createConfiguration(false, true);
 conf.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "STRICT_IE6");
 SSLFactory sslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
 try {
  sslFactory.init();
  HttpsURLConnection sslConn =
    (HttpsURLConnection) new URL("https://foo").openConnection();
  Assert.assertNotSame("STRICT_IE6",
             sslConn.getHostnameVerifier().toString());
  sslFactory.configure(sslConn);
  Assert.assertEquals("STRICT_IE6",
            sslConn.getHostnameVerifier().toString());
 } finally {
  sslFactory.destroy();
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test
public void testConnectionConfigurator() throws Exception {
 Configuration conf = createConfiguration(false, true);
 conf.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "STRICT_IE6");
 SSLFactory sslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
 try {
  sslFactory.init();
  HttpsURLConnection sslConn =
    (HttpsURLConnection) new URL("https://foo").openConnection();
  Assert.assertNotSame("STRICT_IE6",
             sslConn.getHostnameVerifier().toString());
  sslFactory.configure(sslConn);
  Assert.assertEquals("STRICT_IE6",
            sslConn.getHostnameVerifier().toString());
 } finally {
  sslFactory.destroy();
 }
}

代码示例来源:origin: kiegroup/droolsjbpm-integration

/**
 * Verify single hostname verifier is created across all calls
 */
@Test
public void singleVerifier() {
  KieServerHttpRequest request1 = getRequest("https://localhost").trustAllHosts();
  KieServerHttpRequest request2 = getRequest("https://localhost").trustAllHosts();
  assertNotNull(((HttpsURLConnection) request1.getConnection()).getHostnameVerifier());
  assertNotNull(((HttpsURLConnection) request2.getConnection()).getHostnameVerifier());
  assertEquals(((HttpsURLConnection) request1.getConnection()).getHostnameVerifier(),
      ((HttpsURLConnection) request2.getConnection()).getHostnameVerifier());
}

代码示例来源:origin: kiegroup/droolsjbpm-integration

/**
 * Verify hostname verifier is set and accepts all
 */
@Test
public void verifierAccepts() {
  KieServerHttpRequest request = getRequest("https://localhost");
  HttpsURLConnection connection = (HttpsURLConnection) request.getConnection();
  request.trustAllHosts();
  assertNotNull(connection.getHostnameVerifier());
  assertTrue(connection.getHostnameVerifier().verify(null, null));
}

相关文章

HttpsURLConnection类方法