[jboss-cvs] JBossAS SVN: r64492 - projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 7 22:55:25 EDT 2007
Author: adrian at jboss.org
Date: 2007-08-07 22:55:25 -0400 (Tue, 07 Aug 2007)
New Revision: 64492
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/SecurityActions.java
Log:
Fix the security actions for the CFlow tests
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/SecurityActions.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/SecurityActions.java 2007-08-08 02:54:49 UTC (rev 64491)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/SecurityActions.java 2007-08-08 02:55:25 UTC (rev 64492)
@@ -21,8 +21,11 @@
*/
package org.jboss.aop.pointcut;
+import java.lang.reflect.AccessibleObject;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
*
@@ -33,15 +36,59 @@
{
static Class loadClass(String name)
{
- try
+ if (System.getSecurityManager() == null)
{
- return getContextClassLoader().loadClass(name);
+ return LoadClassAction.NON_PRIVILEGED.loadClass(name);
}
- catch (ClassNotFoundException e)
+ else
{
- throw new RuntimeException(e);
+ return LoadClassAction.PRIVILEGED.loadClass(name);
}
}
+
+ interface LoadClassAction
+ {
+ Class loadClass(String name);
+
+ LoadClassAction PRIVILEGED = new LoadClassAction()
+ {
+ public Class loadClass(final String name)
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>()
+ {
+ public Class run() throws Exception
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException("Unable to load class " + name, e.getException());
+ }
+ }
+ };
+
+ LoadClassAction NON_PRIVILEGED = new LoadClassAction()
+ {
+ public Class loadClass(String name)
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Unable to load class " + name, e);
+ }
+ }
+ };
+ }
+ static void setAccessible(AccessibleObject accessibleObject)
+ {
+ }
public static class GetContextClassLoaderAction implements PrivilegedAction<ClassLoader>
{
More information about the jboss-cvs-commits
mailing list