[exo-jcr-commits] exo-jcr SVN: r4454 - kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue May 31 02:49:59 EDT 2011


Author: dkuleshov
Date: 2011-05-31 02:49:58 -0400 (Tue, 31 May 2011)
New Revision: 4454

Modified:
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java
Log:
EXOJCR-1365: wrapped code blocks into privileged sections to allow to get sys props

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-31 06:41:06 UTC (rev 4453)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/AbstractTransactionService.java	2011-05-31 06:49:58 UTC (rev 4454)
@@ -24,6 +24,7 @@
 import org.exoplatform.services.log.Log;
 import org.exoplatform.services.transaction.TransactionService;
 
+import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
 import javax.transaction.HeuristicMixedException;
@@ -109,14 +110,49 @@
       final Transaction tx = tm.getTransaction();
       if (tx != null)
       {
-         int flag = XAResource.TMSUCCESS;
-         switch (tx.getStatus())
+         PrivilegedExceptionAction<Boolean> action = new PrivilegedExceptionAction<Boolean>()
          {
-            case Status.STATUS_MARKED_ROLLBACK:
-            case Status.STATUS_ROLLEDBACK:
-            case Status.STATUS_ROLLING_BACK: flag = XAResource.TMFAIL;                     
-         }      
-         return tx.delistResource(xares, flag);
+            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 SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
       else
       {
@@ -133,7 +169,42 @@
       final Transaction tx = tm.getTransaction();
       if (tx != null)
       {
-         return tx.enlistResource(xares);
+         PrivilegedExceptionAction<Boolean> action = new PrivilegedExceptionAction<Boolean>()
+         {
+            public Boolean run() throws Exception
+            {               
+               return tx.enlistResource(xares);
+            }
+         };
+         try
+         {
+            return SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
       else
       {
@@ -314,7 +385,38 @@
          }
 
          // Start the transaction
-         tm.begin();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.begin();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -323,7 +425,54 @@
       public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
          SecurityException, IllegalStateException, SystemException
       {
-         tm.commit();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.commit();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -339,7 +488,32 @@
        */
       public Transaction getTransaction() throws SystemException
       {
-         return tm.getTransaction();
+         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);
+            }
+         }
       }
 
       /**
@@ -348,7 +522,42 @@
       public void resume(final Transaction tx) throws InvalidTransactionException, IllegalStateException,
          SystemException
       {
-         tm.resume(tx);
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.resume(tx);
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -356,7 +565,42 @@
        */
       public void rollback() throws IllegalStateException, SecurityException, SystemException
       {
-         tm.rollback();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.rollback();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -381,7 +625,33 @@
        */
       public Transaction suspend() throws SystemException
       {
-         return tm.suspend();
+         PrivilegedExceptionAction<Transaction> action = new PrivilegedExceptionAction<Transaction>()
+         {
+            public Transaction run() throws Exception
+            {
+               return tm.suspend();
+            }
+         };
+         try
+         {
+            return SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
    }
    
@@ -414,7 +684,38 @@
        */
       public void begin() throws NotSupportedException, SystemException
       {
-         tm.begin();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.begin();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -423,7 +724,54 @@
       public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
          SecurityException, IllegalStateException, SystemException
       {
-         tm.commit();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.commit();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**
@@ -431,7 +779,42 @@
        */
       public void rollback() throws IllegalStateException, SecurityException, SystemException
       {
-         tm.rollback();
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               tm.rollback();
+               return null;
+            }
+         };
+         try
+         {
+            SecurityHelper.doPrivilegedExceptionAction(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);
+            }
+         }
       }
 
       /**



More information about the exo-jcr-commits mailing list