[exo-jcr-commits] exo-jcr SVN: r4440 - in kernel/trunk: exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri May 27 07:31:28 EDT 2011


Author: dkuleshov
Date: 2011-05-27 07:31:27 -0400 (Fri, 27 May 2011)
New Revision: 4440

Modified:
   kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java
   kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
   kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedSystemHelper.java
   kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
   kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommandService.java
   kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommonsXMLConfigurationPlugin.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/impl/QuartzSheduler.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/util/PrivilegedCacheHelper.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
Log:
EXOJCR-1186: source code has been reworked to increase performance

Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -26,7 +26,6 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.RandomAccessFile;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -60,7 +59,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -98,7 +97,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -136,7 +135,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -175,7 +174,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -213,7 +212,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -251,7 +250,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -289,7 +288,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -327,7 +326,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -370,7 +369,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -416,7 +415,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -461,7 +460,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -500,7 +499,7 @@
             return new Long(file.length());
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -519,7 +518,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -537,7 +536,7 @@
             return file.getAbsolutePath();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -558,7 +557,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -593,7 +592,7 @@
             return file.delete();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -612,7 +611,7 @@
             return file.isDirectory();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -631,7 +630,7 @@
             return file.exists();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -649,7 +648,7 @@
             return file.mkdirs();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -668,7 +667,7 @@
             return new Boolean(srcFile.renameTo(dstfile));
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -686,7 +685,7 @@
             return file.list();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -704,7 +703,7 @@
             return file.list(filter);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -722,7 +721,7 @@
             return file.listFiles();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -740,7 +739,7 @@
             return file.listFiles(filter);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -758,6 +757,6 @@
             return file.listFiles(filter);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 }

Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedSystemHelper.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedSystemHelper.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedSystemHelper.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -20,7 +20,6 @@
 
 import java.io.InputStream;
 import java.net.URL;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Properties;
 
@@ -47,7 +46,7 @@
             return System.getProperty(key);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -65,7 +64,7 @@
             return System.getProperties();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -84,7 +83,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -103,7 +102,7 @@
             return System.getProperty(key, def);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -122,7 +121,7 @@
             return Thread.currentThread().getContextClassLoader().getResource(name);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -141,7 +140,7 @@
             return Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 
 }

Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -53,7 +53,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -85,7 +85,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -117,7 +117,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -150,7 +150,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -187,7 +187,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -219,7 +219,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -252,7 +252,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(action);
+         return doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -281,9 +281,14 @@
     */
    public static <E> E doPrivilegedAction(PrivilegedAction<E> action)
    {
-      return AccessController.doPrivileged(action);
+//      if (System.getSecurityManager() != null)
+      {
+         // A security manager has been established
+         return AccessController.doPrivileged(action);
+      }
+//      return action.run();
    }
-   
+
    /**
     * Launches action in privileged mode. 
     * 
@@ -294,7 +299,18 @@
    public static <E> E doPrivilegedExceptionAction(PrivilegedExceptionAction<E> action)
       throws PrivilegedActionException
    {
-      return AccessController.doPrivileged(action);
+//      if (System.getSecurityManager() != null)
+      {
+         // A security manager has been established
+         return AccessController.doPrivileged(action);
+      }
+/*    try
+      {
+         return action.run();
+      }
+      catch (Exception e)
+      {
+         throw new PrivilegedActionException(e);
+      }*/
    }
-   
 }

