src/share/classes/javax/crypto/CryptoPermission.java

Print this page




 454     private boolean equalObjects(Object obj1, Object obj2) {
 455         if (obj1 == null) {
 456             return (obj2 == null ? true : false);
 457         }
 458 
 459         return obj1.equals(obj2);
 460     }
 461 }
 462 
 463 /**
 464  * A CryptoPermissionCollection stores a set of CryptoPermission
 465  * permissions.
 466  *
 467  * @see java.security.Permission
 468  * @see java.security.Permissions
 469  * @see java.security.PermissionCollection
 470  *
 471  * @author Sharon Liu
 472  */
 473 final class CryptoPermissionCollection extends PermissionCollection
 474 implements Serializable {
 475 
 476     private static final long serialVersionUID = -511215555898802763L;
 477 
 478     private Vector<Permission> permissions;
 479 
 480     /**
 481      * Creates an empty CryptoPermissionCollection
 482      * object.
 483      */
 484     CryptoPermissionCollection() {
 485         permissions = new Vector<Permission>(3);
 486     }
 487 
 488     /**
 489      * Adds a permission to the CryptoPermissionCollection.
 490      *
 491      * @param permission the Permission object to add.
 492      *
 493      * @exception SecurityException - if this CryptoPermissionCollection
 494      * object has been marked <i>readOnly</i>.
 495      */
 496     public void add(Permission permission)
 497     {
 498         if (isReadOnly())
 499             throw new SecurityException("attempt to add a Permission " +
 500                                         "to a readonly PermissionCollection");
 501 
 502         if (!(permission instanceof CryptoPermission))
 503             return;
 504 
 505         permissions.addElement(permission);
 506     }
 507 
 508     /**
 509       * Check and see if this CryptoPermission object implies
 510       * the given Permission object.
 511      *
 512      * @param p the Permission object to compare
 513      *
 514      * @return true if the given permission  is implied by this
 515      * CryptoPermissionCollection, false if not.
 516      */
 517     public boolean implies(Permission permission) {
 518         if (!(permission instanceof CryptoPermission))
 519             return false;
 520 
 521         CryptoPermission cp = (CryptoPermission)permission;
 522 
 523         Enumeration<Permission> e = permissions.elements();
 524 
 525         while (e.hasMoreElements()) {
 526             CryptoPermission x = (CryptoPermission) e.nextElement();
 527             if (x.implies(cp)) {
 528                 return true;
 529             }
 530         }
 531         return false;
 532     }
 533 
 534     /**
 535      * Returns an enumeration of all the CryptoPermission objects
 536      * in the container.
 537      *
 538      * @return an enumeration of all the CryptoPermission objects.
 539      */
 540 
 541     public Enumeration<Permission> elements()
 542     {
 543         return permissions.elements();
 544     }
 545 }


 454     private boolean equalObjects(Object obj1, Object obj2) {
 455         if (obj1 == null) {
 456             return (obj2 == null ? true : false);
 457         }
 458 
 459         return obj1.equals(obj2);
 460     }
 461 }
 462 
 463 /**
 464  * A CryptoPermissionCollection stores a set of CryptoPermission
 465  * permissions.
 466  *
 467  * @see java.security.Permission
 468  * @see java.security.Permissions
 469  * @see java.security.PermissionCollection
 470  *
 471  * @author Sharon Liu
 472  */
 473 final class CryptoPermissionCollection extends PermissionCollection
 474     implements Serializable
 475 {
 476     private static final long serialVersionUID = -511215555898802763L;
 477 
 478     private Vector<Permission> permissions;
 479 
 480     /**
 481      * Creates an empty CryptoPermissionCollection
 482      * object.
 483      */
 484     CryptoPermissionCollection() {
 485         permissions = new Vector<Permission>(3);
 486     }
 487 
 488     /**
 489      * Adds a permission to the CryptoPermissionCollection.
 490      *
 491      * @param permission the Permission object to add.
 492      *
 493      * @exception SecurityException - if this CryptoPermissionCollection
 494      * object has been marked <i>readOnly</i>.
 495      */
 496     public void add(Permission permission) {

 497         if (isReadOnly())
 498             throw new SecurityException("attempt to add a Permission " +
 499                                         "to a readonly PermissionCollection");
 500 
 501         if (!(permission instanceof CryptoPermission))
 502             return;
 503 
 504         permissions.addElement(permission);
 505     }
 506 
 507     /**
 508      * Check and see if this CryptoPermission object implies
 509      * the given Permission object.
 510      *
 511      * @param permission the Permission object to compare
 512      *
 513      * @return true if the given permission  is implied by this
 514      * CryptoPermissionCollection, false if not.
 515      */
 516     public boolean implies(Permission permission) {
 517         if (!(permission instanceof CryptoPermission))
 518             return false;
 519 
 520         CryptoPermission cp = (CryptoPermission)permission;
 521 
 522         Enumeration<Permission> e = permissions.elements();
 523 
 524         while (e.hasMoreElements()) {
 525             CryptoPermission x = (CryptoPermission) e.nextElement();
 526             if (x.implies(cp)) {
 527                 return true;
 528             }
 529         }
 530         return false;
 531     }
 532 
 533     /**
 534      * Returns an enumeration of all the CryptoPermission objects
 535      * in the container.
 536      *
 537      * @return an enumeration of all the CryptoPermission objects.
 538      */
 539 
 540     public Enumeration<Permission> elements() {

 541         return permissions.elements();
 542     }
 543 }