use of io.dropwizard.client.ssl.TlsConfiguration in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomHostnameVerifierWhenTlsConfigurationSpecified.
@Test
public void canUseACustomHostnameVerifierWhenTlsConfigurationSpecified() throws Exception {
final TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setVerifyHostname(true);
configuration.setTlsConfiguration(tlsConfiguration);
final HostnameVerifier customVerifier = (s, sslSession) -> false;
final Registry<ConnectionSocketFactory> configuredRegistry;
configuredRegistry = builder.using(configuration).using(customVerifier).createConfiguredRegistry();
assertThat(configuredRegistry).isNotNull();
final SSLConnectionSocketFactory socketFactory = (SSLConnectionSocketFactory) configuredRegistry.lookup("https");
assertThat(socketFactory).isNotNull();
final Field hostnameVerifierField = FieldUtils.getField(SSLConnectionSocketFactory.class, "hostnameVerifier", true);
assertThat(hostnameVerifierField.get(socketFactory)).isSameAs(customVerifier);
}
use of io.dropwizard.client.ssl.TlsConfiguration in project dropwizard by dropwizard.
the class HttpClientBuilder method createConfiguredRegistry.
@VisibleForTesting
Registry<ConnectionSocketFactory> createConfiguredRegistry() {
if (registry != null) {
return registry;
}
TlsConfiguration tlsConfiguration = configuration.getTlsConfiguration();
if (tlsConfiguration == null && verifier != null) {
tlsConfiguration = new TlsConfiguration();
}
final SSLConnectionSocketFactory sslConnectionSocketFactory;
if (tlsConfiguration == null) {
sslConnectionSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
} else {
sslConnectionSocketFactory = new DropwizardSSLConnectionSocketFactory(tlsConfiguration, verifier).getSocketFactory();
}
return RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslConnectionSocketFactory).build();
}
use of io.dropwizard.client.ssl.TlsConfiguration in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseASystemHostnameVerifierByDefaultWhenTlsConfigurationSpecified.
@Test
public void canUseASystemHostnameVerifierByDefaultWhenTlsConfigurationSpecified() throws Exception {
final TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setVerifyHostname(true);
configuration.setTlsConfiguration(tlsConfiguration);
final Registry<ConnectionSocketFactory> configuredRegistry;
configuredRegistry = builder.using(configuration).createConfiguredRegistry();
assertThat(configuredRegistry).isNotNull();
final SSLConnectionSocketFactory socketFactory = (SSLConnectionSocketFactory) configuredRegistry.lookup("https");
assertThat(socketFactory).isNotNull();
final Field hostnameVerifierField = FieldUtils.getField(SSLConnectionSocketFactory.class, "hostnameVerifier", true);
assertThat(hostnameVerifierField.get(socketFactory)).isInstanceOf(HostnameVerifier.class);
}
Aggregations