summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2008-02-12 17:06:13 +0000
committerkkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2008-02-12 17:06:13 +0000
commit1d2f91432f09742e864f221aee8f66f9205f7fd4 (patch)
tree01dd9d46160a0129a70d3514cc06290e752af879
parent2db5ca38f3f8a6ce31457045371973f4266948cf (diff)
downloadjavassist-1d2f91432f09742e864f221aee8f66f9205f7fd4.tar.gz
javassist-1d2f91432f09742e864f221aee8f66f9205f7fd4.zip
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
-rw-r--r--src/main/javassist/util/proxy/ProxyFactory.java43
1 files changed, 41 insertions, 2 deletions
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();
+ }});
+ }
+ }
+ }
}