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

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

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

HttpsURLConnection.getDefaultHostnameVerifier介绍

[英]Returns the default hostname verifier.
[中]返回默认主机名验证程序。

代码示例

代码示例来源:origin: knowm/XChange

@Override
 public boolean verify(String hostname, SSLSession session) {
  try {
   String principalName = session.getPeerPrincipal().getName();
   if (hostname.equals(requestHostname) && principalName.equals(certPrincipalName))
    return true;
  } catch (SSLPeerUnverifiedException e) {
  }
  return HttpsURLConnection.getDefaultHostnameVerifier().verify(hostname, session);
 }
};

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

HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
ClientConfig config = new DefaultClientConfig();
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, myTrustManager, null);
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx));
Client client = Client.create(config);

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

public boolean verify(String hostname, SSLSession session) {
  HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
  return hv.verify("localhost", session);

代码示例来源:origin: wildfly/wildfly

JwtValidator(Builder configuration) {
  this.issuers = checkNotNullParam("issuers", configuration.issuers);
  this.audiences = checkNotNullParam("audience", configuration.audience);
  this.defaultPublicKey = configuration.publicKey;
  this.namedKeys = configuration.namedKeys;
  if (configuration.sslContext != null) {
    this.jwkManager = new JwkManager(configuration.sslContext,
                    configuration.hostnameVerifier != null ? configuration.hostnameVerifier : HttpsURLConnection.getDefaultHostnameVerifier(),
                    configuration.updateTimeout);
  }
  else {
    log.tokenRealmJwtNoSSLIgnoringJku();
    this.jwkManager = null;
  }
  if (defaultPublicKey == null && jwkManager == null && namedKeys.isEmpty()) {
    log.tokenRealmJwtWarnNoPublicKeyIgnoringSignatureCheck();
  }
  if (issuers.isEmpty()) {
    log.tokenRealmJwtWarnNoIssuerIgnoringIssuerCheck();
  }
  if (audiences.isEmpty()) {
    log.tokenRealmJwtWarnNoAudienceIgnoringAudienceCheck();
  }
}

代码示例来源:origin: neo4j/neo4j

private static Client createClient() throws Exception
  {
    HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    ClientConfig config = new DefaultClientConfig();
    SSLContext ctx = SSLContext.getInstance( "TLS" );
    ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null );
    config.getProperties().put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) );
    return Client.create( config );
  }
}

代码示例来源:origin: neo4j/neo4j

/**
 * Create a Jersey HTTP client that is able to talk HTTPS and trusts all certificates.
 *
 * @return new client.
 */
private static Client createClient()
{
  try
  {
    HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    ClientConfig config = new DefaultClientConfig();
    SSLContext ctx = SSLContext.getInstance( "TLS" );
    ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null );
    Map<String,Object> properties = config.getProperties();
    properties.put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) );
    properties.put( PROPERTY_FOLLOW_REDIRECTS, false );
    return Client.create( config );
  }
  catch ( Exception e )
  {
    throw new RuntimeException( e );
  }
}

代码示例来源:origin: wendux/DSBridge-Android

@Override
  public boolean verify(String hostname, SSLSession session) {
    //return "api.dtworkroom.com".equals(hostname);
    HostnameVerifier hv=HttpsURLConnection.getDefaultHostnameVerifier();
    return hv.verify("*.dtworkroom.com",session);
  }
});

代码示例来源:origin: i2p/i2p.i2p

if (SystemVersion.isAndroid()) {
  hv = HttpsURLConnection.getDefaultHostnameVerifier();
} else {

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

public static HostnameVerifier getHostnameVerifier(TLSClientParameters tlsClientParameters) {
  HostnameVerifier verifier;
  if (tlsClientParameters.getHostnameVerifier() != null) {
    verifier = tlsClientParameters.getHostnameVerifier();
  } else if (tlsClientParameters.isUseHttpsURLConnectionDefaultHostnameVerifier()) {
    verifier = HttpsURLConnection.getDefaultHostnameVerifier();
  } else if (tlsClientParameters.isDisableCNCheck()) {
    verifier = new AllowAllHostnameVerifier();
  } else {
    verifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault());
  }
  return verifier;
}

代码示例来源: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: apereo/java-cas-client

