1 22 package org.jboss.aop; 23 24 import java.lang.reflect.AccessibleObject ; 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 SetAccessibleAction 38 { 39 void setAccessible(AccessibleObject accessibleObject); 40 41 SetAccessibleAction PRIVILEGED = new SetAccessibleAction() 42 { 43 public void setAccessible(final AccessibleObject accessibleObject) 44 { 45 try 46 { 47 AccessController.doPrivileged(new PrivilegedExceptionAction () 48 { 49 public Object run() throws Exception 50 { 51 accessibleObject.setAccessible(true); 52 return null; 53 } 54 }); 55 } 56 catch (PrivilegedActionException e) 57 { 58 throw new RuntimeException ("Error setting " + accessibleObject + " as accessible ", e.getException()); 59 } 60 } 61 }; 62 63 SetAccessibleAction NON_PRIVILEGED = new SetAccessibleAction() 64 { 65 public void setAccessible(AccessibleObject accessibleObject) 66 { 67 accessibleObject.setAccessible(true); 68 } 69 }; 70 } 71 72 static void setAccessible(AccessibleObject accessibleObject) 73 { 74 if (System.getSecurityManager() == null) 75 { 76 SetAccessibleAction.NON_PRIVILEGED.setAccessible(accessibleObject); 77 } 78 else 79 { 80 SetAccessibleAction.PRIVILEGED.setAccessible(accessibleObject); 81 } 82 } 83 84 } 85 | Popular Tags |