[jboss-cvs] JBossAS SVN: r57551 - trunk/server/src/main/org/jboss/deployment

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 10 17:15:13 EDT 2006


Author: bill.burke at jboss.com
Date: 2006-10-10 17:15:12 -0400 (Tue, 10 Oct 2006)
New Revision: 57551

Added:
   trunk/server/src/main/org/jboss/deployment/EARStructure.java
   trunk/server/src/main/org/jboss/deployment/JaccCommitDeployer.java
   trunk/server/src/main/org/jboss/deployment/JaccInitializationDeployer.java
Log:
untested EAR and Jacc deployers

Added: trunk/server/src/main/org/jboss/deployment/EARStructure.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/EARStructure.java	2006-10-10 20:23:23 UTC (rev 57550)
+++ trunk/server/src/main/org/jboss/deployment/EARStructure.java	2006-10-10 21:15:12 UTC (rev 57551)
@@ -0,0 +1,221 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.deployment;
+
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
+import org.jboss.deployers.plugins.structure.vfs.AbstractStructureDeployer;
+import org.jboss.deployers.plugins.structure.vfs.jar.JARCandidateStructureVisitorFactory;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.metadata.XmlFileLoader;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * WARStructure.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class EARStructure extends AbstractStructureDeployer
+{
+   /**
+    * The default filter
+    */
+   public static final VirtualFileFilter DEFAULT_EAR_LIB_FILTER = new SuffixMatchFilter(".jar");
+
+   /**
+    * The web-inf/lib filter
+    */
+   private VirtualFileFilter earLibFilter = DEFAULT_EAR_LIB_FILTER;
+
+   @Override
+   public int getRelativeOrder()
+   {
+      return 1000;
+   }
+
+   /**
+    * Get the webInfLibFilter.
+    *
+    * @return the webInfLibFilter.
+    */
+   public VirtualFileFilter getEarLibFilter()
+   {
+      return earLibFilter;
+   }
+
+   /**
+    * Set the webInfLibFilter.
+    *
+    * @param earLibFilter the webInfLibFilter.
+    * @throws IllegalArgumentException for a null filter
+    */
+   public void setEarLibFilter(VirtualFileFilter earLibFilter)
+   {
+      if (earLibFilter == null)
+         throw new IllegalArgumentException("Null filter");
+      this.earLibFilter = earLibFilter;
+   }
+
+   public boolean determineStructure(DeploymentContext context)
+   {
+      try
+      {
+         VirtualFile root = context.getRoot();
+         if (root.isLeaf() == false)
+         {
+            // We require either a WEB-INF or the name ends in .war
+            if (root.getName().endsWith(".ear") == false)
+            {
+               try
+               {
+                  root.findChild("META-INF");
+                  log.trace("... ok - directory has a META-INF subdirectory");
+               }
+               catch (IOException e)
+               {
+                  log.trace("... no - doesn't look like a ear and no META-INF subdirectory.");
+                  return false;
+               }
+            }
+            else
+            {
+               log.trace("... ok - name ends in .ear.");
+            }
+
+            // The metadata path is WEB-INF
+            context.setMetaDataPath("META-INF");
+
+            VirtualFile applicationXml = context.getMetaDataFile("application.xml");
+            VirtualFile jbossAppXml = context.getMetaDataFile("jboss-app.xml");
+            VirtualFile lib = null;
+            J2eeApplicationMetaData metaData = new J2eeApplicationMetaData();
+            boolean scan = true;
+            context.getTransientAttachments().addAttachment(J2eeApplicationMetaData.class, metaData);
+
+            if (applicationXml != null)
+            {
+               InputStream in = applicationXml.openStream();
+               XmlFileLoader xfl = new XmlFileLoader(false);
+               Element application = xfl.getDocument(in, "META-INF/application.xml").getDocumentElement();
+               metaData.importXml(application);
+               in.close();
+               scan = false;
+            }
+            if (jbossAppXml != null)
+            {
+               InputStream in = jbossAppXml.openStream();
+               XmlFileLoader xfl = new XmlFileLoader(false);
+               Element jbossApp = xfl.getDocument(in, "META-INF/jboss-app.xml").getDocumentElement();
+               metaData.importXml(jbossApp);
+               in.close();
+            }
+
+            // set up classpaths
+            List<VirtualFile> classpaths = new ArrayList<VirtualFile>();
+            String libDir = metaData.getLibraryDirectory() == null ? "lib" : metaData.getLibraryDirectory();
+            if (metaData.getLibraryDirectory() != null)
+            {
+               try
+               {
+                  lib = root.findChild(libDir);
+                  if (lib != null)
+                  {
+                     List<VirtualFile> archives = lib.getChildren(earLibFilter);
+                     for (VirtualFile archive : archives)
+                        classpaths.add(archive);
+                  }
+               }
+               catch (IOException ignored)
+               {
+                  // lib directory does not exist
+               }
+            }
+
+            // Add the manifest locations
+            VFSUtils.addManifestLocations(root, classpaths);
+            context.setClassPath(classpaths);
+
+            // Create subdeployments for the ear modules
+            for (Iterator iter = metaData.getModules(); iter.hasNext();)
+            {
+               J2eeModuleMetaData mod = (J2eeModuleMetaData) iter.next();
+               String fileName = mod.getFileName();
+               if (fileName != null && (fileName = fileName.trim()).length() > 0)
+               {
+                  try
+                  {
+                     VirtualFile module = root.findChild(fileName);
+                     if (module == null)
+                     {
+                        throw new RuntimeException(fileName + " module listed in application.xml does not exist within .ear " + root.getName());
+                     }
+                     AbstractDeploymentContext moduleContext = new AbstractDeploymentContext(module, true, context);
+                     moduleContext.getTransientAttachments().addAttachment(J2eeModuleMetaData.class, mod);
+                     context.addChild(moduleContext);
+                  }
+                  catch (IOException ignored)
+                  {
+                     throw new RuntimeException(fileName + " module listed in application.xml does not exist within .ear " + root.getName(), ignored);
+                  }
+               }
+            }
+
+            if (scan)
+            {
+               JARCandidateStructureVisitorFactory factory = new JARCandidateStructureVisitorFactory();
+               final J2eeApplicationMetaData my = metaData;
+               factory.setFilter(new VirtualFileFilter() {
+                  public boolean accepts(VirtualFile file)
+                  {
+                     if (my.hasModule(file.getName())) return false;
+                     return true;
+                  }
+               });
+               VirtualFileVisitor visitor = factory.createVisitor(context, null);
+               root.visit(visitor);
+            }
+
+            return true;
+         }
+         else
+         {
+            log.trace("... no - not a directory or an archive.");
+            return false;
+         }
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error determining structure: " + context.getName(), e);
+      }
+   }
+}

