use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sslSessionTracking.
@Test
void sslSessionTracking() {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = new Ssl();
ssl.setEnabled(true);
ssl.setKeyStore("src/test/resources/test.jks");
ssl.setKeyPassword("password");
factory.setSsl(ssl);
factory.getSession().setTrackingModes(EnumSet.of(SessionTrackingMode.SSL));
AtomicReference<ServletContext> contextReference = new AtomicReference<>();
this.webServer = factory.getWebServer(contextReference::set);
assertThat(contextReference.get().getEffectiveSessionTrackingModes()).isEqualTo(EnumSet.of(jakarta.servlet.SessionTrackingMode.SSL));
}
use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sslWithCustomSslStoreProvider.
@Test
void sslWithCustomSslStoreProvider() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
addTestTxtFile(factory);
Ssl ssl = new Ssl();
ssl.setClientAuth(ClientAuth.NEED);
ssl.setKeyPassword("password");
factory.setSsl(ssl);
SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class);
given(sslStoreProvider.getKeyStore()).willReturn(loadStore());
given(sslStoreProvider.getTrustStore()).willReturn(loadStore());
factory.setSslStoreProvider(sslStoreProvider);
this.webServer = factory.getWebServer();
this.webServer.start();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
loadStore(keyStore, new FileSystemResource("src/test/resources/test.jks"));
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).loadKeyMaterial(keyStore, "password".toCharArray()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test");
then(sslStoreProvider).should(atLeastOnce()).getKeyStore();
then(sslStoreProvider).should(atLeastOnce()).getTrustStore();
}
use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sslKeyAlias.
@Test
void sslKeyAlias() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = getSsl(null, "password", "test-alias", "src/test/resources/test.jks");
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello");
this.webServer = factory.getWebServer(registration);
this.webServer.start();
TrustStrategy trustStrategy = new SerialNumberValidatingTrustSelfSignedStrategy("3a3aaec8");
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext)).build();
String response = getResponse(getLocalUrl("https", "/hello"), new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response).contains("scheme=https");
}
use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method sslWithPemCertificates.
@Test
void sslWithPemCertificates() throws Exception {
Ssl ssl = new Ssl();
ssl.setClientAuth(Ssl.ClientAuth.NEED);
ssl.setCertificate("classpath:test-cert.pem");
ssl.setCertificatePrivateKey("classpath:test-key.pem");
ssl.setTrustCertificate("classpath:test-cert.pem");
ssl.setKeyStorePassword("secret");
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector("test.p12", "secret"));
}
use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method sslNeedsClientAuthenticationFailsWithoutClientCertificate.
@Test
void sslNeedsClientAuthenticationFailsWithoutClientCertificate() {
Ssl ssl = new Ssl();
ssl.setClientAuth(Ssl.ClientAuth.NEED);
ssl.setKeyStore("classpath:test.jks");
ssl.setKeyStorePassword("secret");
ssl.setKeyPassword("password");
ssl.setTrustStore("classpath:test.jks");
testClientAuthFailure(ssl, buildTrustAllSslConnector());
}
Aggregations