summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/host-jetty
diff options
context:
space:
mode:
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.java48
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();