From: kkhan Date: Tue, 12 Feb 2008 17:06:13 +0000 (+0000) Subject: Make ProxyFactory use privileged blocks when a security manager is present X-Git-Tag: rel_3_17_1_ga~223 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1d2f91432f09742e864f221aee8f66f9205f7fd4;p=javassist.git Make ProxyFactory use privileged blocks when a security manager is present git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@419 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index de6d96d1..452768b7 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -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(); + }}); + } + } + } }