Browse Source

Polishing: use passed-in ssl instance rather than calling getSsl()

pull/1297/head
Andy Wilkinson 12 years ago
parent
commit
7bb1f7eb77
  1. 39
      spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java
  2. 34
      spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java

39
spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java

@ -69,7 +69,7 @@ import org.springframework.util.StringUtils; @@ -69,7 +69,7 @@ import org.springframework.util.StringUtils;
* @see JettyEmbeddedServletContainer
*/
public class JettyEmbeddedServletContainerFactory extends
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
private List<Configuration> configurations = new ArrayList<Configuration>();
@ -130,47 +130,46 @@ public class JettyEmbeddedServletContainerFactory extends @@ -130,47 +130,46 @@ public class JettyEmbeddedServletContainerFactory extends
}
protected void configureSslContextFactory(SslContextFactory sslContextFactory, Ssl ssl) {
sslContextFactory.setProtocol(getSsl().getProtocol());
if (getSsl().getClientAuth() == ClientAuth.NEED) {
sslContextFactory.setProtocol(ssl.getProtocol());
if (ssl.getClientAuth() == ClientAuth.NEED) {
sslContextFactory.setNeedClientAuth(true);
sslContextFactory.setWantClientAuth(true);
}
else if (getSsl().getClientAuth() == ClientAuth.WANT) {
else if (ssl.getClientAuth() == ClientAuth.WANT) {
sslContextFactory.setWantClientAuth(true);
}
if (getSsl().getKeyStorePassword() != null) {
sslContextFactory.setKeyStorePassword(getSsl().getKeyStorePassword());
if (ssl.getKeyStorePassword() != null) {
sslContextFactory.setKeyStorePassword(ssl.getKeyStorePassword());
}
if (getSsl().getKeyPassword() != null) {
sslContextFactory.setKeyManagerPassword(getSsl().getKeyPassword());
if (ssl.getKeyPassword() != null) {
sslContextFactory.setKeyManagerPassword(ssl.getKeyPassword());
}
sslContextFactory.setCertAlias(getSsl().getKeyAlias());
sslContextFactory.setCertAlias(ssl.getKeyAlias());
try {
sslContextFactory.setKeyStoreResource(Resource.newResource(ResourceUtils
.getURL(getSsl().getKeyStore())));
.getURL(ssl.getKeyStore())));
}
catch (IOException e) {
throw new EmbeddedServletContainerException("Could not find key store '"
+ getSsl().getKeyStore() + "'", e);
+ ssl.getKeyStore() + "'", e);
}
if (getSsl().getCiphers() != null) {
sslContextFactory.setIncludeCipherSuites(getSsl().getCiphers());
if (ssl.getCiphers() != null) {
sslContextFactory.setIncludeCipherSuites(ssl.getCiphers());
}
if (getSsl().getTrustStorePassword() != null) {
sslContextFactory.setTrustStorePassword(getSsl().getTrustStorePassword());
if (ssl.getTrustStorePassword() != null) {
sslContextFactory.setTrustStorePassword(ssl.getTrustStorePassword());
}
if (getSsl().getTrustStore() != null) {
if (ssl.getTrustStore() != null) {
try {
sslContextFactory.setTrustStoreResource(Resource
.newResource(ResourceUtils.getURL(getSsl().getTrustStore())));
.newResource(ResourceUtils.getURL(ssl.getTrustStore())));
}
catch (IOException e) {
throw new EmbeddedServletContainerException(
"Could not find trust store '" + getSsl().getTrustStore() + "'",
e);
"Could not find trust store '" + ssl.getTrustStore() + "'", e);
}
}
}
@ -203,7 +202,7 @@ public class JettyEmbeddedServletContainerFactory extends @@ -203,7 +202,7 @@ public class JettyEmbeddedServletContainerFactory extends
initializersToUse);
context.setConfigurations(configurations);
context.getSessionHandler().getSessionManager()
.setMaxInactiveInterval(getSessionTimeout());
.setMaxInactiveInterval(getSessionTimeout());
postProcessWebAppContext(context);
}

34
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java

@ -79,7 +79,7 @@ import org.springframework.util.StringUtils; @@ -79,7 +79,7 @@ import org.springframework.util.StringUtils;
* @see TomcatEmbeddedServletContainer
*/
public class TomcatEmbeddedServletContainerFactory extends
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
private static final String DEFAULT_PROTOCOL = "org.apache.coyote.http11.Http11NioProtocol";
@ -226,7 +226,7 @@ public class TomcatEmbeddedServletContainerFactory extends @@ -226,7 +226,7 @@ public class TomcatEmbeddedServletContainerFactory extends
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
if (getAddress() != null) {
((AbstractProtocol) connector.getProtocolHandler())
.setAddress(getAddress());
.setAddress(getAddress());
}
}
if (getUriEncoding() != null) {
@ -258,40 +258,40 @@ public class TomcatEmbeddedServletContainerFactory extends @@ -258,40 +258,40 @@ public class TomcatEmbeddedServletContainerFactory extends
protected void configureJsseProtocol(AbstractHttp11JsseProtocol jsseProtocol, Ssl ssl) {
jsseProtocol.setSSLEnabled(true);
jsseProtocol.setSslProtocol(getSsl().getProtocol());
if (getSsl().getClientAuth() == ClientAuth.NEED) {
jsseProtocol.setSslProtocol(ssl.getProtocol());
if (ssl.getClientAuth() == ClientAuth.NEED) {
jsseProtocol.setClientAuth(Boolean.TRUE.toString());
}
else if (getSsl().getClientAuth() == ClientAuth.WANT) {
else if (ssl.getClientAuth() == ClientAuth.WANT) {
jsseProtocol.setClientAuth("want");
}
jsseProtocol.setKeystorePass(getSsl().getKeyStorePassword());
jsseProtocol.setKeyPass(getSsl().getKeyPassword());
jsseProtocol.setKeyAlias(getSsl().getKeyAlias());
jsseProtocol.setKeystorePass(ssl.getKeyStorePassword());
jsseProtocol.setKeyPass(ssl.getKeyPassword());
jsseProtocol.setKeyAlias(ssl.getKeyAlias());
try {
jsseProtocol.setKeystoreFile(ResourceUtils.getFile(getSsl().getKeyStore())
jsseProtocol.setKeystoreFile(ResourceUtils.getFile(ssl.getKeyStore())
.getAbsolutePath());
}
catch (FileNotFoundException e) {
throw new EmbeddedServletContainerException("Could not find key store "
+ getSsl().getKeyStore(), e);
+ ssl.getKeyStore(), e);
}
jsseProtocol.setCiphers(StringUtils.arrayToCommaDelimitedString(getSsl()
.getCiphers()));
jsseProtocol
.setCiphers(StringUtils.arrayToCommaDelimitedString(ssl.getCiphers()));
if (getSsl().getTrustStore() != null) {
if (ssl.getTrustStore() != null) {
try {
jsseProtocol.setTruststoreFile(ResourceUtils.getFile(
getSsl().getTrustStore()).getAbsolutePath());
jsseProtocol.setTruststoreFile(ResourceUtils.getFile(ssl.getTrustStore())
.getAbsolutePath());
}
catch (FileNotFoundException e) {
throw new EmbeddedServletContainerException("Could not find trust store "
+ getSsl().getTrustStore(), e);
+ ssl.getTrustStore(), e);
}
}
jsseProtocol.setTruststorePass(getSsl().getTrustStorePassword());
jsseProtocol.setTruststorePass(ssl.getTrustStorePassword());
}
/**

Loading…
Cancel
Save