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