[jboss-svn-commits] JBL Code SVN: r28569 - in labs/jbossesb/workspace/tfennelly/httpg2/product: rosetta/src/org/jboss/internal/soa/esb/listeners/war and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 29 08:56:47 EDT 2009


Author: tfennelly
Date: 2009-07-29 08:56:46 -0400 (Wed, 29 Jul 2009)
New Revision: 28569

Added:
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Constraints.java
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Security.java
Modified:
   labs/jbossesb/workspace/tfennelly/httpg2/product/etc/schemas/xml/jbossesb-1.2.0.xsd
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/HttpGatewayDeploymentFactory.java
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/Servlet.java
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/web.xml.ftl
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers120/HttpListenerMapper.java
   labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java
Log:
added http method, role and auth method support

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/etc/schemas/xml/jbossesb-1.2.0.xsd
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/etc/schemas/xml/jbossesb-1.2.0.xsd	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/etc/schemas/xml/jbossesb-1.2.0.xsd	2009-07-29 12:56:46 UTC (rev 28569)
@@ -1698,7 +1698,42 @@
 		</xsd:annotation>
 		<xsd:complexType>
 			<xsd:complexContent>
-				<xsd:extension base="jesb:bus" />
+				<xsd:extension base="jesb:bus">
+                    <xsd:choice minOccurs="0" maxOccurs="2">
+                        <xsd:element name="methods" minOccurs="0" maxOccurs="1">
+                            <xsd:complexType>
+                                <xsd:sequence>
+                                    <xsd:element name="method" minOccurs="1" maxOccurs="5">
+                                        <xsd:complexType>
+                                            <xsd:attribute name="name" use="required">
+                                                <xsd:simpleType>
+                                                    <xsd:restriction base="xsd:NMTOKEN">
+                                                        <xsd:enumeration value="GET" />
+                                                        <xsd:enumeration value="POST" />
+                                                        <xsd:enumeration value="PUT" />
+                                                        <xsd:enumeration value="DELETE" />
+                                                        <xsd:enumeration value="HEAD" />
+                                                    </xsd:restriction>
+                                                </xsd:simpleType>
+                                            </xsd:attribute>
+                                        </xsd:complexType>
+                                    </xsd:element>
+                                </xsd:sequence>
+                            </xsd:complexType>
+                        </xsd:element>
+                        <xsd:element name="roles" minOccurs="0" maxOccurs="1">
+                            <xsd:complexType>
+                                <xsd:sequence>
+                                    <xsd:element name="role" minOccurs="1" maxOccurs="unbounded">
+                                        <xsd:complexType>
+                                            <xsd:attribute name="name" type="xsd:string" use="required" />
+                                        </xsd:complexType>
+                                    </xsd:element>
+                                </xsd:sequence>
+                            </xsd:complexType>
+                        </xsd:element>
+                    </xsd:choice>
+                </xsd:extension>
 			</xsd:complexContent>
 		</xsd:complexType>
 	</xsd:element>
@@ -1711,7 +1746,23 @@
 		</xsd:annotation>
 		<xsd:complexType>
 			<xsd:complexContent>
-				<xsd:extension base="jesb:bus-provider" />
+				<xsd:extension base="jesb:bus-provider">
+                    <xsd:sequence>
+                        <xsd:element name="auth" minOccurs="0" maxOccurs="1">
+                            <xsd:complexType>
+                                <xsd:attribute name="method" use="required">
+                                    <xsd:simpleType>
+                                        <xsd:restriction base="xsd:NMTOKEN">
+                                            <xsd:enumeration value="BASIC" />
+                                            <xsd:enumeration value="DIGEST" />
+                                            <xsd:enumeration value="CLIENT-CERT" />
+                                        </xsd:restriction>
+                                    </xsd:simpleType>
+                                </xsd:attribute>
+                            </xsd:complexType>
+                        </xsd:element>
+                    </xsd:sequence>
+                </xsd:extension>
 			</xsd:complexContent>
 		</xsd:complexType>
 	</xsd:element>

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/HttpGatewayDeploymentFactory.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/HttpGatewayDeploymentFactory.java	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/HttpGatewayDeploymentFactory.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -21,20 +21,22 @@
 
 import org.jboss.internal.soa.esb.listeners.war.Servlet;
 import org.jboss.internal.soa.esb.listeners.war.WebDeploymentArchive;
+import org.jboss.internal.soa.esb.listeners.war.security.Security;
+import org.jboss.internal.soa.esb.listeners.war.security.Constraints;
 import org.jboss.soa.esb.listeners.config.DeploymentResourceLocator;
 import org.jboss.soa.esb.listeners.gateway.HttpGatewayServlet;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.internal.soa.esb.assertion.AssertArgument;
