[jboss-cvs] JBossAS SVN: r60923 - in projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers: plugins/deployers/helpers and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 26 18:19:22 EST 2007


Author: scott.stark at jboss.org
Date: 2007-02-26 18:19:21 -0500 (Mon, 26 Feb 2007)
New Revision: 60923

Added:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/SecurityActions.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/SecurityActions.java
Modified:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/DefaultStructureBuilder.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractCandidateStructureVisitor.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractStructureDeployer.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/DeclaredStructure.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/FileStructure.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/JARStructure.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/WARStructure.java
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
Log:
JBMICROCONT-150, add priviledged blocks around the vfs calls

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -356,6 +356,15 @@
       return result;
    }
 
+   public DeploymentUnit getParent()
+   {
+      DeploymentContext parentCtx = deploymentContext.getParent();
+      DeploymentUnit parent = null;
+      if( parentCtx != null )
+         parent = parentCtx.getDeploymentUnit();
+      return parent;
+   }
+
    @Deprecated
    public DeploymentContext getDeploymentContext()
    {

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -151,14 +151,7 @@
     */
    protected T parse(DeploymentUnit unit, VirtualFile file, T root) throws Exception
    {
-      // First look for an existing Document attachment 
-      Document document = unit.getAttachment(Document.class);
-      if( document == null )
-      {
-         // Next parse the metadata file
-         document = doParse(unit, file);
-      }
-
+      Document document = doParse(unit, file);
       // Transform the document into a T instance
       return parse(unit, file, document);
    }
@@ -176,25 +169,35 @@
       if (file == null)
          throw new IllegalArgumentException("Null file");
       
-      InputStream is = file.openStream();
-      try
+      // First look for an existing Document attachment 
+      Document document = unit.getAttachment(Document.class);
+      if( document == null )
       {
-         DocumentBuilder parser = getDocumentBuilderFactory().newDocumentBuilder();
-         InputSource source = new InputSource(is);
-         source.setSystemId(file.toURI().toString());
-         parser.setEntityResolver(new JBossEntityResolver());
-         return parser.parse(is);
-      }
-      finally
-      {
+         // Next parse the metadata file
+         InputStream is = SecurityActions.openStream(file);
          try
          {
-            is.close();
+            DocumentBuilder parser = getDocumentBuilderFactory().newDocumentBuilder();
+            InputSource source = new InputSource(is);
+            source.setSystemId(file.toURI().toString());
+            parser.setEntityResolver(new JBossEntityResolver());
+            document = parser.parse(is);
          }
-         catch (Exception ignored)
+         finally
          {
+            try
+            {
+               is.close();
+            }
+            catch (Exception ignored)
+            {
+            }
          }
       }
+      // Save dom view
+      if( document != null )
+         unit.addAttachment(Document.class, document);
+      return document;
    }
 
    /**

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.deployers.helpers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public InputStream openStream(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>()
+               {
+                  public InputStream run() throws Exception
+                  {
+                     return f.openStream();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public InputStream openStream(VirtualFile f) throws IOException
+         {
+            return f.openStream();
+         }
+      };
+
+      public InputStream openStream(VirtualFile f) throws IOException;
+   } 
+
+   static InputStream openStream(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.openStream(f);
+      else
+         return FileActions.NON_PRIVILEGED.openStream(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -107,11 +107,11 @@
    private Attachments predeterminedManagedObjects = new AttachmentsImpl();
    
    /** The attachments */
-   private transient Attachments transientAttachments = new AttachmentsImpl();
+   private transient Attachments transientAttachments =
+      GeneratedAOPProxyFactory.createProxy(new AttachmentsImpl(), Attachments.class);
    
    /** The managed objects */
-   private transient Attachments transientManagedObjects =
-      GeneratedAOPProxyFactory.createProxy(new AttachmentsImpl(), Attachments.class);
+   private transient Attachments transientManagedObjects = new AttachmentsImpl();
 
    /** Throwable */
    private Throwable problem;
