You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/02/25 16:02:18 UTC

svn commit: r916308 - in /tuscany/sca-java-2.x/trunk/modules: host-http/src/main/java/org/apache/tuscany/sca/host/http/ host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/ host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/

Author: slaws
Date: Thu Feb 25 15:02:17 2010
New Revision: 916308

URL: http://svn.apache.org/viewvc?rev=916308&view=rev
Log:
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. 

Added:
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java   (with props)
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java   (with props)
Modified:
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java
    tuscany/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
    tuscany/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Modified: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java?rev=916308&r1=916307&r2=916308&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java Thu Feb 25 15:02:17 2010
@@ -132,6 +132,10 @@
         public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException {
             getServletHost().addServletMapping(uri, servlet);
         }
+        
+        public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
+            getServletHost().addServletMapping(uri, servlet, securityContext);
+        }        
 
         public String getContextPath() {
             return getServletHost().getContextPath();

Modified: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java?rev=916308&r1=916307&r2=916308&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java Thu Feb 25 15:02:17 2010
@@ -68,6 +68,16 @@
         // For now just select the first one
         getDefaultServletHost().addServletMapping(uri, servlet);
     }
+    
+    public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
+        if (servletHosts.getServletHosts().isEmpty()) {
+            throw new ServletMappingException("No servlet host available");
+        }
+
+        // TODO implement selection of the correct Servlet host based on the mapping
+        // For now just select the first one
+        getDefaultServletHost().addServletMapping(uri, servlet, securityContext);
+    }    
 
     public Servlet getServletMapping(String uri) throws ServletMappingException {
         if (servletHosts.getServletHosts().isEmpty()) {

Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java?rev=916308&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java Thu Feb 25 15:02:17 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.host.http;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * A class to store policy context to enable Security QoS to 
+ * HTTP binding  
+ */
+public class SecurityContext {
+    private boolean isSSLEnabled = false;
+    private Properties sslProperties;
+    
+    private boolean isAuthenticationEnabled = false;
+    private List<UserContext> users = new ArrayList<UserContext>(); 
+    
+    public boolean isSSLEnabled() {
+        return isSSLEnabled;
+    }
+    
+    public void setSSLEnabled(boolean value) {
+        this.isSSLEnabled = value;
+    }
+    
+    public Properties getSSLProperties() {
+        return sslProperties;
+    }
+    
+    public void setSSLProperties(Properties sslProperties) {
+        this.sslProperties = sslProperties;
+    }
+    
+    public boolean isAuthenticationEnabled() {
+        return this.isAuthenticationEnabled;
+    }
+    
+    public void setAuthenticationEnabled(boolean value) {
+        this.isAuthenticationEnabled = value;
+    }
+    
+    public List<UserContext> getUsers() {
+        return this.users;
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java?rev=916308&r1=916307&r2=916308&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java Thu Feb 25 15:02:17 2010
@@ -58,6 +58,19 @@
      * @throws ServletMappingException
      */
     void addServletMapping(String uri, Servlet servlet) throws ServletMappingException;
+    
+    /**
+     * Add a mapping for an instance of a Servlet. This requests that the
+     * Servlet container direct all requests to the designated mapping to the
+     * supplied Servlet instance. SecurityContext can be passed to enable
+     * QoS services such as Confidentiality (SSL) and Authentication/Authorization
+     * 
+     * @param uri the URI-mapping for the Servlet
+     * @param servlet the Servlet that should be invoked
+     * @param securityContext the SecurityContext to enable QoS services
+     * @throws ServletMappingException
+     */    
+    void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException;    
 
     /**
      * Remove a Servlet mapping. This directs the Servlet container not to direct

Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java?rev=916308&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java Thu Feb 25 15:02:17 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.host.http;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Model class used to define list of users and it's roles
+ * 
+ * These info is used to configure authentication/authorization 
+ * in embedded http servers 
+ *
+ * @version $Rev$ $Date$
+ */
+public class UserContext {
+    private String username;
+    private String password;
+    private List<String> roles = new ArrayList<String>();
+    
+    
+    public UserContext() {
+        
+    }
+    
+    public UserContext(String username, String password) {
+        this.username = username;
+        this.password = password;
+    }
+    
+    public String getUsername() {
+        return this.username;
+    }
+    
+    public void setUsername(String username) {
+        this.username = username;
+    }
+    
+    public String getPassword() {
+        return this.password;
+    }
+    
+    public void setPassword(String password) {
+        this.password = password;
+    }
+    
+    public List<String> getRoles() {
+        return this.roles;
+    }
+    
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java?rev=916308&r1=916307&r2=916308&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java Thu Feb 25 15:02:17 2010
@@ -44,6 +44,7 @@
 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 @@
 
     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 @@
 
     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 @@
         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 @@
         }
     }
 
-    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 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 @@
                     //                    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();

Modified: tuscany/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=916308&r1=916307&r2=916308&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java Thu Feb 25 15:02:17 2010
@@ -38,6 +38,7 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+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.node.Node;
@@ -75,8 +76,12 @@
     public String getName() {
         return "webapp";
     }
-
+    
     public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException {
+        addServletMapping(suri, servlet, null);
+    }    
+
+    public void addServletMapping(String suri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
         URI pathURI = URI.create(suri);
 
         // Make sure that the path starts with a /