Modified: kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java
===================================================================
--- kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -18,15 +18,32 @@
  */
 package org.exoplatform.commons.test;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.security.Permission;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
 
 /**
+ * You can exclude methods by adding the file <code>tsm-excludes.properties</code> into the classpath. The expected format is:
+ * <code>
+ * ${fqn-of-the-class}.${method-name}=${called-method-name}(,${called-method-name})*
+ * </code>
+ * 
  * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
  * @version $Id: TestSecurityManager.java 2636 2010-06-16 14:18:23Z tolusha $
  *
  */
 public class TestSecurityManager extends SecurityManager
 {
+   /**
+    * Map of methods to exclude and for each method we define a list of method called to ignore
+    */
+   private final Map<String, Set<String>> excludes = getExcludes();
 
    /**
     * {@inheritDoc}
@@ -52,7 +69,14 @@
             {
                String className = traceElements[i].getClassName();
                String fileName = traceElements[i].getFileName();
-
+               String methodName = traceElements[i].getMethodName();
+               if (excludes != null && i - 1 >= 0
+                  && excludes.containsKey(className + "." + methodName)
+                  && excludes.get(className + "." + methodName).contains(traceElements[i - 1].getMethodName()))
+               {
+                  // the called method is excluded thus we ignore the exception
+                  return;
+               }
                if (className.startsWith("org.exoplatform"))
                {
                   // known tests classes
@@ -101,4 +125,52 @@
          throw se;
       }
    }
+
+   /**
+    * @return
+    */
+   private Map<String, Set<String>> getExcludes()
+   {
+      InputStream is = null;
+      try
+      {
+         is = Thread.currentThread().getContextClassLoader().getResourceAsStream("tsm-excludes.properties");
+      }
+      catch (Exception e)
+      {
+         // ignore me
+      }
+      if (is != null)
+      {
+         try
+         {
+            System.out.println("A file 'tsm-excludes.properties' has been found"); //NOSONAR
+            Properties p = new Properties();
+            p.load(is);
+            Map<String, Set<String>> excludes = new HashMap<String, Set<String>>();
+            for (Object key : p.keySet())
+            {
+               String[] values = p.getProperty((String)key).split(",");
+               excludes.put((String)key, new HashSet<String>(Arrays.asList(values)));
+            }
+            return excludes;
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace(); //NOSONAR
+         }
+         finally
+         {
+            try
+            {
+               is.close();
+            }
+            catch (IOException e)
+            {
+               // ignore me
+            }
+         }         
+      }
+      return null;
+   }
 }

Modified: kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommandService.java
===================================================================
--- kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommandService.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommandService.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -23,12 +23,12 @@
 import org.apache.commons.chain.config.ConfigParser;
 import org.apache.commons.chain.impl.CatalogFactoryBase;
 import org.apache.commons.digester.Digester;
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.container.component.ComponentPlugin;
 import org.xml.sax.SAXException;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -56,7 +56,7 @@
       this.catalogFactory = CatalogFactoryBase.getInstance();
 
       final ConfigParser parser = new ConfigParser();
