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

Print this page




 242         if ((mask & INITIATE) == INITIATE) {
 243             if (comma) sb.append(',');
 244             else comma = true;
 245             sb.append("initiate");
 246         }
 247 
 248         if ((mask & ACCEPT) == ACCEPT) {
 249             if (comma) sb.append(',');
 250             else comma = true;
 251             sb.append("accept");
 252         }
 253 
 254         return sb.toString();
 255     }
 256 
 257     /**
 258      * Returns the canonical string representation of the actions.
 259      * Always returns present actions in the following order:
 260      * initiate, accept.
 261      */
 262 
 263     public String getActions() {
 264         if (actions == null)
 265             actions = getActions(this.mask);
 266 
 267         return actions;
 268     }
 269 
 270 
 271     /**
 272      * Returns a PermissionCollection object for storing
 273      * ServicePermission objects.
 274      * <br>
 275      * ServicePermission objects must be stored in a manner that
 276      * allows them to be inserted into the collection in any order, but
 277      * that also enables the PermissionCollection implies method to
 278      * be implemented in an efficient (and consistent) manner.
 279      *
 280      * @return a new PermissionCollection object suitable for storing
 281      * ServicePermissions.
 282      */
 283 
 284     public PermissionCollection newPermissionCollection() {
 285         return new KrbServicePermissionCollection();
 286     }
 287 
 288     /**
 289      * Return the current action mask.
 290      *
 291      * @return the actions mask.
 292      */
 293 
 294     int getMask() {
 295         return mask;
 296     }
 297 
 298     /**
 299      * Convert an action string to an integer actions mask.
 300      *
 301      * @param action the action string
 302      * @return the action mask
 303      */
 304 
 305     private static int getMask(String action) {
 306 
 307         if (action == null) {
 308             throw new NullPointerException("action can't be null");
 309         }
 310 
 311         if (action.equals("")) {
 312             throw new IllegalArgumentException("action can't be empty");
 313         }
 314 
 315         int mask = NONE;
 316 
 317         char[] a = action.toCharArray();
 318 
 319         int i = a.length - 1;
 320         if (i < 0)
 321             return mask;
 322 
 323         while (i != -1) {
 324             char c;


 451       }
 452     */
 453 
 454 }
 455 
 456 
 457 final class KrbServicePermissionCollection extends PermissionCollection
 458     implements java.io.Serializable {
 459 
 460     // Not serialized; see serialization section at end of class
 461     private transient List<Permission> perms;
 462 
 463     public KrbServicePermissionCollection() {
 464         perms = new ArrayList<Permission>();
 465     }
 466 
 467     /**
 468      * Check and see if this collection of permissions implies the permissions
 469      * expressed in "permission".
 470      *
 471      * @param p the Permission object to compare
 472      *
 473      * @return true if "permission" is a proper subset of a permission in
 474      * the collection, false if not.
 475      */
 476 
 477     public boolean implies(Permission permission) {
 478         if (! (permission instanceof ServicePermission))
 479                 return false;
 480 
 481         ServicePermission np = (ServicePermission) permission;
 482         int desired = np.getMask();
 483         int effective = 0;
 484         int needed = desired;
 485 
 486         synchronized (this) {
 487             int len = perms.size();
 488 
 489             // need to deal with the case where the needed permission has
 490             // more than one action and the collection has individual permissions
 491             // that sum up to the needed.
 492 
 493             for (int i = 0; i < len; i++) {
 494                 ServicePermission x = (ServicePermission) perms.get(i);
 495 
 496                 //System.out.println("  trying "+x);


 500                         return true;
 501                     needed = (desired ^ effective);
 502                 }
 503             }
 504         }
 505         return false;
 506     }
 507 
 508     /**
 509      * Adds a permission to the ServicePermissions. The key for
 510      * the hash is the name.
 511      *
 512      * @param permission the Permission object to add.
 513      *
 514      * @exception IllegalArgumentException - if the permission is not a
 515      *                                       ServicePermission
 516      *
 517      * @exception SecurityException - if this PermissionCollection object
 518      *                                has been marked readonly
 519      */
 520 
 521     public void add(Permission permission) {
 522         if (! (permission instanceof ServicePermission))
 523             throw new IllegalArgumentException("invalid permission: "+
 524                                                permission);
 525         if (isReadOnly())
 526             throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
 527 
 528         synchronized (this) {
 529             perms.add(0, permission);
 530         }
 531     }
 532 
 533     /**
 534      * Returns an enumeration of all the ServicePermission objects
 535      * in the container.
 536      *
 537      * @return an enumeration of all the ServicePermission objects.
 538      */
 539 
 540     public Enumeration<Permission> elements() {


 567      */
 568     private void writeObject(ObjectOutputStream out) throws IOException {
 569         // Don't call out.defaultWriteObject()
 570 
 571         // Write out Vector
 572         Vector<Permission> permissions = new Vector<>(perms.size());
 573 
 574         synchronized (this) {
 575             permissions.addAll(perms);
 576         }
 577 
 578         ObjectOutputStream.PutField pfields = out.putFields();
 579         pfields.put("permissions", permissions);
 580         out.writeFields();
 581     }
 582 
 583     /*
 584      * Reads in a Vector of ServicePermissions and saves them in the perms field.
 585      */
 586     @SuppressWarnings("unchecked")
 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 the one we want
 595         Vector<Permission> permissions =
 596                 (Vector<Permission>)gfields.get("permissions", null);
 597         perms = new ArrayList<Permission>(permissions.size());
 598         perms.addAll(permissions);
 599     }
 600 }


 242         if ((mask & INITIATE) == INITIATE) {
 243             if (comma) sb.append(',');
 244             else comma = true;
 245             sb.append("initiate");
 246         }
 247 
 248         if ((mask & ACCEPT) == ACCEPT) {
 249             if (comma) sb.append(',');
 250             else comma = true;
 251             sb.append("accept");
 252         }
 253 
 254         return sb.toString();
 255     }
 256 
 257     /**
 258      * Returns the canonical string representation of the actions.
 259      * Always returns present actions in the following order:
 260      * initiate, accept.
 261      */

 262     public String getActions() {
 263         if (actions == null)
 264             actions = getActions(this.mask);
 265 
 266         return actions;
 267     }
 268 
 269 
 270     /**
 271      * Returns a PermissionCollection object for storing
 272      * ServicePermission objects.
 273      * <br>
 274      * ServicePermission objects must be stored in a manner that
 275      * allows them to be inserted into the collection in any order, but
 276      * that also enables the PermissionCollection implies method to
 277      * be implemented in an efficient (and consistent) manner.
 278      *
 279      * @return a new PermissionCollection object suitable for storing
 280      * ServicePermissions.
 281      */

 282     public PermissionCollection newPermissionCollection() {
 283         return new KrbServicePermissionCollection();
 284     }
 285 
 286     /**
 287      * Return the current action mask.
 288      *
 289      * @return the actions mask.
 290      */

 291     int getMask() {
 292         return mask;
 293     }
 294 
 295     /**
 296      * Convert an action string to an integer actions mask.
 297      *
 298      * @param action the action string
 299      * @return the action mask
 300      */

 301     private static int getMask(String action) {
 302 
 303         if (action == null) {
 304             throw new NullPointerException("action can't be null");
 305         }
 306 
 307         if (action.equals("")) {
 308             throw new IllegalArgumentException("action can't be empty");
 309         }
 310 
 311         int mask = NONE;
 312 
 313         char[] a = action.toCharArray();
 314 
 315         int i = a.length - 1;
 316         if (i < 0)
 317             return mask;
 318 
 319         while (i != -1) {
 320             char c;


 447       }
 448     */
 449 
 450 }
 451 
 452 
 453 final class KrbServicePermissionCollection extends PermissionCollection
 454     implements java.io.Serializable {
 455 
 456     // Not serialized; see serialization section at end of class
 457     private transient List<Permission> perms;
 458 
 459     public KrbServicePermissionCollection() {
 460         perms = new ArrayList<Permission>();
 461     }
 462 
 463     /**
 464      * Check and see if this collection of permissions implies the permissions
 465      * expressed in "permission".
 466      *
 467      * @param permission the Permission object to compare
 468      *
 469      * @return true if "permission" is a proper subset of a permission in
 470      * the collection, false if not.
 471      */

 472     public boolean implies(Permission permission) {
 473         if (! (permission instanceof ServicePermission))
 474                 return false;
 475 
 476         ServicePermission np = (ServicePermission) permission;
 477         int desired = np.getMask();
 478         int effective = 0;
 479         int needed = desired;
 480 
 481         synchronized (this) {
 482             int len = perms.size();
 483 
 484             // need to deal with the case where the needed permission has
 485             // more than one action and the collection has individual permissions
 486             // that sum up to the needed.
 487 
 488             for (int i = 0; i < len; i++) {
 489                 ServicePermission x = (ServicePermission) perms.get(i);
 490 
 491                 //System.out.println("  trying "+x);


 495                         return true;
 496                     needed = (desired ^ effective);
 497                 }
 498             }
 499         }
 500         return false;
 501     }
 502 
 503     /**
 504      * Adds a permission to the ServicePermissions. The key for
 505      * the hash is the name.
 506      *
 507      * @param permission the Permission object to add.
 508      *
 509      * @exception IllegalArgumentException - if the permission is not a
 510      *                                       ServicePermission
 511      *
 512      * @exception SecurityException - if this PermissionCollection object
 513      *                                has been marked readonly
 514      */

 515     public void add(Permission permission) {
 516         if (! (permission instanceof ServicePermission))
 517             throw new IllegalArgumentException("invalid permission: "+
 518                                                permission);
 519         if (isReadOnly())
 520             throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
 521 
 522         synchronized (this) {
 523             perms.add(0, permission);
 524         }
 525     }
 526 
 527     /**
 528      * Returns an enumeration of all the ServicePermission objects
 529      * in the container.
 530      *
 531      * @return an enumeration of all the ServicePermission objects.
 532      */
 533 
 534     public Enumeration<Permission> elements() {


 561      */
 562     private void writeObject(ObjectOutputStream out) throws IOException {
 563         // Don't call out.defaultWriteObject()
 564 
 565         // Write out Vector
 566         Vector<Permission> permissions = new Vector<>(perms.size());
 567 
 568         synchronized (this) {
 569             permissions.addAll(perms);
 570         }
 571 
 572         ObjectOutputStream.PutField pfields = out.putFields();
 573         pfields.put("permissions", permissions);
 574         out.writeFields();
 575     }
 576 
 577     /*
 578      * Reads in a Vector of ServicePermissions and saves them in the perms field.
 579      */
 580     @SuppressWarnings("unchecked")
 581     private void readObject(ObjectInputStream in)
 582         throws IOException, ClassNotFoundException
 583     {
 584         // Don't call defaultReadObject()
 585 
 586         // Read in serialized fields
 587         ObjectInputStream.GetField gfields = in.readFields();
 588 
 589         // Get the one we want
 590         Vector<Permission> permissions =
 591                 (Vector<Permission>)gfields.get("permissions", null);
 592         perms = new ArrayList<Permission>(permissions.size());
 593         perms.addAll(permissions);
 594     }
 595 }