[jbossws-commits] JBossWS SVN: r10404 - in container/jboss50/branches/ropalka-jboss510/src/main: resources/jbossws-jboss.deployer/META-INF and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Jul 29 04:03:08 EDT 2009


Author: richard.opalka at jboss.com
Date: 2009-07-29 04:03:08 -0400 (Wed, 29 Jul 2009)
New Revision: 10404

Added:
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandler.java
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB21.java
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB3.java
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebAppGeneratorDeploymentAspect.java
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifier.java
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifyingDeploymentAspect.java
Removed:
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/ejb/
   container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/jse/
Modified:
   container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss.deployer/META-INF/stack-agnostic-jboss-beans.xml
Log:
[JBWS-2332] refactoring

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandler.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandler.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandler.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.spi.deployment.Deployment;
+
+/**
+ * Handle web app security meta data 
+ * 
+ * @author Thomas.Diesler at jboss.org
+ */
+public interface SecurityHandler
+{
+   /** Add the security domain to jboss-web.xml */
+   void addSecurityDomain(JBossWebMetaData jbossWeb, Deployment dep);
+   
+   /** Add the security roles to web.xml */
+   void addSecurityRoles(JBossWebMetaData webApp, Deployment dep);
+}

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB21.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB21.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB21.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import org.jboss.metadata.common.ejb.IAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.common.integration.WSHelper;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData;
+
+/**
+ * Handle web app security meta data for EJB21 
+ * 
+ * @author Thomas.Diesler at jboss.org
+ * @author <a href="ropalka at redhat.com">Richard Opalka</a>
+ */
+public class SecurityHandlerEJB21 implements SecurityHandler
+{
+   public void addSecurityDomain(JBossWebMetaData jbossWeb, Deployment dep)
+   {
+      EJBArchiveMetaData ejbMetaData = WSHelper.getRequiredAttachment( dep, EJBArchiveMetaData.class );
+
+      String securityDomain = ejbMetaData.getSecurityDomain();
+      if (securityDomain != null)
+      {
+         if (securityDomain.startsWith("java:/jaas/") == false)
+            securityDomain = "java:/jaas/" + securityDomain;
+
+         jbossWeb.setSecurityDomain(securityDomain);
+      }
+   }
+
+   public void addSecurityRoles(JBossWebMetaData webApp, Deployment dep)
+   {
+      JBossMetaData jbmd = WSHelper.getRequiredAttachment( dep, JBossMetaData.class );
+      IAssemblyDescriptorMetaData assemblyDescriptor = jbmd.getAssemblyDescriptor();
+      if (assemblyDescriptor != null)
+      {
+         SecurityRolesMetaData securityRoles = assemblyDescriptor.getSecurityRoles();
+         if (securityRoles != null)
+            webApp.setSecurityRoles(securityRoles);
+      }
+   }
+}

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB3.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB3.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/SecurityHandlerEJB3.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.common.integration.WSHelper;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.integration.WebServiceDeclaration;
+import org.jboss.wsf.spi.deployment.integration.WebServiceDeployment;
+
+import javax.annotation.security.RolesAllowed;
+import java.util.Iterator;
+
+/**
+ * Handle web app security meta data for EJB3 
+ * 
+ * @author Thomas.Diesler at jboss.org
+ * @author <a href="ropalka at redhat.com">Richard Opalka</a>
+ */
+public class SecurityHandlerEJB3 implements SecurityHandler
+{
+   public void addSecurityDomain(JBossWebMetaData jbossWeb, Deployment dep)
+   {
+      WebServiceDeployment webServiceDeployment = WSHelper.getRequiredAttachment( dep, WebServiceDeployment.class );
+      String securityDomain = null;
+      Iterator<WebServiceDeclaration> it = webServiceDeployment.getServiceEndpoints().iterator();
+
+      while (it.hasNext())
+      {
+         WebServiceDeclaration container = it.next();
+         SecurityDomain anSecurityDomain = container.getAnnotation(SecurityDomain.class);
+         if (anSecurityDomain != null)
+         {
+            if (securityDomain != null && !securityDomain.equals(anSecurityDomain.value()))
+               throw new IllegalStateException("Multiple security domains not supported");
+
+            securityDomain = anSecurityDomain.value();
+         }
+      }
+
+      if (securityDomain != null)
+      {
+         if (securityDomain.startsWith("java:/jaas/") == false)
+            securityDomain = "java:/jaas/" + securityDomain;
+
+         jbossWeb.setSecurityDomain(securityDomain);
+      }
+   }
+
+   public void addSecurityRoles(JBossWebMetaData webApp, Deployment dep)
+   {
+      WebServiceDeployment webServiceDeployment = WSHelper.getRequiredAttachment( dep, WebServiceDeployment.class );
+
+      Iterator<WebServiceDeclaration> it = webServiceDeployment.getServiceEndpoints().iterator();
+      while (it.hasNext())
+      {
+         WebServiceDeclaration container = it.next();
+         RolesAllowed anRolesAllowed = container.getAnnotation(RolesAllowed.class);
+         if (anRolesAllowed != null)
+         {
+            SecurityRolesMetaData securityRoles = webApp.getSecurityRoles();
+            for (String roleName : anRolesAllowed.value())
+            {
+               SecurityRoleMetaData role = new SecurityRoleMetaData();
+               role.setRoleName(roleName);
+               securityRoles.add(role);
+            }
+         }
+      }
+   }
+
+}

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebAppGeneratorDeploymentAspect.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebAppGeneratorDeploymentAspect.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebAppGeneratorDeploymentAspect.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,285 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.web.jboss.JBossServletMetaData;
+import org.jboss.metadata.web.jboss.JBossServletsMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.metadata.web.spec.AuthConstraintMetaData;
+import org.jboss.metadata.web.spec.LoginConfigMetaData;
+import org.jboss.metadata.web.spec.SecurityConstraintMetaData;
+import org.jboss.metadata.web.spec.ServletMappingMetaData;
+import org.jboss.metadata.web.spec.TransportGuaranteeType;
+import org.jboss.metadata.web.spec.UserDataConstraintMetaData;
+import org.jboss.metadata.web.spec.WebResourceCollectionMetaData;
+import org.jboss.metadata.web.spec.WebResourceCollectionsMetaData;
+import org.jboss.wsf.common.integration.WSHelper;
+import org.jboss.wsf.spi.annotation.WebContext;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.DeploymentAspect;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.EJBMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.EJBSecurityMetaData;
+
+/**
+ * A deployment aspect that generates a webapp for an EJB endpoint 
+ * 
+ * @author Thomas.Diesler at jboss.org
+ */
+public class WebAppGeneratorDeploymentAspect extends DeploymentAspect
+{
+   private SecurityHandler securityHandlerEJB21;
+   private SecurityHandler securityHandlerEJB3;
+
+   public void setSecurityHandlerEJB21(SecurityHandler handler)
+   {
+      this.securityHandlerEJB21 = handler;
+   }
+
+   public void setSecurityHandlerEJB3(SecurityHandler handler)
+   {
+      this.securityHandlerEJB3 = handler;
+   }
+
+   @Override
+   public void start(Deployment dep)
+   {
+      final DeploymentUnit unit = WSHelper.getRequiredAttachment( dep, DeploymentUnit.class );
+      
+      if ( WSHelper.isJaxrpcEjbDeployment( dep ) )
+      {
+         JBossWebMetaData jbwmd = generateWebDeployment(dep, securityHandlerEJB21);
+         dep.addAttachment(JBossWebMetaData.class, jbwmd);
+         unit.addAttachment(JBossWebMetaData.class, jbwmd);
+      }
+      else if ( WSHelper.isJaxwsEjbDeployment( dep ) )
+      {
+         JBossWebMetaData jbwmd = generateWebDeployment(dep, securityHandlerEJB3);
+         dep.addAttachment(JBossWebMetaData.class, jbwmd);
+         unit.addAttachment(JBossWebMetaData.class, jbwmd);
+      }
+   }
+
+   protected JBossWebMetaData generateWebDeployment(Deployment dep, SecurityHandler securityHandler)
+   {
+      JBossWebMetaData jbwmd = new JBossWebMetaData();
+      createWebAppDescriptor(dep, jbwmd, securityHandler);
+      createJBossWebAppDescriptor(dep, jbwmd, securityHandler);
+      return jbwmd;
+   }
+
+   protected void createWebAppDescriptor(Deployment dep, JBossWebMetaData jbwmd, SecurityHandler securityHandler)
+   {
+      /*
+       <servlet>
+       <servlet-name>
+       <servlet-class>
+       </servlet>
+       */
+      JBossServletsMetaData servlets = jbwmd.getServlets();
+      for (Endpoint ep : dep.getService().getEndpoints())
+      {
+         JBossServletMetaData servlet = new JBossServletMetaData();
+         servlet.setServletName(ep.getShortName());
+         servlet.setServletClass(ep.getTargetBeanName());
+         servlets.add(servlet);
+      }
+
+      /*
+       <servlet-mapping>
+       <servlet-name>
+       <url-pattern>
+       </servlet-mapping>
+       */
+      for (Endpoint ep : dep.getService().getEndpoints())
+      {
+         List<ServletMappingMetaData> servletMappings = jbwmd.getServletMappings();
+         if (servletMappings == null)
+         {
+            servletMappings = new ArrayList<ServletMappingMetaData>();
+            jbwmd.setServletMappings(servletMappings);
+         }
+         ServletMappingMetaData servletMapping = new ServletMappingMetaData();
+         servletMapping.setServletName(ep.getShortName());
+         servletMapping.setUrlPatterns(Arrays.asList(new String[] { ep.getURLPattern() }));
+         servletMappings.add(servletMapping);
+      }
+
+      String authMethod = null;
+
+      // Add web-app/security-constraint for each port component
+      for (Endpoint ep : dep.getService().getEndpoints())
+      {
+         String ejbName = ep.getShortName();
+
+         Boolean secureWSDLAccess = null;
+         String transportGuarantee = null;
+         String beanAuthMethod = null;
+
+         WebContext anWebContext = (WebContext)ep.getTargetBeanClass().getAnnotation(WebContext.class);
+         if (anWebContext != null)
+         {
+            if (anWebContext.authMethod().length() > 0)
+               beanAuthMethod = anWebContext.authMethod();
+            if (anWebContext.transportGuarantee().length() > 0)
+               transportGuarantee = anWebContext.transportGuarantee();
+            if (anWebContext.secureWSDLAccess())
+               secureWSDLAccess = anWebContext.secureWSDLAccess();
+         }
+
+         EJBArchiveMetaData appMetaData = WSHelper.getOptionalAttachment( dep, EJBArchiveMetaData.class );
+         if (appMetaData != null && appMetaData.getBeanByEjbName(ejbName) != null)
+         {
+            EJBMetaData bmd = appMetaData.getBeanByEjbName(ejbName);
+            EJBSecurityMetaData smd = bmd.getSecurityMetaData();
+            if (smd != null)
+            {
+               beanAuthMethod = smd.getAuthMethod();
+               transportGuarantee = smd.getTransportGuarantee();
+               secureWSDLAccess = smd.getSecureWSDLAccess();
+            }
+         }
+
+         if (beanAuthMethod != null || transportGuarantee != null)
+         {
+            /*
+             <security-constraint>
+             <web-resource-collection>
+             <web-resource-name>TestUnAuthPort</web-resource-name>
+             <url-pattern>/HSTestRoot/TestUnAuth/*</url-pattern>
+             </web-resource-collection>
+             <auth-constraint>
+             <role-name>*</role-name>
+             </auth-constraint>
+             <user-data-constraint>
+             <transport-guarantee>NONE</transport-guarantee>
+             </user-data-constraint>
+             </security-constraint>
+             */
+            List<SecurityConstraintMetaData> securityContraints = jbwmd.getSecurityContraints();
+            if (securityContraints == null)
+            {
+               securityContraints = new ArrayList<SecurityConstraintMetaData>();
+               jbwmd.setSecurityContraints(securityContraints);
+            }
+            SecurityConstraintMetaData securityConstraint = new SecurityConstraintMetaData();
+            securityContraints.add(securityConstraint);
+            
+            WebResourceCollectionsMetaData resourceCollections = securityConstraint.getResourceCollections();
+            if (resourceCollections == null)
+            {
+               resourceCollections = new WebResourceCollectionsMetaData();
+               securityConstraint.setResourceCollections(resourceCollections);
+            }
+            WebResourceCollectionMetaData resourceCollection = new WebResourceCollectionMetaData();
+            resourceCollections.add(resourceCollection);
+            
+            resourceCollection.setWebResourceName(ejbName);
+            resourceCollection.setUrlPatterns(Arrays.asList(new String[] { ep.getURLPattern() }));
+            ArrayList<String> httpMethods = new ArrayList<String>();
+            resourceCollection.setHttpMethods(httpMethods);
+            if (Boolean.TRUE.equals(secureWSDLAccess))
+            {
+               httpMethods.add("GET");
+            }
+            httpMethods.add("POST");
+
+            // Optional auth-constraint
+            if (beanAuthMethod != null)
+            {
+               // Only the first auth-method gives the war login-config/auth-method
+               if (authMethod == null)
+                  authMethod = beanAuthMethod;
+
+               AuthConstraintMetaData authConstraint = new AuthConstraintMetaData();
+               authConstraint.setRoleNames(Arrays.asList(new String[] { "*" }));
+               securityConstraint.setAuthConstraint(authConstraint);
+            }
+            // Optional user-data-constraint
+            if (transportGuarantee != null)
+            {
+               UserDataConstraintMetaData userDataConstraint = new UserDataConstraintMetaData();
+               userDataConstraint.setTransportGuarantee(TransportGuaranteeType.valueOf(transportGuarantee));
+               securityConstraint.setUserDataConstraint(userDataConstraint);
+            }
+         }
+      }
+
+      // Optional login-config/auth-method
+      if (authMethod != null && securityHandler != null)
+      {
+         LoginConfigMetaData loginConfig = jbwmd.getLoginConfig();
+         if (loginConfig == null)
+         {
+            loginConfig = new LoginConfigMetaData();
+            jbwmd.setLoginConfig(loginConfig);
+         }
+         loginConfig.setAuthMethod(authMethod);
+         loginConfig.setRealmName("EJBServiceEndpointServlet Realm");
+
+         securityHandler.addSecurityRoles(jbwmd, dep);
+      }
+   }
+
+   /**
+    * Creates jboss-web meta data.
+    * 
+    * <jboss-web>
+    *   <security-domain>java:/jaas/custom-security-domain</security-domain>
+    *   <context-root>/custom-context-root</context-root>
+    *   <virtual-host>custom-virtual-host</virtual-host>
+    * </jboss-web>
+    *
+    * @param dep 
+    * @param jbwmd
+    * @param securityHandler
+    */
+   protected void createJBossWebAppDescriptor
+   ( 
+      final Deployment dep, final JBossWebMetaData jbossWebMD, final SecurityHandler securityHandler
+   )
+   {
+      // Set security domain
+      if (securityHandler != null)
+      {
+         securityHandler.addSecurityDomain(jbossWebMD, dep);
+      }
+
+      // Set context root
+      String contextRoot = dep.getService().getContextRoot();
+      jbossWebMD.setContextRoot(contextRoot);
+
+      // Set virtual hosts
+      String[] virtualHosts = dep.getService().getVirtualHosts();
+      if (virtualHosts != null && virtualHosts.length > 0)
+      {
+         jbossWebMD.setVirtualHosts(Arrays.asList(virtualHosts));
+      }
+   }
+
+}

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifier.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifier.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifier.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.metadata.javaee.spec.ParamValueMetaData;
+import org.jboss.metadata.web.jboss.JBossServletMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.metadata.web.spec.ServletMetaData;
+import org.jboss.webservices.integration.util.ASHelper;
+import org.jboss.wsf.common.integration.WSConstants;
+import org.jboss.wsf.common.integration.WSHelper;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+
+/**
+ * The modifier of jboss web meta data. 
+ * It configures WS transport for every webservice endpoint
+ * plus propagates WS stack specific context parameters if required.
+ *
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public final class WebMetaDataModifier
+{
+
+   /**
+    * Constructor.
+    */
+   public WebMetaDataModifier()
+   {
+      super();
+   }
+
+   /**
+    * Modifies web meta data to configure webservice stack transport and properties.
+    * 
+    * @param dep webservice deployment
+    */
+   public void modify( final Deployment dep )
+   {
+      final JBossWebMetaData jbossWebMD = WSHelper.getRequiredAttachment( dep, JBossWebMetaData.class );
+
+      this.propagateContextProps( dep, jbossWebMD );
+      this.configureEndpoints( dep, jbossWebMD );
+   }
+
+   /**
+    * Propagates stack specific context parameters if specified. 
+    * 
+    * @param dep webservice deployment
+    * @param jbossWebMD web meta data
+    */
+   @SuppressWarnings( "unchecked" )
+   private void propagateContextProps( final Deployment dep, final JBossWebMetaData jbossWebMD )
+   {
+      final Map< String, String > stackContextParams = ( Map< String, String > )
+          dep.getProperty( WSConstants.STACK_CONTEXT_PARAMS );
+      
+      if ( stackContextParams != null )
+      {
+         final List< ParamValueMetaData > contextParams = this.getContextParams( jbossWebMD );
+
+         for ( Map.Entry< String, String > entry : stackContextParams.entrySet() )
+         {
+            final ParamValueMetaData newParam = this.newParameter( entry.getKey(), entry.getValue() );
+            contextParams.add( newParam );
+         }
+      }
+   }
+
+   /**
+    * Configures transport servlet class for every found webservice endpoint. 
+    * 
+    * @param dep webservice deployment
+    * @param jbossWebMD web meta data
+    */
+   private void configureEndpoints( final Deployment dep, final JBossWebMetaData jbossWebMD )
+   {
+      final Iterator< JBossServletMetaData > servlets = jbossWebMD.getServlets().iterator();
+      
+      while ( servlets.hasNext() )
+      {
+         final ServletMetaData servletMD = servlets.next();
+         final ClassLoader loader = dep.getInitialClassLoader();
+         final boolean isWebserviceEndpoint = ASHelper.getEndpointClass( servletMD, loader ) != null;
+
+         if ( isWebserviceEndpoint )
+         {
+            // set transport servlet
+            servletMD.setServletClass( this.getTransportClassName( dep ) );
+
+            // configure webservice endpoint
+            final String endpointClassName = servletMD.getServletClass();
+            final List< ParamValueMetaData > initParams = this.getServletInitParams( servletMD );
+            final ParamValueMetaData endpointParam = this.newParameter( 
+               Endpoint.SEPID_DOMAIN_ENDPOINT, endpointClassName ); 
+            
+            initParams.add( endpointParam );
+         }
+      }
+   }
+   
+   /**
+    * Returns stack specific transport class name.
+    * 
+    * @param dep webservice deployment
+    * @return stack specific transport class name
+    * @throws IllegalStateException if transport class name is not found in deployment properties map
+    */
+   private String getTransportClassName( final Deployment dep )
+   {
+      final String transportClassName = ( String ) dep.getProperty( WSConstants.STACK_TRANSPORT_CLASS );
+      
+      if ( transportClassName == null )
+      {
+         throw new IllegalStateException( "Cannot obtain deployment property: " + WSConstants.STACK_TRANSPORT_CLASS );
+      }
+      
+      return transportClassName;
+   }
+   
+   /**
+    * Creates new parameter with specified key and value.
+    * 
+    * @param key the key
+    * @param value the value
+    * @return new parameter
+    */
+   private ParamValueMetaData newParameter( final String key, final String value )
+   {
+      final ParamValueMetaData paramMD = new ParamValueMetaData();
+      paramMD.setParamName( key );
+      paramMD.setParamValue( value );
+      
+      return paramMD;
+   }
+   
+   /**
+    * Gets servlet init params list. Constructs new init params list if it does not exist yet.
+    * 
+    * @param servletMD servlet meta data
+    * @return servlet init params list
+    */
+   private List< ParamValueMetaData > getServletInitParams( final ServletMetaData servletMD )
+   {
+      List< ParamValueMetaData > initParams = servletMD.getInitParam();
+
+      if ( initParams == null )
+      {
+         initParams = new ArrayList< ParamValueMetaData >();
+         servletMD.setInitParam( initParams );
+      }
+      
+      return initParams;
+   }
+
+   /**
+    * Gets context params list. Constructs new context params list if it does not exist yet.
+    * 
+    * @param jbossWebMD web meta data
+    * @return context params list
+    */
+   private List< ParamValueMetaData > getContextParams( final JBossWebMetaData jbossWebMD )
+   {
+      List< ParamValueMetaData > contextParams = jbossWebMD.getContextParams();
+      
+      if ( contextParams == null )
+      {
+         contextParams = new ArrayList< ParamValueMetaData >();
+         jbossWebMD.setContextParams( contextParams );
+      }
+      
+      return contextParams;
+   }
+
+}

