Commit 7bb1f7eb authored by Andy Wilkinson's avatar Andy Wilkinson

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

parent 0960908b
...@@ -69,7 +69,7 @@ import org.springframework.util.StringUtils; ...@@ -69,7 +69,7 @@ import org.springframework.util.StringUtils;
* @see JettyEmbeddedServletContainer * @see JettyEmbeddedServletContainer
*/ */
public class JettyEmbeddedServletContainerFactory extends public class JettyEmbeddedServletContainerFactory extends
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
private List<Configuration> configurations = new ArrayList<Configuration>(); 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) { protected void configureSslContextFactory(SslContextFactory sslContextFactory, Ssl ssl) {
sslContextFactory.setProtocol(getSsl().getProtocol()); sslContextFactory.setProtocol(ssl.getProtocol());
if (getSsl().getClientAuth() == ClientAuth.NEED) { if (ssl.getClientAuth() == ClientAuth.NEED) {
sslContextFactory.setNeedClientAuth(true); sslContextFactory.setNeedClientAuth(true);
sslContextFactory.setWantClientAuth(true); sslContextFactory.setWantClientAuth(true);
} }
else if (getSsl().getClientAuth() == ClientAuth.WANT) { else if (ssl.getClientAuth() == ClientAuth.WANT) {
sslContextFactory.setWantClientAuth(true); sslContextFactory.setWantClientAuth(true);
} }
if (getSsl().getKeyStorePassword() != null) { if (ssl.getKeyStorePassword() != null) {
sslContextFactory.setKeyStorePassword(getSsl().getKeyStorePassword()); sslContextFactory.setKeyStorePassword(ssl.getKeyStorePassword());
} }
if (getSsl().getKeyPassword() != null) { if (ssl.getKeyPassword() != null) {
sslContextFactory.setKeyManagerPassword(getSsl().getKeyPassword()); sslContextFactory.setKeyManagerPassword(ssl.getKeyPassword());
} }
sslContextFactory.setCertAlias(getSsl().getKeyAlias()); sslContextFactory.setCertAlias(ssl.getKeyAlias());
try { try {
sslContextFactory.setKeyStoreResource(Resource.newResource(ResourceUtils sslContextFactory.setKeyStoreResource(Resource.newResource(ResourceUtils
.getURL(getSsl().getKeyStore()))); .getURL(ssl.getKeyStore())));
} }
catch (IOException e) { catch (IOException e) {
throw new EmbeddedServletContainerException("Could not find key store '" throw new EmbeddedServletContainerException("Could not find key store '"
+ getSsl().getKeyStore() + "'", e); + ssl.getKeyStore() + "'", e);
} }
if (getSsl().getCiphers() != null) { if (ssl.getCiphers() != null) {
sslContextFactory.setIncludeCipherSuites(getSsl().getCiphers()); sslContextFactory.setIncludeCipherSuites(ssl.getCiphers());
} }
if (getSsl().getTrustStorePassword() != null) { if (ssl.getTrustStorePassword() != null) {
sslContextFactory.setTrustStorePassword(getSsl().getTrustStorePassword()); sslContextFactory.setTrustStorePassword(ssl.getTrustStorePassword());
} }
if (getSsl().getTrustStore() != null) { if (ssl.getTrustStore() != null) {
try { try {
sslContextFactory.setTrustStoreResource(Resource sslContextFactory.setTrustStoreResource(Resource
.newResource(ResourceUtils.getURL(getSsl().getTrustStore()))); .newResource(ResourceUtils.getURL(ssl.getTrustStore())));
} }
catch (IOException e) { catch (IOException e) {
throw new EmbeddedServletContainerException( throw new EmbeddedServletContainerException(
"Could not find trust store '" + getSsl().getTrustStore() + "'", "Could not find trust store '" + ssl.getTrustStore() + "'", e);
e);
} }
} }
} }
...@@ -203,7 +202,7 @@ public class JettyEmbeddedServletContainerFactory extends ...@@ -203,7 +202,7 @@ public class JettyEmbeddedServletContainerFactory extends
initializersToUse); initializersToUse);
context.setConfigurations(configurations); context.setConfigurations(configurations);
context.getSessionHandler().getSessionManager() context.getSessionHandler().getSessionManager()
.setMaxInactiveInterval(getSessionTimeout()); .setMaxInactiveInterval(getSessionTimeout());
postProcessWebAppContext(context); postProcessWebAppContext(context);
} }
......
...@@ -79,7 +79,7 @@ import org.springframework.util.StringUtils; ...@@ -79,7 +79,7 @@ import org.springframework.util.StringUtils;
* @see TomcatEmbeddedServletContainer * @see TomcatEmbeddedServletContainer
*/ */
public class TomcatEmbeddedServletContainerFactory extends public class TomcatEmbeddedServletContainerFactory extends
AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
private static final String DEFAULT_PROTOCOL = "org.apache.coyote.http11.Http11NioProtocol"; 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 (connector.getProtocolHandler() instanceof AbstractProtocol) {
if (getAddress() != null) { if (getAddress() != null) {
((AbstractProtocol) connector.getProtocolHandler()) ((AbstractProtocol) connector.getProtocolHandler())
.setAddress(getAddress()); .setAddress(getAddress());
} }
} }
if (getUriEncoding() != null) { 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) { protected void configureJsseProtocol(AbstractHttp11JsseProtocol jsseProtocol, Ssl ssl) {
jsseProtocol.setSSLEnabled(true); jsseProtocol.setSSLEnabled(true);
jsseProtocol.setSslProtocol(getSsl().getProtocol()); jsseProtocol.setSslProtocol(ssl.getProtocol());
if (getSsl().getClientAuth() == ClientAuth.NEED) { if (ssl.getClientAuth() == ClientAuth.NEED) {
jsseProtocol.setClientAuth(Boolean.TRUE.toString()); jsseProtocol.setClientAuth(Boolean.TRUE.toString());
} }
else if (getSsl().getClientAuth() == ClientAuth.WANT) { else if (ssl.getClientAuth() == ClientAuth.WANT) {
jsseProtocol.setClientAuth("want"); jsseProtocol.setClientAuth("want");
} }
jsseProtocol.setKeystorePass(getSsl().getKeyStorePassword()); jsseProtocol.setKeystorePass(ssl.getKeyStorePassword());
jsseProtocol.setKeyPass(getSsl().getKeyPassword()); jsseProtocol.setKeyPass(ssl.getKeyPassword());
jsseProtocol.setKeyAlias(getSsl().getKeyAlias()); jsseProtocol.setKeyAlias(ssl.getKeyAlias());
try { try {
jsseProtocol.setKeystoreFile(ResourceUtils.getFile(getSsl().getKeyStore()) jsseProtocol.setKeystoreFile(ResourceUtils.getFile(ssl.getKeyStore())
.getAbsolutePath()); .getAbsolutePath());
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
throw new EmbeddedServletContainerException("Could not find key store " throw new EmbeddedServletContainerException("Could not find key store "
+ getSsl().getKeyStore(), e); + ssl.getKeyStore(), e);
} }
jsseProtocol.setCiphers(StringUtils.arrayToCommaDelimitedString(getSsl() jsseProtocol
.getCiphers())); .setCiphers(StringUtils.arrayToCommaDelimitedString(ssl.getCiphers()));
if (getSsl().getTrustStore() != null) { if (ssl.getTrustStore() != null) {
try { try {
jsseProtocol.setTruststoreFile(ResourceUtils.getFile( jsseProtocol.setTruststoreFile(ResourceUtils.getFile(ssl.getTrustStore())
getSsl().getTrustStore()).getAbsolutePath()); .getAbsolutePath());
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
throw new EmbeddedServletContainerException("Could not find trust store " throw new EmbeddedServletContainerException("Could not find trust store "
+ getSsl().getTrustStore(), e); + ssl.getTrustStore(), e);
} }
} }
jsseProtocol.setTruststorePass(getSsl().getTrustStorePassword()); jsseProtocol.setTruststorePass(ssl.getTrustStorePassword());
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment