|
|
@ -404,7 +404,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
addTestTxtFile(factory);
|
|
|
|
addTestTxtFile(factory);
|
|
|
|
factory.setSsl(getSsl(ClientAuth.NEED, null, "classpath:test.p12",
|
|
|
|
factory.setSsl(getSsl(ClientAuth.NEED, null, "classpath:test.p12",
|
|
|
|
"classpath:test.p12"));
|
|
|
|
"classpath:test.p12", null, null));
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
this.container.start();
|
|
|
|
this.container.start();
|
|
|
|
KeyStore keyStore = KeyStore.getInstance("pkcs12");
|
|
|
|
KeyStore keyStore = KeyStore.getInstance("pkcs12");
|
|
|
@ -428,7 +428,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
addTestTxtFile(factory);
|
|
|
|
addTestTxtFile(factory);
|
|
|
|
factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks",
|
|
|
|
factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks",
|
|
|
|
"classpath:test.jks"));
|
|
|
|
"classpath:test.jks", null, null));
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
this.container.start();
|
|
|
|
this.container.start();
|
|
|
|
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
|
|
|
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
|
|
@ -526,11 +526,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) {
|
|
|
|
private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) {
|
|
|
|
return getSsl(clientAuth, keyPassword, keyStore, null);
|
|
|
|
return getSsl(clientAuth, keyPassword, keyStore, null, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore,
|
|
|
|
private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore,
|
|
|
|
String trustStore) {
|
|
|
|
String trustStore, String[] protocols, String[] ciphers) {
|
|
|
|
Ssl ssl = new Ssl();
|
|
|
|
Ssl ssl = new Ssl();
|
|
|
|
ssl.setClientAuth(clientAuth);
|
|
|
|
ssl.setClientAuth(clientAuth);
|
|
|
|
if (keyPassword != null) {
|
|
|
|
if (keyPassword != null) {
|
|
|
@ -546,9 +546,42 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
ssl.setTrustStorePassword("secret");
|
|
|
|
ssl.setTrustStorePassword("secret");
|
|
|
|
ssl.setTrustStoreType(getStoreType(trustStore));
|
|
|
|
ssl.setTrustStoreType(getStoreType(trustStore));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ciphers != null) {
|
|
|
|
|
|
|
|
ssl.setCiphers(ciphers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (protocols != null) {
|
|
|
|
|
|
|
|
ssl.setProtocols(protocols);
|
|
|
|
|
|
|
|
}
|
|
|
|
return ssl;
|
|
|
|
return ssl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @see <a
|
|
|
|
|
|
|
|
* href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html#SunJSSEProvider">
|
|
|
|
|
|
|
|
* SunJSSE supported Cipher Suites</a>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void testRestrictedSSLProtocolsAndCipherSuites(String[] protocols,
|
|
|
|
|
|
|
|
String[] ciphers) throws Exception {
|
|
|
|
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
|
|
|
|
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks", null,
|
|
|
|
|
|
|
|
protocols, ciphers));
|
|
|
|
|
|
|
|
this.container = factory.getEmbeddedServletContainer(
|
|
|
|
|
|
|
|
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
|
|
|
|
|
|
|
this.container.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
|
|
|
|
|
|
|
new SSLContextBuilder()
|
|
|
|
|
|
|
|
.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
|
|
|
|
|
|
|
|
httpClient);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory))
|
|
|
|
|
|
|
|
.contains("scheme=https");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getStoreType(String keyStore) {
|
|
|
|
private String getStoreType(String keyStore) {
|
|
|
|
return (keyStore.endsWith(".p12") ? "pkcs12" : null);
|
|
|
|
return (keyStore.endsWith(".p12") ? "pkcs12" : null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|