Added: trunk/server/src/main/org/jboss/deployment/JaccCommitDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/JaccCommitDeployer.java	2006-10-10 20:23:23 UTC (rev 57550)
+++ trunk/server/src/main/org/jboss/deployment/JaccCommitDeployer.java	2006-10-10 21:15:12 UTC (rev 57551)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.deployment;
+
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.logging.Logger;
+
+import javax.security.jacc.PolicyConfiguration;
+import javax.security.jacc.PolicyConfigurationFactory;
+import javax.security.jacc.PolicyContextException;
+import java.util.Set;
+
+/**
+ * Second phase of JACC Policy deployment.  If the DU has a policy attachment
+ * link it to any parent PC and then commit it.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 57082 $
+ */
+public class JaccCommitDeployer extends AbstractSimpleDeployer
+{
+   private static final Logger log = Logger.getLogger(JaccCommitDeployer.class);
+
+   public void deploy(DeploymentUnit unit) throws org.jboss.deployers.spi.DeploymentException
+   {
+      PolicyConfiguration pc = unit.getDeploymentContext().getTransientAttachments().getAttachment("javax.security.jacc.PolicyConfiguration", PolicyConfiguration.class);
+      if (pc == null) return;
+
+      PolicyConfiguration parentPc = unit.getDeploymentContext().getParent().getDeploymentUnit().getAttachment("javax.security.jacc.PolicyConfiguration", PolicyConfiguration.class);
+      try
+      {
+         if (parentPc != null && pc != parentPc)
+         {
+            parentPc.linkConfiguration(pc);
+         }
+         pc.commit();
+      }
+      catch (PolicyContextException e)
+      {
+         throw new RuntimeException("Failed to commit PolicyConfiguration for unit: " + unit.getName(), e);
+      }
+   }
+
+}

Added: trunk/server/src/main/org/jboss/deployment/JaccInitializationDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/JaccInitializationDeployer.java	2006-10-10 20:23:23 UTC (rev 57550)
+++ trunk/server/src/main/org/jboss/deployment/JaccInitializationDeployer.java	2006-10-10 21:15:12 UTC (rev 57551)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.deployment;
+
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.logging.Logger;
+
+import javax.security.jacc.PolicyConfigurationFactory;
+import javax.security.jacc.PolicyConfiguration;
+import javax.security.jacc.PolicyContextException;
+import java.util.Set;
+
+/**
+ * Create a JACC policy if the DeploymentUnit contains a named attachment
+ * for example, if it contains J2EEApplicationMetaData.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 57082 $
+ */
+public class JaccInitializationDeployer extends AbstractSimpleDeployer
+{
+   private static final Logger log = Logger.getLogger(JaccInitializationDeployer.class);
+
+   private Set<String> acceptedAttachments;
+
+   public Set<String> getAcceptedAttachments()
+   {
+      return acceptedAttachments;
+   }
+
+   public void setAcceptedAttachments(Set<String> acceptedAttachments)
+   {
+      this.acceptedAttachments = acceptedAttachments;
+   }
+
+   public void deploy(DeploymentUnit unit) throws org.jboss.deployers.spi.DeploymentException
+   {
+      boolean accepted = false;
+      for (String accept : acceptedAttachments)
+      {
+         if (unit.getDeploymentContext().getTransientAttachments().isAttachmentPresent(accept))
+         {
+            accepted = true;
+            break;
+         }
+      }
+      if (accepted == false) return;
+
+      String contextID = unit.getName();
+      PolicyConfiguration pc = null;
+      try
+      {
+         PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
+         pc = pcFactory.getPolicyConfiguration(contextID, true);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("failed to initialize JACC for unit: " + unit.getName(), e);
+      }
+      unit.getAttachment("");
+      unit.getDeploymentContext().getTransientAttachments().addAttachment("javax.security.jacc.PolicyConfiguration", pc);
+   }
+
+}




More information about the jboss-cvs-commits mailing list