Added: container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifyingDeploymentAspect.java
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifyingDeploymentAspect.java	                        (rev 0)
+++ container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/tomcat/WebMetaDataModifyingDeploymentAspect.java	2009-07-29 08:03:08 UTC (rev 10404)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.webservices.integration.tomcat;
+
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.DeploymentAspect;
+
+/**
+ * Modifies web meta data to configure webservice stack endpoints and properties.
+ * 
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public final class WebMetaDataModifyingDeploymentAspect extends DeploymentAspect
+{
+   
+   /** Web meta data modifier. */
+   private WebMetaDataModifier webMetaDataModifier;
+
+   /**
+    * Constructor.
+    */
+   public WebMetaDataModifyingDeploymentAspect()
+   {
+      super();
+   }
+
+   /**
+    * Sets Web meta data modifier. This method is called using MC injection.
+    * 
+    * @param webMDModifier web meta data modifier
+    */
+   public void setWebMetaDataModifier( final WebMetaDataModifier webMDModifier )
+   {
+      this.webMetaDataModifier = webMDModifier;
+   }
+
+   /**
+    * Modifies web meta data.
+    * 
+    * @param dep webservice deployment
+    */
+   public void start( final Deployment dep )
+   {
+      this.webMetaDataModifier.modify( dep );
+   }
+   
+}

