1 22 package org.jboss.aop.util; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.Method ; 26 import java.security.AccessController ; 27 import java.security.PrivilegedActionException ; 28 import java.security.PrivilegedExceptionAction ; 29 30 35 class SecurityActions 36 { 37 interface GetDeclaredMethodsAction 38 { 39 Method [] getDeclaredMethods(Class clazz); 40 41 GetDeclaredMethodsAction PRIVILEGED = new GetDeclaredMethodsAction() 42 { 43 public Method [] getDeclaredMethods(final Class clazz) 44 { 45 try 46 { 47 return (Method [])AccessController.doPrivileged(new PrivilegedExceptionAction () 48 { 49 public Object run() throws Exception 50 { 51 return clazz.getDeclaredMethods(); 52 } 53 }); 54 } 55 catch (PrivilegedActionException e) 56 { 57 throw new RuntimeException (e); 58 } 59 } 60 }; 61 62 GetDeclaredMethodsAction NON_PRIVILEGED = new GetDeclaredMethodsAction() 63 { 64 public Method [] getDeclaredMethods(Class clazz) 65 { 66 return clazz.getDeclaredMethods(); 67 } 68 }; 69 } 70 71 interface GetDeclaredConstructorsAction 72 { 73 Constructor [] getDeclaredConstructors(Class clazz); 74 75 GetDeclaredConstructorsAction PRIVILEGED = new GetDeclaredConstructorsAction() 76 { 77 public Constructor [] getDeclaredConstructors(final Class clazz) 78 { 79 try 80 { 81 return (Constructor [])AccessController.doPrivileged(new PrivilegedExceptionAction () 82 { 83 public Object run() throws Exception 84 { 85 return clazz.getDeclaredConstructors(); 86 } 87 }); 88 } 89 catch (PrivilegedActionException e) 90 { 91 throw new RuntimeException (e); 92 } 93 } 94 }; 95 96 GetDeclaredConstructorsAction NON_PRIVILEGED = new GetDeclaredConstructorsAction() 97 { 98 public Constructor [] getDeclaredConstructors(Class clazz) 99 { 100 return clazz.getDeclaredConstructors(); 101 } 102 }; 103 } 104 105 static Method [] getDeclaredMethods(Class clazz) 106 { 107 if (System.getSecurityManager() == null) 108 { 109 return GetDeclaredMethodsAction.NON_PRIVILEGED.getDeclaredMethods(clazz); 110 } 111 else 112 { 113 return GetDeclaredMethodsAction.PRIVILEGED.getDeclaredMethods(clazz); 114 } 115 } 116 117 static Constructor [] getDeclaredConstructors(Class clazz) 118 { 119 if (System.getSecurityManager() == null) 120 { 121 return GetDeclaredConstructorsAction.NON_PRIVILEGED.getDeclaredConstructors(clazz); 122 } 123 else 124 { 125 return GetDeclaredConstructorsAction.PRIVILEGED.getDeclaredConstructors(clazz); 126 } 127 } 128 } 129 | Popular Tags |