< prev index next >

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

Print this page




 315      * contains a BasicPermission with '*' as its permission name.
 316      *
 317      * @see #serialPersistentFields
 318      */
 319     private boolean all_allowed;
 320 
 321     /**
 322      * The class to which all BasicPermissions in this
 323      * BasicPermissionCollection belongs.
 324      *
 325      * @see #serialPersistentFields
 326      */
 327     private Class<?> permClass;
 328 
 329     /**
 330      * Create an empty BasicPermissionCollection object.
 331      *
 332      */
 333 
 334     public BasicPermissionCollection(Class<?> clazz) {
 335         perms = new HashMap<String, Permission>(11);
 336         all_allowed = false;
 337         permClass = clazz;
 338     }
 339 
 340     /**
 341      * Adds a permission to the BasicPermissions. The key for the hash is
 342      * permission.path.
 343      *
 344      * @param permission the Permission object to add.
 345      *
 346      * @exception IllegalArgumentException - if the permission is not a
 347      *                                       BasicPermission, or if
 348      *                                       the permission is not of the
 349      *                                       same Class as the other
 350      *                                       permissions in this collection.
 351      *
 352      * @exception SecurityException - if this BasicPermissionCollection object
 353      *                                has been marked readonly
 354      */
 355     public void add(Permission permission) {


 516     }
 517 
 518     /**
 519      * readObject is called to restore the state of the
 520      * BasicPermissionCollection from a stream.
 521      */
 522     private void readObject(java.io.ObjectInputStream in)
 523          throws IOException, ClassNotFoundException
 524     {
 525         // Don't call defaultReadObject()
 526 
 527         // Read in serialized fields
 528         ObjectInputStream.GetField gfields = in.readFields();
 529 
 530         // Get permissions
 531         // writeObject writes a Hashtable<String, Permission> for the
 532         // permissions key, so this cast is safe, unless the data is corrupt.
 533         @SuppressWarnings("unchecked")
 534         Hashtable<String, Permission> permissions =
 535                 (Hashtable<String, Permission>)gfields.get("permissions", null);
 536         perms = new HashMap<String, Permission>(permissions.size()*2);
 537         perms.putAll(permissions);
 538 
 539         // Get all_allowed
 540         all_allowed = gfields.get("all_allowed", false);
 541 
 542         // Get permClass
 543         permClass = (Class<?>) gfields.get("permClass", null);
 544 
 545         if (permClass == null) {
 546             // set permClass
 547             Enumeration<Permission> e = permissions.elements();
 548             if (e.hasMoreElements()) {
 549                 Permission p = e.nextElement();
 550                 permClass = p.getClass();
 551             }
 552         }
 553     }
 554 }


 315      * contains a BasicPermission with '*' as its permission name.
 316      *
 317      * @see #serialPersistentFields
 318      */
 319     private boolean all_allowed;
 320 
 321     /**
 322      * The class to which all BasicPermissions in this
 323      * BasicPermissionCollection belongs.
 324      *
 325      * @see #serialPersistentFields
 326      */
 327     private Class<?> permClass;
 328 
 329     /**
 330      * Create an empty BasicPermissionCollection object.
 331      *
 332      */
 333 
 334     public BasicPermissionCollection(Class<?> clazz) {
 335         perms = new HashMap<>(11);
 336         all_allowed = false;
 337         permClass = clazz;
 338     }
 339 
 340     /**
 341      * Adds a permission to the BasicPermissions. The key for the hash is
 342      * permission.path.
 343      *
 344      * @param permission the Permission object to add.
 345      *
 346      * @exception IllegalArgumentException - if the permission is not a
 347      *                                       BasicPermission, or if
 348      *                                       the permission is not of the
 349      *                                       same Class as the other
 350      *                                       permissions in this collection.
 351      *
 352      * @exception SecurityException - if this BasicPermissionCollection object
 353      *                                has been marked readonly
 354      */
 355     public void add(Permission permission) {


 516     }
 517 
 518     /**
 519      * readObject is called to restore the state of the
 520      * BasicPermissionCollection from a stream.
 521      */
 522     private void readObject(java.io.ObjectInputStream in)
 523          throws IOException, ClassNotFoundException
 524     {
 525         // Don't call defaultReadObject()
 526 
 527         // Read in serialized fields
 528         ObjectInputStream.GetField gfields = in.readFields();
 529 
 530         // Get permissions
 531         // writeObject writes a Hashtable<String, Permission> for the
 532         // permissions key, so this cast is safe, unless the data is corrupt.
 533         @SuppressWarnings("unchecked")
 534         Hashtable<String, Permission> permissions =
 535                 (Hashtable<String, Permission>)gfields.get("permissions", null);
 536         perms = new HashMap<>(permissions.size()*2);
 537         perms.putAll(permissions);
 538 
 539         // Get all_allowed
 540         all_allowed = gfields.get("all_allowed", false);
 541 
 542         // Get permClass
 543         permClass = (Class<?>) gfields.get("permClass", null);
 544 
 545         if (permClass == null) {
 546             // set permClass
 547             Enumeration<Permission> e = permissions.elements();
 548             if (e.hasMoreElements()) {
 549                 Permission p = e.nextElement();
 550                 permClass = p.getClass();
 551             }
 552         }
 553     }
 554 }
< prev index next >