< prev index next >

src/java.base/share/classes/java/security/Permissions.java

Print this page




  82 implements Serializable
  83 {
  84     /**
  85      * Key is permissions Class, value is PermissionCollection for that class.
  86      * Not serialized; see serialization section at end of class.
  87      */
  88     private transient Map<Class<?>, PermissionCollection> permsMap;
  89 
  90     // optimization. keep track of whether unresolved permissions need to be
  91     // checked
  92     private transient boolean hasUnresolved = false;
  93 
  94     // optimization. keep track of the AllPermission collection
  95     // - package private for ProtectionDomain optimization
  96     PermissionCollection allPermission;
  97 
  98     /**
  99      * Creates a new Permissions object containing no PermissionCollections.
 100      */
 101     public Permissions() {
 102         permsMap = new HashMap<Class<?>, PermissionCollection>(11);
 103         allPermission = null;
 104     }
 105 
 106     /**
 107      * Adds a permission object to the PermissionCollection for the class the
 108      * permission belongs to. For example, if <i>permission</i> is a
 109      * FilePermission, it is added to the FilePermissionCollection stored
 110      * in this Permissions object.
 111      *
 112      * This method creates
 113      * a new PermissionCollection object (and adds the permission to it)
 114      * if an appropriate collection does not yet exist.
 115      *
 116      * @param permission the Permission object to add.
 117      *
 118      * @exception SecurityException if this Permissions object is
 119      * marked as readonly.
 120      *
 121      * @see PermissionCollection#isReadOnly()
 122      */


 377     /*
 378      * Reads in a Hashtable of Class/PermissionCollections and saves them in the
 379      * permsMap field. Reads in allPermission.
 380      */
 381     private void readObject(ObjectInputStream in) throws IOException,
 382     ClassNotFoundException {
 383         // Don't call defaultReadObject()
 384 
 385         // Read in serialized fields
 386         ObjectInputStream.GetField gfields = in.readFields();
 387 
 388         // Get allPermission
 389         allPermission = (PermissionCollection) gfields.get("allPermission", null);
 390 
 391         // Get permissions
 392         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
 393         // the perms key, so this cast is safe, unless the data is corrupt.
 394         @SuppressWarnings("unchecked")
 395         Hashtable<Class<?>, PermissionCollection> perms =
 396             (Hashtable<Class<?>, PermissionCollection>)gfields.get("perms", null);
 397         permsMap = new HashMap<Class<?>, PermissionCollection>(perms.size()*2);
 398         permsMap.putAll(perms);
 399 
 400         // Set hasUnresolved
 401         UnresolvedPermissionCollection uc =
 402         (UnresolvedPermissionCollection) permsMap.get(UnresolvedPermission.class);
 403         hasUnresolved = (uc != null && uc.elements().hasMoreElements());
 404     }
 405 }
 406 
 407 final class PermissionsEnumerator implements Enumeration<Permission> {
 408 
 409     // all the perms
 410     private Iterator<PermissionCollection> perms;
 411     // the current set
 412     private Enumeration<Permission> permset;
 413 
 414     PermissionsEnumerator(Iterator<PermissionCollection> e) {
 415         perms = e;
 416         permset = getNextEnumWithMore();
 417     }


 471  *
 472  * @author Roland Schemers
 473  *
 474  * @serial include
 475  */
 476 
 477 final class PermissionsHash extends PermissionCollection
 478 implements Serializable
 479 {
 480     /**
 481      * Key and value are (same) permissions objects.
 482      * Not serialized; see serialization section at end of class.
 483      */
 484     private transient Map<Permission, Permission> permsMap;
 485 
 486     /**
 487      * Create an empty PermissionsHash object.
 488      */
 489 
 490     PermissionsHash() {
 491         permsMap = new HashMap<Permission, Permission>(11);
 492     }
 493 
 494     /**
 495      * Adds a permission to the PermissionsHash.
 496      *
 497      * @param permission the Permission object to add.
 498      */
 499 
 500     public void add(Permission permission) {
 501         synchronized (this) {
 502             permsMap.put(permission, permission);
 503         }
 504     }
 505 
 506     /**
 507      * Check and see if this set of permissions implies the permissions
 508      * expressed in "permission".
 509      *
 510      * @param permission the Permission object to compare
 511      *


 580         out.writeFields();
 581     }
 582 
 583     /*
 584      * Reads in a Hashtable of Permission/Permission and saves them in the
 585      * permsMap field.
 586      */
 587     private void readObject(ObjectInputStream in) throws IOException,
 588     ClassNotFoundException {
 589         // Don't call defaultReadObject()
 590 
 591         // Read in serialized fields
 592         ObjectInputStream.GetField gfields = in.readFields();
 593 
 594         // Get permissions
 595         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
 596         // the perms key, so this cast is safe, unless the data is corrupt.
 597         @SuppressWarnings("unchecked")
 598         Hashtable<Permission, Permission> perms =
 599                 (Hashtable<Permission, Permission>)gfields.get("perms", null);
 600         permsMap = new HashMap<Permission, Permission>(perms.size()*2);
 601         permsMap.putAll(perms);
 602     }
 603 }


  82 implements Serializable
  83 {
  84     /**
  85      * Key is permissions Class, value is PermissionCollection for that class.
  86      * Not serialized; see serialization section at end of class.
  87      */
  88     private transient Map<Class<?>, PermissionCollection> permsMap;
  89 
  90     // optimization. keep track of whether unresolved permissions need to be
  91     // checked
  92     private transient boolean hasUnresolved = false;
  93 
  94     // optimization. keep track of the AllPermission collection
  95     // - package private for ProtectionDomain optimization
  96     PermissionCollection allPermission;
  97 
  98     /**
  99      * Creates a new Permissions object containing no PermissionCollections.
 100      */
 101     public Permissions() {
 102         permsMap = new HashMap<>(11);
 103         allPermission = null;
 104     }
 105 
 106     /**
 107      * Adds a permission object to the PermissionCollection for the class the
 108      * permission belongs to. For example, if <i>permission</i> is a
 109      * FilePermission, it is added to the FilePermissionCollection stored
 110      * in this Permissions object.
 111      *
 112      * This method creates
 113      * a new PermissionCollection object (and adds the permission to it)
 114      * if an appropriate collection does not yet exist.
 115      *
 116      * @param permission the Permission object to add.
 117      *
 118      * @exception SecurityException if this Permissions object is
 119      * marked as readonly.
 120      *
 121      * @see PermissionCollection#isReadOnly()
 122      */


 377     /*
 378      * Reads in a Hashtable of Class/PermissionCollections and saves them in the
 379      * permsMap field. Reads in allPermission.
 380      */
 381     private void readObject(ObjectInputStream in) throws IOException,
 382     ClassNotFoundException {
 383         // Don't call defaultReadObject()
 384 
 385         // Read in serialized fields
 386         ObjectInputStream.GetField gfields = in.readFields();
 387 
 388         // Get allPermission
 389         allPermission = (PermissionCollection) gfields.get("allPermission", null);
 390 
 391         // Get permissions
 392         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
 393         // the perms key, so this cast is safe, unless the data is corrupt.
 394         @SuppressWarnings("unchecked")
 395         Hashtable<Class<?>, PermissionCollection> perms =
 396             (Hashtable<Class<?>, PermissionCollection>)gfields.get("perms", null);
 397         permsMap = new HashMap<>(perms.size()*2);
 398         permsMap.putAll(perms);
 399 
 400         // Set hasUnresolved
 401         UnresolvedPermissionCollection uc =
 402         (UnresolvedPermissionCollection) permsMap.get(UnresolvedPermission.class);
 403         hasUnresolved = (uc != null && uc.elements().hasMoreElements());
 404     }
 405 }
 406 
 407 final class PermissionsEnumerator implements Enumeration<Permission> {
 408 
 409     // all the perms
 410     private Iterator<PermissionCollection> perms;
 411     // the current set
 412     private Enumeration<Permission> permset;
 413 
 414     PermissionsEnumerator(Iterator<PermissionCollection> e) {
 415         perms = e;
 416         permset = getNextEnumWithMore();
 417     }


 471  *
 472  * @author Roland Schemers
 473  *
 474  * @serial include
 475  */
 476 
 477 final class PermissionsHash extends PermissionCollection
 478 implements Serializable
 479 {
 480     /**
 481      * Key and value are (same) permissions objects.
 482      * Not serialized; see serialization section at end of class.
 483      */
 484     private transient Map<Permission, Permission> permsMap;
 485 
 486     /**
 487      * Create an empty PermissionsHash object.
 488      */
 489 
 490     PermissionsHash() {
 491         permsMap = new HashMap<>(11);
 492     }
 493 
 494     /**
 495      * Adds a permission to the PermissionsHash.
 496      *
 497      * @param permission the Permission object to add.
 498      */
 499 
 500     public void add(Permission permission) {
 501         synchronized (this) {
 502             permsMap.put(permission, permission);
 503         }
 504     }
 505 
 506     /**
 507      * Check and see if this set of permissions implies the permissions
 508      * expressed in "permission".
 509      *
 510      * @param permission the Permission object to compare
 511      *


 580         out.writeFields();
 581     }
 582 
 583     /*
 584      * Reads in a Hashtable of Permission/Permission and saves them in the
 585      * permsMap field.
 586      */
 587     private void readObject(ObjectInputStream in) throws IOException,
 588     ClassNotFoundException {
 589         // Don't call defaultReadObject()
 590 
 591         // Read in serialized fields
 592         ObjectInputStream.GetField gfields = in.readFields();
 593 
 594         // Get permissions
 595         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
 596         // the perms key, so this cast is safe, unless the data is corrupt.
 597         @SuppressWarnings("unchecked")
 598         Hashtable<Permission, Permission> perms =
 599                 (Hashtable<Permission, Permission>)gfields.get("perms", null);
 600         permsMap = new HashMap<>(perms.size()*2);
 601         permsMap.putAll(perms);
 602     }
 603 }
< prev index next >