[exo-jcr-commits] exo-jcr SVN: r4073 - in kernel/trunk: exo.kernel.component.common/src/main/java/org/exoplatform/services/naming and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 10 13:03:21 EST 2011


Author: tolusha
Date: 2011-03-10 13:03:20 -0500 (Thu, 10 Mar 2011)
New Revision: 4073

Modified:
   kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java
Log:
EXOJCR-1159: add privileged block of code

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-03-10 16:11:21 UTC (rev 4072)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java	2011-03-10 18:03:20 UTC (rev 4073)
@@ -28,6 +28,7 @@
 import java.security.PrivilegedExceptionAction;
 import java.sql.SQLException;
 
+import javax.naming.NamingException;
 import javax.xml.parsers.ParserConfigurationException;
 
 /**
@@ -73,13 +74,45 @@
    }
 
    /**
-    * Launches action in privileged mode. Can throw only IO exception.
+    * Launches action in privileged mode. Can throw only NamingException.
     * 
     * @param <E>
     * @param action
     * @return
     * @throws IOException
     */
+   public static <E> E doPrivilegedNamingExceptionAction(PrivilegedExceptionAction<E> action) throws NamingException
+   {
+      try
+      {
+         return AccessController.doPrivileged(action);
+      }
+      catch (PrivilegedActionException pae)
+      {
+         Throwable cause = pae.getCause();
+         if (cause instanceof NamingException)
+         {
+            throw (NamingException)cause;
+         }
+         else if (cause instanceof RuntimeException)
+         {
+            throw (RuntimeException)cause;
+         }
+         else
+         {
+            throw new RuntimeException(cause);
+         }
+      }
+   }
+
+   /**
+    * Launches action in privileged mode. Can throw only SQL exception.
+    * 
+    * @param <E>
+    * @param action
+    * @return
+    * @throws IOException
+    */
    public static <E> E doPrivilegedSQLExceptionAction(PrivilegedExceptionAction<E> action) throws SQLException
    {
       try

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java	2011-03-10 16:11:21 UTC (rev 4072)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/SimpleContext.java	2011-03-10 18:03:20 UTC (rev 4073)
@@ -18,6 +18,9 @@
  */
 package org.exoplatform.services.naming;
 
+import org.exoplatform.commons.utils.SecurityHelper;
+
+import java.security.PrivilegedExceptionAction;
 import java.util.Hashtable;
 
 import javax.naming.Binding;
@@ -57,12 +60,18 @@
       Object obj = objects.get(name);
       if (obj instanceof Reference)
       {
-         Reference ref = (Reference)obj;
+         final Reference ref = (Reference)obj;
          String factoryCN = ref.getFactoryClassName();
          try
          {
-            ObjectFactory factory = (ObjectFactory)Class.forName(factoryCN).newInstance();
-            obj = factory.getObjectInstance(ref, null, null, null);
+            final ObjectFactory factory = (ObjectFactory)Class.forName(factoryCN).newInstance();
+            obj = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Object>()
+            {
+               public Object run() throws Exception
+               {
+                  return factory.getObjectInstance(ref, null, null, null);
+               }
+            });
          }
          catch (Exception e)
          {



More information about the exo-jcr-commits mailing list