]> source.dussan.org Git - javassist.git/commitdiff
Make ProxyFactory use privileged blocks when a security manager is present
authorkkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 12 Feb 2008 17:06:13 +0000 (17:06 +0000)
committerkkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 12 Feb 2008 17:06:13 +0000 (17:06 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@419 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/util/proxy/ProxyFactory.java

index de6d96d1e8776d818042bcb03cafc699759a77ce..452768b722e72122d2438e687d06de0daf415e72 100644 (file)
@@ -21,6 +21,8 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Member;
 import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.util.HashMap;
 import java.util.WeakHashMap;
@@ -659,7 +661,7 @@ public class ProxyFactory {
     private void makeConstructors(String thisClassName, ClassFile cf,
             ConstPool cp, String classname) throws CannotCompileException
     {
-        Constructor[] cons = superClass.getDeclaredConstructors();
+        Constructor[] cons = SecurityActions.getDeclaredConstructors(superClass);
         for (int i = 0; i < cons.length; i++) {
             Constructor c = cons[i];
             int mod = c.getModifiers();
@@ -741,7 +743,7 @@ public class ProxyFactory {
         if (parent != null)
             getMethods(hash, parent);
 
-        Method[] methods = clazz.getDeclaredMethods();
+        Method[] methods = SecurityActions.getDeclaredMethods(clazz);
         for (int i = 0; i < methods.length; i++)
             if (!Modifier.isPrivate(methods[i].getModifiers())) {
                 Method m = methods[i];
@@ -1041,4 +1043,41 @@ public class ProxyFactory {
         minfo.setCodeAttribute(code.toCodeAttribute());
         return minfo;
     }
+    
+    private static class SecurityActions
+    {
+       private static Method[] getDeclaredMethods(final Class clazz)
+       {
+          if (System.getSecurityManager() == null)
+          {
+             return clazz.getDeclaredMethods();
+          }
+          else
+          {
+             return (Method[])AccessController.doPrivileged(new PrivilegedAction() {
+
+               public Object run()
+               {
+                  return clazz.getDeclaredMethods();
+               }});
+          }
+       }
+       
+       private static Constructor[] getDeclaredConstructors(final Class clazz)
+       {
+          if (System.getSecurityManager() == null)
+          {
+             return clazz.getDeclaredConstructors();
+          }
+          else
+          {
+             return (Constructor[])AccessController.doPrivileged(new PrivilegedAction() {
+
+               public Object run()
+               {
+                  return clazz.getDeclaredConstructors();
+               }});
+          }
+       }
+    }
 }