diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-25 15:02:17 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-25 15:02:17 +0000 |
commit | 3662be91d1148b7a02b4713026b9e82eb7d846ea (patch) | |
tree | 9020c88f4a8b67a8ab673381a61732ff895c0b5e /sca-java-2.x/trunk/modules/host-jetty | |
parent | bc45b1fb7c484445f6478ef3a860ddcf0df20272 (diff) |
Add security context changes in from 1.x. Going to use for firing up SSL in the embedded container case when testing binding.ws policy. Manual merge as there are subsequent 2.x changes here.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@916308 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/host-jetty')
-rw-r--r-- | sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java index e746767338..b526103552 100644 --- a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java +++ b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java @@ -44,6 +44,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.LifeCycleListener; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.host.http.DefaultResourceServlet; +import org.apache.tuscany.sca.host.http.SecurityContext; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletMappingException; import org.apache.tuscany.sca.work.WorkScheduler; @@ -70,7 +71,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { private final Object joinLock = new Object(); private String trustStore; - private String truststorePassword; + private String trustStorePassword; private String keyStore; private String keyStorePassword; @@ -79,8 +80,10 @@ public class JettyServer implements ServletHost, LifeCycleListener { private boolean sendServerVersion; private WorkScheduler workScheduler; - private int defaultPort = portDefault; + public static int portDefault = 8080; + private int defaultPort = portDefault; + private int defaultSSLPort = 443; /** * Represents a port and the server that serves it. @@ -117,7 +120,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { trustStore = System.getProperty("javax.net.ssl.trustStore"); - truststorePassword = System.getProperty("javax.net.ssl.trustStorePassword"); + trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword"); keyStore = System.getProperty("javax.net.ssl.keyStore"); keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword"); @@ -172,14 +175,23 @@ public class JettyServer implements ServletHost, LifeCycleListener { } } - private void configureSSL(SslSocketConnector connector) { + private void configureSSL(SslSocketConnector connector, SecurityContext securityContext) { connector.setProtocol("TLS"); + if (securityContext != null) { + keyStoreType = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType()); + keyStore = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStore"); + keyStorePassword = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStorePassword"); + + trustStoreType = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()); + trustStore = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStore"); + trustStorePassword = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStorePassword"); + } connector.setKeystore(keyStore); connector.setKeyPassword(keyStorePassword); connector.setKeystoreType(keyStoreType); connector.setTruststore(trustStore); - connector.setTrustPassword(truststorePassword); + connector.setTrustPassword(trustStorePassword); connector.setTruststoreType(trustStoreType); connector.setPassword(keyStorePassword); @@ -188,18 +200,32 @@ public class JettyServer implements ServletHost, LifeCycleListener { } } - + public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException { + addServletMapping(suri, servlet, null); + } + + public void addServletMapping(String suri, Servlet servlet, final SecurityContext securityContext) throws ServletMappingException { URI uri = URI.create(suri); // Get the URI scheme and port - String scheme = uri.getScheme(); - if (scheme == null) { - scheme = "http"; + String scheme = null; + if(securityContext != null && securityContext.isSSLEnabled()) { + scheme = "https"; + } else { + scheme = uri.getScheme(); + if (scheme == null) { + scheme = "http"; + } } + int portNumber = uri.getPort(); if (portNumber == -1) { - portNumber = defaultPort; + if ("http".equals(scheme)) { + portNumber = defaultPort; + } else { + portNumber = defaultSSLPort; + } } // Get the port object associated with the given port number @@ -215,7 +241,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { // httpConnector.setPort(portNumber); SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setPort(portNumber); - configureSSL(sslConnector); + configureSSL(sslConnector, securityContext); server.setConnectors(new Connector[] {sslConnector}); } else { SelectChannelConnector selectConnector = new SelectChannelConnector(); |