-import org.apache.log4j.Logger;
 
 /**
  * Http Gateway deployment factory.
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
 public class HttpGatewayDeploymentFactory implements WebGatewayDeploymentFactory {
+    
+    public static final String URL_PATTERN = "urlPattern";
+    public static final String METHODS = "methods";
 
     public void setBusName(String busName) {
         // Not relevant to this factory!
@@ -50,7 +52,7 @@
 
         // Set the endpoint urlPattern so as to map requests from that namespace into
         // this servlet instance...
-        String urlPattern = webEndpointConfig.getAttribute("urlPattern");
+        String urlPattern = webEndpointConfig.getAttribute(URL_PATTERN);
         if(urlPattern != null) {
             if(urlPattern.startsWith("/")) {
                 servlet.getUrlMappings().add("/http" + urlPattern);
@@ -63,10 +65,50 @@
             servlet.getUrlMappings().add("/http/" + serviceCat + "/" + serviceName);
         }
 
+        // Add the security configurations for the servlet...
+        addSecurityConstraints(webEndpointConfig, servlet);
+
         // Map all config tree attributes as servlet parameters...
         servlet.getParams().addAll(webEndpointConfig.attributesAsList());
 
         // Add the servlet definition to the model...
         webDeployment.getWebModel().getServlets().add(servlet);
     }
+
+    private void addSecurityConstraints(ConfigTree webEndpointConfig, Servlet servlet) {
+        String methodsConfig = webEndpointConfig.getAttribute(METHODS);
+        Security security = getSecurity(servlet);
+        Constraints constraints = getConstraints(security);
+
+        if(methodsConfig != null) {
+            String[] methods = methodsConfig.split(",");
+
+            // Add the specified methods...
+            for(String method : methods) {
+                constraints.getAllowedMethods().add(method.trim());
+            }
+        } else {
+            // If no methods are defined, then all default methods are
+            // allowed...
+            constraints.addDefaultAllowedMethods();
+        }
+    }
+
+    private Security getSecurity(Servlet servlet) {
+        Security security = servlet.getSecurity();
+        if(security == null) {
+            security = new Security();
+            servlet.setSecurity(security);
+        }
+        return security;
+    }
+
+    private Constraints getConstraints(Security security) {
+        Constraints constraints = security.getConstraints();
+        if(constraints == null) {
+            constraints = new Constraints();
+            security.setConstraints(constraints);
+        }
+        return constraints;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/Servlet.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/Servlet.java	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/Servlet.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -22,6 +22,7 @@
 package org.jboss.internal.soa.esb.listeners.war;
 
 import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.listeners.war.security.Security;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 
 import javax.servlet.http.HttpServlet;
@@ -37,6 +38,7 @@
 public class Servlet extends AbstractWebComponent {
 
     private List<String> urlMappings = new ArrayList<String>();
+    private Security security;
 
     public Servlet(String name, String runtimeClass) {
         super(name, runtimeClass);
@@ -45,4 +47,12 @@
     public List<String> getUrlMappings() {
         return urlMappings;
     }
+
+    public Security getSecurity() {
+        return security;
+    }
+
+    public void setSecurity(Security security) {
+        this.security = security;
+    }
 }

Added: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Constraints.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Constraints.java	                        (rev 0)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Constraints.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.listeners.war.security;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * Security constraints.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class Constraints {
+    
+    private Set<String> allowedMethods = new HashSet<String>();
+
+    public Constraints() {
+        // OPTIONS are always supported...
+        allowedMethods.add("OPTIONS");
+    }
+
+    public Set<String> getAllowedMethods() {
+        return allowedMethods;
+    }
+
+    public void addDefaultAllowedMethods() {
+        allowedMethods.add("GET");
+        allowedMethods.add("POST");
+        allowedMethods.add("PUT");
+        allowedMethods.add("DELETE");
+        allowedMethods.add("HEAD");
+    }
+}

Added: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Security.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Security.java	                        (rev 0)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/security/Security.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.listeners.war.security;
+
+import java.util.List;
+
+/**
+ * Security.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class Security {
+    
+    private Constraints constraints;
+
+    public Constraints getConstraints() {
+        return constraints;
+    }
+
+    public void setConstraints(Constraints constraints) {
+        this.constraints = constraints;
+    }
+}

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/web.xml.ftl
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/web.xml.ftl	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/internal/soa/esb/listeners/war/web.xml.ftl	2009-07-29 12:56:46 UTC (rev 28569)
@@ -26,7 +26,6 @@
     </filter-mapping>
     </#list>
 
-
     <#list webModel.servlets as servlet>
 
     <!-- Servlet '${servlet.name}' configuration... -->
@@ -51,4 +50,42 @@
     </#list>
     </#list>
 
+    <!-- Security constraints... -->
+    <#list webModel.servlets as servlet>
+
+    <#if servlet.security??>
+    <!-- Servlet '${servlet.name}' security configuration... -->
+
+    <#if servlet.security.constraints??>
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Global "Lockdown" constraints for servlet ${servlet.name}</web-resource-name>
+            <#list servlet.urlMappings as urlMapping>
+            <url-pattern>${urlMapping}</url-pattern>
+            </#list>
+        </web-resource-collection>
+        <auth-constraint />
+    </security-constraint>
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Localized "Reopen" constraints for servlet ${servlet.name}</web-resource-name>
+            <#list servlet.urlMappings as urlMapping>
+            <url-pattern>${urlMapping}</url-pattern>
+            </#list>
+            <#list servlet.security.constraints.methods as method>
+            <http-method>${method}</http-method>
+            </#list>
+        </web-resource-collection>
+        <user-data-constraint>
+            <transport-guarantee>NONE</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+    </#if>
+
+    <#else>
+    <!-- Servlet '${servlet.name}' doesn't define a security! -->
+    </#if>
+
+    </#list>
+
 </web-app>

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers120/HttpListenerMapper.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers120/HttpListenerMapper.java	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers120/HttpListenerMapper.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -3,6 +3,7 @@
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.dom.YADOMUtil;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.gateway.HttpGatewayServlet;
 import org.jboss.soa.esb.listeners.config.xbeanmodel120.PropertyDocument.Property;
 import org.jboss.soa.esb.listeners.config.xbeanmodel120.HttpBusDocument.HttpBus;
 import org.jboss.soa.esb.listeners.config.xbeanmodel120.HttpListenerDocument.HttpListener;
@@ -16,7 +17,8 @@
  * @author <a href="mailto:ema at redhat.com">Jim Ma</a>
  */
 public class HttpListenerMapper {
-	 /**
+
+    /**
      * Perform the Http listener mapping.
      * @param root The "ConfigTree" configuration root node.
      * @param listener http listener config.
@@ -59,16 +61,27 @@
         if(listener.getIsGateway()) {
             String urlPattern = listener.getUrlPattern();
             PayloadAs.Enum payloadAs = listener.getPayloadAs();
+            HttpBus.Methods methods = bus.getMethods();
 
-            listenerNode.setAttribute("gatewayClass", HttpGatewayDeploymentFactory.class.getName());
+            listenerNode.setAttribute(ListenerTagNames.GATEWAY_CLASS_TAG, HttpGatewayDeploymentFactory.class.getName());
 			listenerNode.setAttribute(ListenerTagNames.IS_GATEWAY_TAG, "true");
 
             if(urlPattern != null) {
-                listenerNode.setAttribute("urlPattern", urlPattern);
+                listenerNode.setAttribute(HttpGatewayDeploymentFactory.URL_PATTERN, urlPattern);
             }
             if(payloadAs != null) {
-                listenerNode.setAttribute("payloadAs", payloadAs.toString());
+                listenerNode.setAttribute(HttpGatewayServlet.PAYLOAD_AS, payloadAs.toString());
             }
+            if(methods != null) {
+                StringBuilder methodString = new StringBuilder();
+                for(HttpBus.Methods.Method method : methods.getMethodList()) {
+                    if(methodString.length() > 0) {
+                        methodString.append(",");
+                    }
+                    methodString.append(method.getName().toString());
+                }
+                listenerNode.setAttribute(HttpGatewayDeploymentFactory.METHODS, methodString.toString());
+            }
         } else {
 			throw new ConfigurationException("Invalid <http-listener> config [" + listener.getName() +"]. <http-listener> is currently only supported as a gateway listener.");
         }

Modified: labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java	2009-07-29 12:22:25 UTC (rev 28568)
+++ labs/jbossesb/workspace/tfennelly/httpg2/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java	2009-07-29 12:56:46 UTC (rev 28569)
@@ -54,6 +54,7 @@
     private MessageComposer<HttpRequestWrapper> messageComposer;
     private String mep;
     private long blockingTimeout;
+    public static final String PAYLOAD_AS = "payloadAs";
 
     public void init(ServletConfig config) throws ServletException {
         service = new Service(config.getInitParameter(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG), config.getInitParameter(ListenerTagNames.TARGET_SERVICE_NAME_TAG));



More information about the jboss-svn-commits mailing list