[exo-jcr-commits] exo-jcr SVN: r2689 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jun 23 09:11:44 EDT 2010


Author: aparfonov
Date: 2010-06-23 09:11:43 -0400 (Wed, 23 Jun 2010)
New Revision: 2689

Modified:
   ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
Log:
EXOJCR-482 : use doPrivileged for loading resources

Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java	2010-06-23 12:54:39 UTC (rev 2688)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java	2010-06-23 13:11:43 UTC (rev 2689)
@@ -26,13 +26,17 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 /**
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
- * @version $Id$
+ * @version $Id: DefaultGroovyResourceLoader.java 2680 2010-06-22 11:43:00Z
+ *          aparfonov $
  */
 public class DefaultGroovyResourceLoader implements GroovyResourceLoader
 {
@@ -66,9 +70,32 @@
    /**
     * {@inheritDoc}
     */
-   public URL loadGroovySource(String filename) throws MalformedURLException
+   public final URL loadGroovySource(String classname) throws MalformedURLException
    {
-      filename = filename.replace('.', File.separatorChar) + ".groovy";
+      final String filename = classname.replace('.', File.separatorChar) + ".groovy";
+      try
+      {
+         return AccessController.doPrivileged(new PrivilegedExceptionAction<URL>()
+         {
+            public URL run() throws Exception
+            {
+               return getResource(filename);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         Throwable cause = e.getCause();
+         if (cause instanceof Error)
+            throw (Error)cause;
+         if (cause instanceof RuntimeException)
+            throw (RuntimeException)cause;
+         throw (MalformedURLException)cause;
+      }
+   }
+
+   protected URL getResource(String filename) throws MalformedURLException
+   {
       filename = filename.intern();
       URL resource = null;
       synchronized (filename)
@@ -81,7 +108,6 @@
             {
                resource = new URL(root, filename);
             }
-            //System.out.println(resource);
             try
             {
                InputStream script = resource.openStream();
@@ -103,6 +129,7 @@
             resources.remove(filename);
          }
       }
+
       return resource;
    }
 



More information about the exo-jcr-commits mailing list