-      this.digester = AccessController.doPrivileged(new PrivilegedAction<Digester>()
+      this.digester = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Digester>()
       {
          public Digester run()
          {
@@ -98,7 +98,7 @@
 
       try
       {
-         AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+         SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
          {
             public Void run() throws Exception
             {

Modified: kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommonsXMLConfigurationPlugin.java
===================================================================
--- kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommonsXMLConfigurationPlugin.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.command/src/main/java/org/exoplatform/services/command/impl/CommonsXMLConfigurationPlugin.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.command.impl;
 
 import org.apache.commons.chain.config.ConfigParser;
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.container.xml.InitParams;
@@ -27,7 +28,6 @@
 import org.exoplatform.services.log.Log;
 
 import java.net.URL;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 
@@ -57,7 +57,7 @@
          final ConfigParser parser = new ConfigParser();
          // may work for StandaloneContainer
          
-         URL res = AccessController.doPrivileged(new PrivilegedAction<URL>()
+         URL res = SecurityHelper.doPrivilegedAction(new PrivilegedAction<URL>()
          {
             public URL run()
             {
@@ -73,7 +73,7 @@
          log.info("Catalog configuration found at " + res);
          
          final URL fRes = res;
-         AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+         SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
          {
             public Void run() throws Exception
             {

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -54,7 +54,6 @@
 import java.io.ObjectOutput;
 import java.io.Serializable;
 import java.net.URL;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -224,7 +223,7 @@
 
       try
       {
-         this.configurator = AccessController.doPrivileged(new PrivilegedExceptionAction<ProtocolStackConfigurator>()
+         this.configurator = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<ProtocolStackConfigurator>()
          {
             public ProtocolStackConfigurator run() throws Exception
             {
@@ -428,7 +427,7 @@
       }
       final Message msg = new Message();
       msg.setObject(new MessageBody(dests.size() == 1 && dests != members ? dests.get(0) : null, commandId, args));
-      RspList rsps = AccessController.doPrivileged(new PrivilegedAction<RspList>()
+      RspList rsps = SecurityHelper.doPrivilegedAction(new PrivilegedAction<RspList>()
       {
          public RspList run()
          {
@@ -703,7 +702,7 @@
 
       try
       {
-         AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+         SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
          {
             public Void run() throws Exception
             {
@@ -755,19 +754,11 @@
       {
          if (LOG.isInfoEnabled())
             LOG.info("Disconnecting and closing the Channel");
-         AccessController.doPrivileged(new PrivilegedAction<Void>()
-         {
-            public Void run()
-            {
-               channel.disconnect();
-               return null;
-            }
-         });
-
          SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
          {
             public Void run()
             {
+               channel.disconnect();
                channel.close();
                return null;
             }

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/impl/QuartzSheduler.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/impl/QuartzSheduler.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/impl/QuartzSheduler.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.scheduler.impl;
 
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.container.BaseContainerLifecyclePlugin;
 import org.exoplatform.container.ExoContainer;
 import org.exoplatform.container.ExoContainerContext;
@@ -29,7 +30,6 @@
 import org.quartz.SchedulerFactory;
 import org.quartz.impl.StdSchedulerFactory;
 
-import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
@@ -51,7 +51,7 @@
 
       try
       {
-         scheduler_ = AccessController.doPrivileged(new PrivilegedExceptionAction<Scheduler>()
+         scheduler_ = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Scheduler>()
          {
             public Scheduler run() throws Exception
             {

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -24,8 +24,6 @@
 import org.exoplatform.services.log.Log;
 import org.exoplatform.services.transaction.TransactionService;
 
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
 import javax.transaction.HeuristicMixedException;
@@ -111,49 +109,14 @@
       final Transaction tx = tm.getTransaction();
       if (tx != null)
       {
-         PrivilegedExceptionAction<Boolean> action = new PrivilegedExceptionAction<Boolean>()
+         int flag = XAResource.TMSUCCESS;
+         switch (tx.getStatus())
          {
-            public Boolean run() throws Exception
-            {
-               int flag = XAResource.TMSUCCESS;
-               switch (tx.getStatus())
-               {
-                  case Status.STATUS_MARKED_ROLLBACK:
-                  case Status.STATUS_ROLLEDBACK:
-                  case Status.STATUS_ROLLING_BACK: flag = XAResource.TMFAIL;                     
-               }      
-               return tx.delistResource(xares, flag);
-            }
-         };
-         try
-         {
-            return AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-
-            if (cause instanceof RollbackException)
-            {
-               throw (RollbackException)cause;
-            }
-            else if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+            case Status.STATUS_MARKED_ROLLBACK:
+            case Status.STATUS_ROLLEDBACK:
+            case Status.STATUS_ROLLING_BACK: flag = XAResource.TMFAIL;                     
+         }      
+         return tx.delistResource(xares, flag);
       }
       else
       {
@@ -170,42 +133,7 @@
       final Transaction tx = tm.getTransaction();
       if (tx != null)
       {
-         PrivilegedExceptionAction<Boolean> action = new PrivilegedExceptionAction<Boolean>()
-         {
-            public Boolean run() throws Exception
-            {               
-               return tx.enlistResource(xares);
-            }
-         };
-         try
-         {
-            return AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-
-            if (cause instanceof RollbackException)
-            {
-               throw (RollbackException)cause;
-            }
-            else if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         return tx.enlistResource(xares);
       }
       else
       {
@@ -386,38 +314,7 @@
          }
 
          // Start the transaction
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.begin();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof NotSupportedException)
-            {
-               throw (NotSupportedException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.begin();
       }
 
       /**
@@ -426,54 +323,7 @@
       public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
          SecurityException, IllegalStateException, SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.commit();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof RollbackException)
-            {
-               throw (RollbackException)cause;
-            }
-            else if (cause instanceof HeuristicMixedException)
-            {
-               throw (HeuristicMixedException)cause;
-            }
-            else if (cause instanceof HeuristicRollbackException)
-            {
-               throw (HeuristicRollbackException)cause;
-            }
-            else if (cause instanceof SecurityException)
-            {
-               throw (SecurityException)cause;
-            }
-            else if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.commit();
       }
 
       /**
@@ -489,32 +339,7 @@
        */
       public Transaction getTransaction() throws SystemException
       {
-         try
-         {
-            return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Transaction>()
-            {
-               public Transaction run() throws Exception
-               {
-                  return tm.getTransaction();
-               }
-            });
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         return tm.getTransaction();
       }
 
       /**
@@ -523,42 +348,7 @@
       public void resume(final Transaction tx) throws InvalidTransactionException, IllegalStateException,
          SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.resume(tx);
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof InvalidTransactionException)
-            {
-               throw (InvalidTransactionException)cause;
-            }
-            else if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.resume(tx);
       }
 
       /**
@@ -566,42 +356,7 @@
        */
       public void rollback() throws IllegalStateException, SecurityException, SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.rollback();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SecurityException)
-            {
-               throw (SecurityException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.rollback();
       }
 
       /**
@@ -626,33 +381,7 @@
        */
       public Transaction suspend() throws SystemException
       {
-         PrivilegedExceptionAction<Transaction> action = new PrivilegedExceptionAction<Transaction>()
-         {
-            public Transaction run() throws Exception
-            {
-               return tm.suspend();
-            }
-         };
-         try
-         {
-            return AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         return tm.suspend();
       }
    }
    
@@ -685,38 +414,7 @@
        */
       public void begin() throws NotSupportedException, SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.begin();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof NotSupportedException)
-            {
-               throw (NotSupportedException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.begin();
       }
 
       /**
@@ -725,54 +423,7 @@
       public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
          SecurityException, IllegalStateException, SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.commit();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof RollbackException)
-            {
-               throw (RollbackException)cause;
-            }
-            else if (cause instanceof HeuristicMixedException)
-            {
-               throw (HeuristicMixedException)cause;
-            }
-            else if (cause instanceof HeuristicRollbackException)
-            {
-               throw (HeuristicRollbackException)cause;
-            }
-            else if (cause instanceof SecurityException)
-            {
-               throw (SecurityException)cause;
-            }
-            else if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.commit();
       }
 
       /**
@@ -780,42 +431,7 @@
        */
       public void rollback() throws IllegalStateException, SecurityException, SystemException
       {
-         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               tm.rollback();
-               return null;
-            }
-         };
-         try
-         {
-            AccessController.doPrivileged(action);
-         }
-         catch (PrivilegedActionException pae)
-         {
-            Throwable cause = pae.getCause();
-            if (cause instanceof IllegalStateException)
-            {
-               throw (IllegalStateException)cause;
-            }
-            else if (cause instanceof SecurityException)
-            {
-               throw (SecurityException)cause;
-            }
-            else if (cause instanceof SystemException)
-            {
-               throw (SystemException)cause;
-            }
-            else if (cause instanceof RuntimeException)
-            {
-               throw (RuntimeException)cause;
-            }
-            else
-            {
-               throw new RuntimeException(cause);
-            }
-         }
+         tm.rollback();
       }
 
       /**

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/util/PrivilegedCacheHelper.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/util/PrivilegedCacheHelper.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/util/PrivilegedCacheHelper.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.cache.impl.jboss.util;
 
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheException;
 import org.jboss.cache.CacheFactory;
@@ -26,7 +27,6 @@
 import org.jboss.cache.config.ConfigurationException;
 
 import java.io.InputStream;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -53,7 +53,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -71,7 +71,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -89,7 +89,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -107,7 +107,7 @@
             return null;
          }
       };
-      AccessController.doPrivileged(action);
+      SecurityHelper.doPrivilegedAction(action);
    }
 
    /**
@@ -127,7 +127,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -164,7 +164,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -200,7 +200,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -236,7 +236,7 @@
       };
       try
       {
-         return AccessController.doPrivileged(action);
+         return SecurityHelper.doPrivilegedExceptionAction(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -270,6 +270,6 @@
             return new DefaultCacheFactory<K, V>();
          }
       };
-      return AccessController.doPrivileged(action);
+      return SecurityHelper.doPrivilegedAction(action);
    }
 }

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -39,7 +39,6 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URL;
-import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
@@ -160,7 +159,7 @@
          DocumentBuilder builder = null;
          try
          {
-            builder = AccessController.doPrivileged(new PrivilegedExceptionAction<DocumentBuilder>()
+            builder = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<DocumentBuilder>()
             {
                public DocumentBuilder run() throws Exception
                {
@@ -264,7 +263,7 @@
       final DocumentBuilderFactory builderFactory = factory;
       try
       {
-         return AccessController.doPrivileged(new PrivilegedExceptionAction<Configuration>()
+         return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Configuration>()
          {
             public Configuration run() throws Exception
             {

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/management/jmx/impl/JMXManagementProvider.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -25,7 +25,6 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
-import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.LinkedHashMap;
@@ -174,7 +173,7 @@
          }
          try
          {
-            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+            SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
             {
                public Void run() throws Exception
                {
@@ -197,7 +196,7 @@
       {
          try
          {
-            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+            SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
             {
                public Void run() throws Exception
                {

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2011-05-27 11:15:05 UTC (rev 4439)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2011-05-27 11:31:27 UTC (rev 4440)
@@ -31,7 +31,6 @@
 import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -278,7 +277,7 @@
    {
       try
       {
-         return AccessController.doPrivileged(new PrivilegedExceptionAction<IBindingFactory>()
+         return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<IBindingFactory>()
          {
             public IBindingFactory run() throws Exception
             {



More information about the exo-jcr-commits mailing list