From do-not-reply at jboss.org Wed Jun 23 09:11:49 2010 Content-Type: multipart/mixed; boundary="===============2279518744045359885==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r2689 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy. Date: Wed, 23 Jun 2010 09:11:44 -0400 Message-ID: <201006231311.o5NDBirf026494@svn01.web.mwc.hst.phx2.redhat.com> --===============2279518744045359885== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/r= est/ext/groovy/DefaultGroovyResourceLoader.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ex= t/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/ex= t/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 Andrey Parfonov - * @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 MalformedURLExcepti= on + public final URL loadGroovySource(String classname) throws MalformedURL= Exception { - filename =3D filename.replace('.', File.separatorChar) + ".groovy"; + final String filename =3D classname.replace('.', File.separatorChar)= + ".groovy"; + try + { + return AccessController.doPrivileged(new PrivilegedExceptionActio= n() + { + public URL run() throws Exception + { + return getResource(filename); + } + }); + } + catch (PrivilegedActionException e) + { + Throwable cause =3D 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 =3D filename.intern(); URL resource =3D null; synchronized (filename) @@ -81,7 +108,6 @@ { resource =3D new URL(root, filename); } - //System.out.println(resource); try { InputStream script =3D resource.openStream(); @@ -103,6 +129,7 @@ resources.remove(filename); } } + return resource; } = --===============2279518744045359885==--