[jboss-cvs] javassist/src/main/javassist/util/proxy ...

Kabir Khan kkhan at jboss.com
Tue Feb 12 12:06:13 EST 2008


  User: kkhan   
  Date: 08/02/12 12:06:13

  Modified:    src/main/javassist/util/proxy  ProxyFactory.java
  Log:
  Make ProxyFactory use privileged blocks when a security manager is present
  
  Revision  Changes    Path
  1.27      +41 -2     javassist/src/main/javassist/util/proxy/ProxyFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ProxyFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/util/proxy/ProxyFactory.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- ProxyFactory.java	2 Oct 2007 03:49:11 -0000	1.26
  +++ ProxyFactory.java	12 Feb 2008 17:06:13 -0000	1.27
  @@ -21,6 +21,8 @@
   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 @@
       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 @@
           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 @@
           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();
  +               }});
  +          }
  +       }
  +    }
   }
  
  
  



More information about the jboss-cvs-commits mailing list