440 |
440 |
441 /** |
441 /** |
442 * Key is property name; value is PropertyPermission. |
442 * Key is property name; value is PropertyPermission. |
443 * Not serialized; see serialization section at end of class. |
443 * Not serialized; see serialization section at end of class. |
444 */ |
444 */ |
445 private transient Map<String, Permission> perms; |
445 private transient Map<String, PropertyPermission> perms; |
446 |
446 |
447 /** |
447 /** |
448 * Boolean saying if "*" is in the collection. |
448 * Boolean saying if "*" is in the collection. |
449 * |
449 * |
450 * @see #serialPersistentFields |
450 * @see #serialPersistentFields |
486 |
486 |
487 PropertyPermission pp = (PropertyPermission) permission; |
487 PropertyPermission pp = (PropertyPermission) permission; |
488 String propName = pp.getName(); |
488 String propName = pp.getName(); |
489 |
489 |
490 synchronized (this) { |
490 synchronized (this) { |
491 PropertyPermission existing = (PropertyPermission) perms.get(propName); |
491 PropertyPermission existing = perms.get(propName); |
492 |
492 |
493 if (existing != null) { |
493 if (existing != null) { |
494 int oldMask = existing.getMask(); |
494 int oldMask = existing.getMask(); |
495 int newMask = pp.getMask(); |
495 int newMask = pp.getMask(); |
496 if (oldMask != newMask) { |
496 if (oldMask != newMask) { |
497 int effective = oldMask | newMask; |
497 int effective = oldMask | newMask; |
498 String actions = PropertyPermission.getActions(effective); |
498 String actions = PropertyPermission.getActions(effective); |
499 perms.put(propName, new PropertyPermission(propName, actions)); |
499 perms.put(propName, new PropertyPermission(propName, actions)); |
500 } |
500 } |
501 } else { |
501 } else { |
502 perms.put(propName, permission); |
502 perms.put(propName, pp); |
503 } |
503 } |
504 } |
504 } |
505 |
505 |
506 if (!all_allowed) { |
506 if (!all_allowed) { |
507 if (propName.equals("*")) |
507 if (propName.equals("*")) |
548 |
548 |
549 String name = pp.getName(); |
549 String name = pp.getName(); |
550 //System.out.println("check "+name); |
550 //System.out.println("check "+name); |
551 |
551 |
552 synchronized (this) { |
552 synchronized (this) { |
553 x = (PropertyPermission) perms.get(name); |
553 x = perms.get(name); |
554 } |
554 } |
555 |
555 |
556 if (x != null) { |
556 if (x != null) { |
557 // we have a direct hit! |
557 // we have a direct hit! |
558 effective |= x.getMask(); |
558 effective |= x.getMask(); |
568 while ((last = name.lastIndexOf(".", offset)) != -1) { |
568 while ((last = name.lastIndexOf(".", offset)) != -1) { |
569 |
569 |
570 name = name.substring(0, last+1) + "*"; |
570 name = name.substring(0, last+1) + "*"; |
571 //System.out.println("check "+name); |
571 //System.out.println("check "+name); |
572 synchronized (this) { |
572 synchronized (this) { |
573 x = (PropertyPermission) perms.get(name); |
573 x = perms.get(name); |
574 } |
574 } |
575 |
575 |
576 if (x != null) { |
576 if (x != null) { |
577 effective |= x.getMask(); |
577 effective |= x.getMask(); |
578 if ((effective & desired) == desired) |
578 if ((effective & desired) == desired) |
590 * Returns an enumeration of all the PropertyPermission objects in the |
590 * Returns an enumeration of all the PropertyPermission objects in the |
591 * container. |
591 * container. |
592 * |
592 * |
593 * @return an enumeration of all the PropertyPermission objects. |
593 * @return an enumeration of all the PropertyPermission objects. |
594 */ |
594 */ |
595 |
595 @SuppressWarnings("unchecked") |
596 public Enumeration<Permission> elements() { |
596 public Enumeration<Permission> elements() { |
597 // Convert Iterator of Map values into an Enumeration |
597 // Convert Iterator of Map values into an Enumeration |
598 synchronized (this) { |
598 synchronized (this) { |
599 return Collections.enumeration(perms.values()); |
599 /** |
|
600 * Casting to rawtype since Enumeration<PropertyPermission> |
|
601 * cannot be directly cast to Enumeration<Permission> |
|
602 */ |
|
603 return (Enumeration)Collections.enumeration(perms.values()); |
600 } |
604 } |
601 } |
605 } |
602 |
606 |
603 private static final long serialVersionUID = 7015263904581634791L; |
607 private static final long serialVersionUID = 7015263904581634791L; |
604 |
608 |
631 */ |
635 */ |
632 private void writeObject(ObjectOutputStream out) throws IOException { |
636 private void writeObject(ObjectOutputStream out) throws IOException { |
633 // Don't call out.defaultWriteObject() |
637 // Don't call out.defaultWriteObject() |
634 |
638 |
635 // Copy perms into a Hashtable |
639 // Copy perms into a Hashtable |
636 Hashtable<String, Permission> permissions = new Hashtable<>(perms.size()*2); |
640 Hashtable<String, Permission> permissions = |
|
641 new Hashtable<>(perms.size()*2); |
637 synchronized (this) { |
642 synchronized (this) { |
638 permissions.putAll(perms); |
643 permissions.putAll(perms); |
639 } |
644 } |
640 |
645 |
641 // Write out serializable fields |
646 // Write out serializable fields |
659 // Get all_allowed |
664 // Get all_allowed |
660 all_allowed = gfields.get("all_allowed", false); |
665 all_allowed = gfields.get("all_allowed", false); |
661 |
666 |
662 // Get permissions |
667 // Get permissions |
663 @SuppressWarnings("unchecked") |
668 @SuppressWarnings("unchecked") |
664 Hashtable<String, Permission> permissions = |
669 Hashtable<String, PropertyPermission> permissions = |
665 (Hashtable<String, Permission>)gfields.get("permissions", null); |
670 (Hashtable<String, PropertyPermission>)gfields.get("permissions", null); |
666 perms = new HashMap<>(permissions.size()*2); |
671 perms = new HashMap<>(permissions.size()*2); |
667 perms.putAll(permissions); |
672 perms.putAll(permissions); |
668 } |
673 } |
669 } |
674 } |