Modified: container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss.deployer/META-INF/stack-agnostic-jboss-beans.xml
===================================================================
--- container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss.deployer/META-INF/stack-agnostic-jboss-beans.xml	2009-07-29 07:55:15 UTC (rev 10403)
+++ container/jboss50/branches/ropalka-jboss510/src/main/resources/jbossws-jboss.deployer/META-INF/stack-agnostic-jboss-beans.xml	2009-07-29 08:03:08 UTC (rev 10404)
@@ -64,9 +64,9 @@
   </bean>
 
   <!-- Deployment aspect helper beans -->
-  <bean name="WSSecurityHandlerEJB21" class="org.jboss.webservices.integration.tomcat.ejb.SecurityHandlerEJB21"/>
-  <bean name="WSSecurityHandlerEJB3" class="org.jboss.webservices.integration.tomcat.ejb.SecurityHandlerEJB3"/>
-  <bean name="WSWebMetaDataModifier" class="org.jboss.webservices.integration.tomcat.jse.WebMetaDataModifier"/>
+  <bean name="WSSecurityHandlerEJB21" class="org.jboss.webservices.integration.tomcat.SecurityHandlerEJB21"/>
+  <bean name="WSSecurityHandlerEJB3" class="org.jboss.webservices.integration.tomcat.SecurityHandlerEJB3"/>
+  <bean name="WSWebMetaDataModifier" class="org.jboss.webservices.integration.tomcat.WebMetaDataModifier"/>
 
   <!-- The AS specific deployment aspects -->
   <bean name="WSContainerMetaDataDeploymentAspect" class="org.jboss.webservices.integration.metadata.ContainerMetaDataDeploymentAspect">