private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    final Object internalHostNameVerifier = in.readObject();
    if (internalHostNameVerifier == null) {
      this.hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    } else {
      this.hostnameVerifier = (HostnameVerifier) internalHostNameVerifier;
    }

    this.sslConfiguration = (Properties) in.readObject();
  }
}

代码示例来源:origin: org.xipki.tk/security

public void shutdown() {
  if (meAsDefaultHostnameVerifier
      && HttpsURLConnection.getDefaultHostnameVerifier() == this) {
    LOG.info("Unregister me as DefaultHostnameVerifier, and reuse the old one {}",
        oldHostnameVerifier);
    HttpsURLConnection.setDefaultHostnameVerifier(oldHostnameVerifier);
    meAsDefaultHostnameVerifier = false;
  }
}

代码示例来源:origin: apereo/java-cas-client

private void writeObject(final ObjectOutputStream out) throws IOException {
  if (this.hostnameVerifier == HttpsURLConnection.getDefaultHostnameVerifier()) {
    out.writeObject(null);
  } else {
    out.writeObject(this.hostnameVerifier);
  }
  out.writeObject(this.sslConfiguration);
}

代码示例来源:origin: org.xipki.tk/security

public void init() {
  LOG.info("enabled: {}", enabled);
  LOG.info("trustAll: {}", trustAll);
  if (enabled) {
    oldHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    LOG.info("Register me as DefaultHostnameVerifier, and backup the old one {}",
        oldHostnameVerifier);
    HttpsURLConnection.setDefaultHostnameVerifier(this);
    meAsDefaultHostnameVerifier = true;
  }
}

代码示例来源:origin: xipki/xipki

public static void init() throws GeneralSecurityException {
 System.err.println("***** ONLY FOR TEST, DO NOT USE IT IN PRODUCTION ENVIRONMENT ******");
 TrustManager[] trustManagers = {new InternX509TrustManager()};
 SSLContext sc = SSLContext.getInstance("SSL");
 sc.init(null, trustManagers, new SecureRandom());
 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
 oldHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
 LOG.info("Register me as DefaultHostnameVerifier, and backup the old one {}",
   oldHostnameVerifier);
 HttpsURLConnection.setDefaultHostnameVerifier(SdkHostnameVerifier.INSTANCE);
}

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

client.setHostnameVerifier(new HostnameVerifier() {
     @Override
     public boolean verify(String hostname, SSLSession session) {
       //return true;
       HostnameVerifier hv =
           HttpsURLConnection.getDefaultHostnameVerifier();
       return hv.verify("ipage.com", session);
     }
   });

代码示例来源:origin: org.knowm.xchange/xchange-core

@Override
 public boolean verify(String hostname, SSLSession session) {
  try {
   String principalName = session.getPeerPrincipal().getName();
   if (hostname.equals(requestHostname) && principalName.equals(certPrincipalName))
    return true;
  } catch (SSLPeerUnverifiedException e) {
  }
  return HttpsURLConnection.getDefaultHostnameVerifier().verify(hostname, session);
 }
};

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

HostnameVerifier hostnameVerifier = new HostnameVerifier() {
  @Override
  public boolean verify(String hostname, SSLSession session) {
    HostnameVerifier hv =
      HttpsURLConnection.getDefaultHostnameVerifier();
    return hv.verify("localhost", session);
  }
};

代码示例来源:origin: apache/attic-polygene-java

@BeforeClass
public static void beforeSecureClass()
  throws IOException, GeneralSecurityException
{
  defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
  defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
  HttpsURLConnection.setDefaultHostnameVerifier( ( string, ssls ) -> true );
  HttpsURLConnection.setDefaultSSLSocketFactory( buildTrustSSLContext().getSocketFactory() );
}

代码示例来源:origin: apache/cxf

public static HostnameVerifier getHostnameVerifier(TLSClientParameters tlsClientParameters) {
  HostnameVerifier verifier;
  if (tlsClientParameters.getHostnameVerifier() != null) {
    verifier = tlsClientParameters.getHostnameVerifier();
  } else if (tlsClientParameters.isUseHttpsURLConnectionDefaultHostnameVerifier()) {
    verifier = HttpsURLConnection.getDefaultHostnameVerifier();
  } else if (tlsClientParameters.isDisableCNCheck()) {
    verifier = new AllowAllHostnameVerifier();
  } else {
    verifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault());
  }
  return verifier;
}

相关文章

HttpsURLConnection类方法