src/share/classes/java/lang/reflect/AccessibleObject.java

Print this page




  27 
  28 import java.security.AccessController;
  29 import sun.reflect.ReflectionFactory;
  30 import java.lang.annotation.Annotation;
  31 
  32 /**
  33  * The AccessibleObject class is the base class for Field, Method and
  34  * Constructor objects.  It provides the ability to flag a reflected
  35  * object as suppressing default Java language access control checks
  36  * when it is used.  The access checks--for public, default (package)
  37  * access, protected, and private members--are performed when Fields,
  38  * Methods or Constructors are used to set or get fields, to invoke
  39  * methods, or to create and initialize new instances of classes,
  40  * respectively.
  41  *
  42  * <p>Setting the {@code accessible} flag in a reflected object
  43  * permits sophisticated applications with sufficient privilege, such
  44  * as Java Object Serialization or other persistence mechanisms, to
  45  * manipulate objects in a manner that would normally be prohibited.
  46  *


  47  * @see Field
  48  * @see Method
  49  * @see Constructor
  50  * @see ReflectPermission
  51  *
  52  * @since 1.2
  53  */
  54 public class AccessibleObject implements AnnotatedElement {
  55 
  56     /**
  57      * The Permission object that is used to check whether a client
  58      * has sufficient privilege to defeat Java language access
  59      * control checks.
  60      */
  61     static final private java.security.Permission ACCESS_PERMISSION =
  62         new ReflectPermission("suppressAccessChecks");
  63 
  64     /**
  65      * Convenience method to set the {@code accessible} flag for an
  66      * array of objects with a single security check (for efficiency).




  27 
  28 import java.security.AccessController;
  29 import sun.reflect.ReflectionFactory;
  30 import java.lang.annotation.Annotation;
  31 
  32 /**
  33  * The AccessibleObject class is the base class for Field, Method and
  34  * Constructor objects.  It provides the ability to flag a reflected
  35  * object as suppressing default Java language access control checks
  36  * when it is used.  The access checks--for public, default (package)
  37  * access, protected, and private members--are performed when Fields,
  38  * Methods or Constructors are used to set or get fields, to invoke
  39  * methods, or to create and initialize new instances of classes,
  40  * respectively.
  41  *
  42  * <p>Setting the {@code accessible} flag in a reflected object
  43  * permits sophisticated applications with sufficient privilege, such
  44  * as Java Object Serialization or other persistence mechanisms, to
  45  * manipulate objects in a manner that would normally be prohibited.
  46  *
  47  * <p>By default, a reflected object is <em>not</em> accessible.
  48  *
  49  * @see Field
  50  * @see Method
  51  * @see Constructor
  52  * @see ReflectPermission
  53  *
  54  * @since 1.2
  55  */
  56 public class AccessibleObject implements AnnotatedElement {
  57 
  58     /**
  59      * The Permission object that is used to check whether a client
  60      * has sufficient privilege to defeat Java language access
  61      * control checks.
  62      */
  63     static final private java.security.Permission ACCESS_PERMISSION =
  64         new ReflectPermission("suppressAccessChecks");
  65 
  66     /**
  67      * Convenience method to set the {@code accessible} flag for an
  68      * array of objects with a single security check (for efficiency).