Search in sources :

Example 6 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.

the class AbstractReactiveWebServerFactoryTests method sslWantsClientAuthenticationSucceedsWithClientCertificate.

@Test
void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(Ssl.ClientAuth.WANT);
    ssl.setKeyStore("classpath:test.jks");
    ssl.setKeyPassword("password");
    ssl.setKeyStorePassword("secret");
    ssl.setTrustStore("classpath:test.jks");
    testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector("test.jks", "password"));
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 7 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.

the class AbstractReactiveWebServerFactoryTests method sslWithValidAlias.

@Test
void sslWithValidAlias() {
    String keyStore = "classpath:test.jks";
    String keyPassword = "password";
    AbstractReactiveWebServerFactory factory = getFactory();
    Ssl ssl = new Ssl();
    ssl.setKeyStore(keyStore);
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword(keyPassword);
    ssl.setKeyAlias("test-alias");
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(new EchoHandler());
    this.webServer.start();
    ReactorClientHttpConnector connector = buildTrustAllSslConnector();
    WebClient client = WebClient.builder().baseUrl("https://localhost:" + this.webServer.getPort()).clientConnector(connector).build();
    Mono<String> result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve().bodyToMono(String.class);
    StepVerifier.setDefaultTimeout(Duration.ofSeconds(30));
    StepVerifier.create(result).expectNext("Hello World").verifyComplete();
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector) Test(org.junit.jupiter.api.Test)

Example 8 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.

the class ServletWebServerFactoryCustomizerTests method testCustomizeSsl.

@Test
void testCustomizeSsl() {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    Ssl ssl = mock(Ssl.class);
    this.properties.setSsl(ssl);
    this.customizer.customize(factory);
    then(factory).should().setSsl(ssl);
}
Also used : ConfigurableServletWebServerFactory(cn.taketoday.framework.web.servlet.server.ConfigurableServletWebServerFactory) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 9 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.

the class AbstractServletWebServerFactoryTests method getSsl.

private Ssl getSsl(String cert, String privateKey) {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(ClientAuth.NEED);
    ssl.setCertificate(cert);
    ssl.setCertificatePrivateKey(privateKey);
    ssl.setTrustCertificate(cert);
    ssl.setKeyStorePassword("secret");
    return ssl;
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl)

Example 10 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.

the class JettyServletWebServerFactoryTests method specificIPAddressWithSslIsNotReverseResolved.

@Test
void specificIPAddressWithSslIsNotReverseResolved() throws Exception {
    JettyServletWebServerFactory factory = getFactory();
    InetAddress localhost = InetAddress.getLocalHost();
    factory.setAddress(InetAddress.getByAddress(localhost.getAddress()));
    Ssl ssl = new Ssl();
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword("password");
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    Connector connector = ((JettyWebServer) this.webServer).getServer().getConnectors()[0];
    Assertions.assertThat(((ServerConnector) connector).getHost()).isEqualTo(localhost.getHostAddress());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InetAddress(java.net.InetAddress) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Aggregations

Ssl (cn.taketoday.framework.web.server.Ssl)72 Test (org.junit.jupiter.api.Test)58 Connector (org.apache.catalina.connector.Connector)12 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SslStoreProvider (cn.taketoday.framework.web.server.SslStoreProvider)8 NoSuchProviderException (java.security.NoSuchProviderException)8 ServletRegistrationBean (cn.taketoday.framework.web.servlet.ServletRegistrationBean)6 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)6 ReactorClientHttpConnector (cn.taketoday.http.client.reactive.ReactorClientHttpConnector)6 ExampleServlet (cn.taketoday.test.web.servlet.ExampleServlet)6 WebClient (cn.taketoday.web.reactive.function.client.WebClient)6 KeyStore (java.security.KeyStore)6 HttpClient (org.apache.http.client.HttpClient)6 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)6 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)6 WebServerException (cn.taketoday.framework.web.server.WebServerException)4 InetAddress (java.net.InetAddress)4 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)4 SSLHostConfigCertificate (org.apache.tomcat.util.net.SSLHostConfigCertificate)4