src/share/classes/javax/security/auth/kerberos/DelegationPermission.java

Print this page




 161      * @return true if <i>obj</i> is a DelegationPermission, and
 162      *  has the same subordinate and service principal as this.
 163      *  DelegationPermission object.
 164      */
 165     public boolean equals(Object obj) {
 166         if (obj == this)
 167             return true;
 168 
 169         if (! (obj instanceof DelegationPermission))
 170             return false;
 171 
 172         DelegationPermission that = (DelegationPermission) obj;
 173         return implies(that);
 174     }
 175 
 176     /**
 177      * Returns the hash code value for this object.
 178      *
 179      * @return a hash code value for this object.
 180      */
 181 
 182     public int hashCode() {
 183         return getName().hashCode();
 184     }
 185 
 186 
 187     /**
 188      * Returns a PermissionCollection object for storing
 189      * DelegationPermission objects.
 190      * <br>
 191      * DelegationPermission objects must be stored in a manner that
 192      * allows them to be inserted into the collection in any order, but
 193      * that also enables the PermissionCollection implies method to
 194      * be implemented in an efficient (and consistent) manner.
 195      *
 196      * @return a new PermissionCollection object suitable for storing
 197      * DelegationPermissions.
 198      */
 199 
 200     public PermissionCollection newPermissionCollection() {
 201         return new KrbDelegationPermissionCollection();


 261       }
 262     */
 263 }
 264 
 265 
 266 final class KrbDelegationPermissionCollection extends PermissionCollection
 267     implements java.io.Serializable {
 268 
 269     // Not serialized; see serialization section at end of class.
 270     private transient List<Permission> perms;
 271 
 272     public KrbDelegationPermissionCollection() {
 273         perms = new ArrayList<Permission>();
 274     }
 275 
 276 
 277     /**
 278      * Check and see if this collection of permissions implies the permissions
 279      * expressed in "permission".
 280      *
 281      * @param p the Permission object to compare
 282      *
 283      * @return true if "permission" is a proper subset of a permission in
 284      * the collection, false if not.
 285      */
 286 
 287     public boolean implies(Permission permission) {
 288         if (! (permission instanceof DelegationPermission))
 289                 return false;
 290 
 291         synchronized (this) {
 292             for (Permission x : perms) {
 293                 if (x.implies(permission))
 294                     return true;
 295             }
 296         }
 297         return false;
 298 
 299     }
 300 
 301     /**
 302      * Adds a permission to the DelegationPermissions. The key for
 303      * the hash is the name.
 304      *
 305      * @param permission the Permission object to add.
 306      *
 307      * @exception IllegalArgumentException - if the permission is not a
 308      *                                       DelegationPermission
 309      *
 310      * @exception SecurityException - if this PermissionCollection object
 311      *                                has been marked readonly
 312      */
 313 
 314     public void add(Permission permission) {
 315         if (! (permission instanceof DelegationPermission))
 316             throw new IllegalArgumentException("invalid permission: "+
 317                                                permission);
 318         if (isReadOnly())
 319             throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
 320 
 321         synchronized (this) {
 322             perms.add(0, permission);
 323         }
 324     }
 325 
 326     /**
 327      * Returns an enumeration of all the DelegationPermission objects
 328      * in the container.
 329      *
 330      * @return an enumeration of all the DelegationPermission objects.
 331      */
 332 
 333     public Enumeration<Permission> elements() {
 334         // Convert Iterator into Enumeration
 335         synchronized (this) {
 336             return Collections.enumeration(perms);
 337         }
 338     }
 339 
 340     private static final long serialVersionUID = -3383936936589966948L;
 341 
 342     // Need to maintain serialization interoperability with earlier releases,
 343     // which had the serializable field:
 344     //    private Vector permissions;
 345     /**
 346      * @serialField permissions java.util.Vector
 347      *     A list of DelegationPermission objects.
 348      */
 349     private static final ObjectStreamField[] serialPersistentFields = {
 350         new ObjectStreamField("permissions", Vector.class),
 351     };
 352 


 359      */
 360     private void writeObject(ObjectOutputStream out) throws IOException {
 361         // Don't call out.defaultWriteObject()
 362 
 363         // Write out Vector
 364         Vector<Permission> permissions = new Vector<>(perms.size());
 365 
 366         synchronized (this) {
 367             permissions.addAll(perms);
 368         }
 369 
 370         ObjectOutputStream.PutField pfields = out.putFields();
 371         pfields.put("permissions", permissions);
 372         out.writeFields();
 373     }
 374 
 375     /*
 376      * Reads in a Vector of DelegationPermissions and saves them in the perms field.
 377      */
 378     @SuppressWarnings("unchecked")
 379     private void readObject(ObjectInputStream in) throws IOException,
 380     ClassNotFoundException {

 381         // Don't call defaultReadObject()
 382 
 383         // Read in serialized fields
 384         ObjectInputStream.GetField gfields = in.readFields();
 385 
 386         // Get the one we want
 387         Vector<Permission> permissions =
 388                 (Vector<Permission>)gfields.get("permissions", null);
 389         perms = new ArrayList<Permission>(permissions.size());
 390         perms.addAll(permissions);
 391     }
 392 }


 161      * @return true if <i>obj</i> is a DelegationPermission, and
 162      *  has the same subordinate and service principal as this.
 163      *  DelegationPermission object.
 164      */
 165     public boolean equals(Object obj) {
 166         if (obj == this)
 167             return true;
 168 
 169         if (! (obj instanceof DelegationPermission))
 170             return false;
 171 
 172         DelegationPermission that = (DelegationPermission) obj;
 173         return implies(that);
 174     }
 175 
 176     /**
 177      * Returns the hash code value for this object.
 178      *
 179      * @return a hash code value for this object.
 180      */

 181     public int hashCode() {
 182         return getName().hashCode();
 183     }
 184 
 185 
 186     /**
 187      * Returns a PermissionCollection object for storing
 188      * DelegationPermission objects.
 189      * <br>
 190      * DelegationPermission objects must be stored in a manner that
 191      * allows them to be inserted into the collection in any order, but
 192      * that also enables the PermissionCollection implies method to
 193      * be implemented in an efficient (and consistent) manner.
 194      *
 195      * @return a new PermissionCollection object suitable for storing
 196      * DelegationPermissions.
 197      */
 198 
 199     public PermissionCollection newPermissionCollection() {
 200         return new KrbDelegationPermissionCollection();


 260       }
 261     */
 262 }
 263 
 264 
 265 final class KrbDelegationPermissionCollection extends PermissionCollection
 266     implements java.io.Serializable {
 267 
 268     // Not serialized; see serialization section at end of class.
 269     private transient List<Permission> perms;
 270 
 271     public KrbDelegationPermissionCollection() {
 272         perms = new ArrayList<Permission>();
 273     }
 274 
 275 
 276     /**
 277      * Check and see if this collection of permissions implies the permissions
 278      * expressed in "permission".
 279      *
 280      * @param permission the Permission object to compare
 281      *
 282      * @return true if "permission" is a proper subset of a permission in
 283      * the collection, false if not.
 284      */

 285     public boolean implies(Permission permission) {
 286         if (! (permission instanceof DelegationPermission))
 287                 return false;
 288 
 289         synchronized (this) {
 290             for (Permission x : perms) {
 291                 if (x.implies(permission))
 292                     return true;
 293             }
 294         }
 295         return false;
 296 
 297     }
 298 
 299     /**
 300      * Adds a permission to the DelegationPermissions. The key for
 301      * the hash is the name.
 302      *
 303      * @param permission the Permission object to add.
 304      *
 305      * @exception IllegalArgumentException - if the permission is not a
 306      *                                       DelegationPermission
 307      *
 308      * @exception SecurityException - if this PermissionCollection object
 309      *                                has been marked readonly
 310      */

 311     public void add(Permission permission) {
 312         if (! (permission instanceof DelegationPermission))
 313             throw new IllegalArgumentException("invalid permission: "+
 314                                                permission);
 315         if (isReadOnly())
 316             throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
 317 
 318         synchronized (this) {
 319             perms.add(0, permission);
 320         }
 321     }
 322 
 323     /**
 324      * Returns an enumeration of all the DelegationPermission objects
 325      * in the container.
 326      *
 327      * @return an enumeration of all the DelegationPermission objects.
 328      */

 329     public Enumeration<Permission> elements() {
 330         // Convert Iterator into Enumeration
 331         synchronized (this) {
 332             return Collections.enumeration(perms);
 333         }
 334     }
 335 
 336     private static final long serialVersionUID = -3383936936589966948L;
 337 
 338     // Need to maintain serialization interoperability with earlier releases,
 339     // which had the serializable field:
 340     //    private Vector permissions;
 341     /**
 342      * @serialField permissions java.util.Vector
 343      *     A list of DelegationPermission objects.
 344      */
 345     private static final ObjectStreamField[] serialPersistentFields = {
 346         new ObjectStreamField("permissions", Vector.class),
 347     };
 348 


 355      */
 356     private void writeObject(ObjectOutputStream out) throws IOException {
 357         // Don't call out.defaultWriteObject()
 358 
 359         // Write out Vector
 360         Vector<Permission> permissions = new Vector<>(perms.size());
 361 
 362         synchronized (this) {
 363             permissions.addAll(perms);
 364         }
 365 
 366         ObjectOutputStream.PutField pfields = out.putFields();
 367         pfields.put("permissions", permissions);
 368         out.writeFields();
 369     }
 370 
 371     /*
 372      * Reads in a Vector of DelegationPermissions and saves them in the perms field.
 373      */
 374     @SuppressWarnings("unchecked")
 375     private void readObject(ObjectInputStream in)
 376         throws IOException, ClassNotFoundException
 377     {
 378         // Don't call defaultReadObject()
 379 
 380         // Read in serialized fields
 381         ObjectInputStream.GetField gfields = in.readFields();
 382 
 383         // Get the one we want
 384         Vector<Permission> permissions =
 385                 (Vector<Permission>)gfields.get("permissions", null);
 386         perms = new ArrayList<Permission>(permissions.size());
 387         perms.addAll(permissions);
 388     }
 389 }