Search in sources :

Example 56 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method sslWantsClientAuthenticationSucceedsWithoutClientCertificate.

@Test
void sslWantsClientAuthenticationSucceedsWithoutClientCertificate() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    addTestTxtFile(factory);
    factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks"));
    this.webServer = factory.getWebServer();
    this.webServer.start();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
    HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test");
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)56 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)41 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)28 SSLContext (javax.net.ssl.SSLContext)20 IOException (java.io.IOException)15 HttpClient (org.apache.http.client.HttpClient)15 KeyStore (java.security.KeyStore)14 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)14 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)13 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 File (java.io.File)9 SSLContextBuilder (org.apache.http.conn.ssl.SSLContextBuilder)9 KeyManagementException (java.security.KeyManagementException)8 KeyStoreException (java.security.KeyStoreException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 FileInputStream (java.io.FileInputStream)6 RequestConfig (org.apache.http.client.config.RequestConfig)6 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)6 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)6