@@ -631,7 +631,7 @@
          if (metaDataLocation == null)
          {
             // It has to be a plain file
-            if (root != null && root.isLeaf())
+            if (root != null && SecurityActions.isLeaf(root))
             {
                String fileName = root.getName();
                if (fileName.equals(name))

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/DefaultStructureBuilder.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/DefaultStructureBuilder.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/DefaultStructureBuilder.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -163,7 +163,7 @@
          try
          {
             // Process any Manifest Class-Path refs on the context itself
-            if( virtualFile.isLeaf() == false )
+            if( SecurityActions.isLeaf(virtualFile) == false )
                VFSUtils.addManifestLocations(virtualFile, paths);
          }
          catch(IOException ignore)

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractCandidateStructureVisitor.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractCandidateStructureVisitor.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractCandidateStructureVisitor.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -146,7 +146,7 @@
          // Ignore directories when asked
          try
          {
-            if (ignoreDirectories && file.isLeaf() == false)
+            if (ignoreDirectories && SecurityActions.isLeaf(file) == false)
                return;
          }
          catch (IOException e)

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractStructureDeployer.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractStructureDeployer.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/AbstractStructureDeployer.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -131,7 +131,7 @@
       if( includeEntry )
          paths.add(entry);
       String rootPath = root.getPathName();
-      if( includeRootManifestCP && entry.isLeaf() == false )
+      if( includeRootManifestCP && SecurityActions.isLeaf(entry) == false )
       {
          try
          {

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure.vfs;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/DeclaredStructure.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/DeclaredStructure.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/DeclaredStructure.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -55,8 +55,12 @@
    {
       try
       {
-         if( root.isLeaf() == false )
+         boolean trace = log.isTraceEnabled();
+         if( SecurityActions.isLeaf(root) == false )
          {
+            boolean isJBossStructure = false;
+            if( trace )
+               log.trace(root+" is not a leaf");
             try
             {
                VirtualFile jbossStructure = root.findChild("META-INF/jboss-structure.xml");
@@ -67,13 +71,16 @@
                StructureMetaDataObjectFactory ofactory = new StructureMetaDataObjectFactory();
                unmarshaller.unmarshal(url.toString(), ofactory, metaData);
                activeMetaData.set(metaData);
+               isJBossStructure = true;
             }
             catch (IOException e)
             {
-               log.trace("... no META-INF subdirectory.");
-               return false;
+               if( trace )
+                  log.trace("... no META-INF subdirectory.");
             }
-            return true;
+            if( trace )
+               log.trace(root+" isJBossStructure: "+isJBossStructure);
+            return isJBossStructure;
          }
       }
       catch (Exception e)

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure.vfs.explicit;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/explicit/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/FileStructure.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/FileStructure.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/FileStructure.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -123,35 +123,46 @@
    {
       try
       {
-         if (root.isLeaf())
+         boolean trace = log.isTraceEnabled();
+         if( SecurityActions.isLeaf(root) == true )
          {
+            boolean isFile = false;
+            if( trace )
+               log.trace(root+" is not a leaf");
             // See if this is a top-level by checking the parent
             if (isTopLevel(root, metaData) == false)
             {
                if (isKnownFile(root.getName()) == false)
                {
-                  log.trace("... no - it is not a top level file and not a known name");
-                  return false;
+                  if( trace )
+                     log.trace("... no - it is not a top level file and not a known name");
                }
                else
                {
-                  log.trace("... ok - not a top level file but it is a known name");
+                  if( trace )
+                     log.trace("... ok - not a top level file but it is a known name");
+                  isFile = true;
                }
             }
             else
             {
-               log.trace("... ok - it is a top level file");
+               if( trace )
+                  log.trace("... ok - it is a top level file");
+               isFile = true;
             }
 
             // Create a context info for this file
             ContextInfoImpl context = new ContextInfoImpl(root.getPathName());
             metaData.addContext(context);
             // There are no subdeployments for files
-            return true;
+            if( trace )
+               log.trace(root+" isFile: "+isFile);
+            return isFile;
          }
          else
          {
-            log.trace("... no - not a file.");
+            if( trace )
+               log.trace("... no - not a file.");
             return false;
          }
       }

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure.vfs.file;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/file/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/JARStructure.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/JARStructure.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/JARStructure.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -80,7 +80,7 @@
       String contextPath = null;
       try
       {
-         if (root.isLeaf() == false)
+         if (SecurityActions.isLeaf(root) == false)
          {
             // For non top level directories that don't look like jars
             // we require a META-INF otherwise each subdirectory would be a subdeployment

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure.vfs.jar;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/jar/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/SecurityActions.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.deployers.plugins.structure.vfs.war;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SecurityActions
+{
+   /**
+    * Actions for File access 
+    */
+   interface FileActions 
+   { 
+      FileActions PRIVILEGED = new FileActions() 
+      { 
+         public Boolean isLeaf(final VirtualFile f) throws IOException
+         {
+            try 
+            { 
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
+               {
+                  public Boolean run() throws Exception
+                  {
+                     return f.isLeaf();
+                  }
+               });
+            }
+            catch(PrivilegedActionException e) 
+            { 
+               Exception ex = e.getException();
+               if( ex instanceof IOException ) 
+                  throw (IOException) ex; 
+               else if( ex instanceof RuntimeException )
+                  throw (RuntimeException) ex;
+               else
+                  throw new UndeclaredThrowableException(ex); 
+            } 
+         }
+      }; 
+
+      FileActions NON_PRIVILEGED = new FileActions() 
+      {
+         public Boolean isLeaf(VirtualFile f) throws IOException
+         {
+            return f.isLeaf();
+         }
+         
+      };
+
+      public Boolean isLeaf(VirtualFile f) throws IOException;
+   } 
+
+   static boolean isLeaf(VirtualFile f) throws IOException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if( sm != null )
+         return FileActions.PRIVILEGED.isLeaf(f);
+      else
+         return FileActions.NON_PRIVILEGED.isLeaf(f);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/WARStructure.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/WARStructure.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/vfs/war/WARStructure.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -84,7 +84,7 @@
    {
       try
       {
-         if (root.isLeaf() == false)
+         if( SecurityActions.isLeaf(root) == false )
          {
             // We require either a WEB-INF or the name ends in .war
             if (root.getName().endsWith(".war") == false)

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2007-02-26 22:35:16 UTC (rev 60922)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2007-02-26 23:19:21 UTC (rev 60923)
@@ -165,8 +165,14 @@
     * @throws IllegalArgumentException for a null name
     */
    boolean removeComponent(String name);
-   
+
    /**
+    * 
+    * @return
+    */
+   public DeploymentUnit getParent();
+
+   /**
     * Get the deployment contxt
     * 
     * @return the deployment context




More information about the jboss-cvs-commits mailing list