Make AccessibleObject Accessible : AccessController « Security « Java






Make AccessibleObject Accessible

 
import java.lang.reflect.AccessibleObject;
import java.security.AccessController;
import java.security.PrivilegedAction;


public class Utils {


  public static void makeAccessible( final AccessibleObject object ) {
      if (!object.isAccessible()) {
          if (System.getSecurityManager() == null) {
              object.setAccessible(true);
          } else {
              AccessController.doPrivileged(new PrivilegedAction<Object>() {

                  public Object run() {
                      object.setAccessible(true);
                      return null;
                  }
              });
          }
      }
  }

}

   
  








Related examples in the same category

1.Use AccessController to check the file permission
2.Use AccessController to check the AWT permission
3.AccessController.doPrivileged(new PrivilegedAction() )
4. ClassLoader java.security.AccessController.doPrivileged(PrivilegedAction action)
5.Security Support
6.Load class
7.Search for resource in different places.
8.Lock request from going up in the classloader hierarchy