@@ -135,14 +135,14 @@
     <property name="relativeOrder">15</property> <!-- [JBDEPLOY-201] workaround -->
   </bean>
 
-  <bean name="WSWebMetaDataModifyingDeploymentAspect" class="org.jboss.webservices.integration.tomcat.jse.WebMetaDataModifyingDeploymentAspect">
+  <bean name="WSWebMetaDataModifyingDeploymentAspect" class="org.jboss.webservices.integration.tomcat.WebMetaDataModifyingDeploymentAspect">
     <property name="requires">WebMetaData, ContextProperties, StackDescriptor</property>
     <property name="provides">WebMetaData</property>
     <property name="webMetaDataModifier"><inject bean="WSWebMetaDataModifier"/></property>
     <property name="relativeOrder">33</property> <!-- [JBDEPLOY-201] workaround -->
   </bean>
 
-  <bean name="WSWebAppGeneratorDeploymentAspect" class="org.jboss.webservices.integration.tomcat.ejb.WebAppGeneratorDeploymentAspect">
+  <bean name="WSWebAppGeneratorDeploymentAspect" class="org.jboss.webservices.integration.tomcat.WebAppGeneratorDeploymentAspect">
     <property name="requires">VirtualHosts,URLPattern</property>
     <property name="provides">WebMetaData</property>
     <property name="securityHandlerEJB21"><inject bean="WSSecurityHandlerEJB21"/></property>



More information about the jbossws-commits mailing list