Author: tolusha
Date: 2010-10-29 06:10:09 -0400 (Fri, 29 Oct 2010)
New Revision: 3366
Modified:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java
Log:
EXOJCR-986: Enable SecurityManager by default: fix
Modified:
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java
===================================================================
---
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java 2010-10-29
09:30:37 UTC (rev 3365)
+++
core/trunk/exo.core.component.script.groovy/src/test/java/org/exoplatform/services/script/groovy/jarjar/Script.java 2010-10-29
10:10:09 UTC (rev 3366)
@@ -23,10 +23,14 @@
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
+import org.codehaus.groovy.control.CompilationFailedException;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import java.io.IOException;
import java.net.URL;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -47,7 +51,7 @@
{
//
- JarJarClassLoader loader =
+ final JarJarClassLoader loader =
JarJarClassLoader.createJarJarClassLoaderInPrivilegedMode(Thread.currentThread().getContextClassLoader());
//
@@ -67,8 +71,36 @@
err.initCause(e);
throw err;
}
- Class testClass = loader.parseClass(gcs);
+ Class testClass;
+ try
+ {
+ final GroovyCodeSource gGcs = gcs;
+ testClass = SecurityHelper.doPriviledgedExceptionAction(new
PrivilegedExceptionAction<Class>()
+ {
+ public Class run() throws Exception
+ {
+ return loader.parseClass(gGcs);
+ }
+ });
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CompilationFailedException)
+ {
+ throw (CompilationFailedException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
// Instantiate script
GroovyObject testObject;
try
Show replies by date