java.security

Class PermissionCollection

Implemented Interfaces:
Serializable
Known Direct Subclasses:
Permissions

public abstract class PermissionCollection
extends Object
implements Serializable

Abstract class representing a collection of Permission objects.

With a PermissionCollection, you can:

When it is desirable to group together a number of Permission objects of the same type, the newPermissionCollection method on that particular type of Permission object should first be called. The default behavior (from the Permission class) is to simply return null. Subclasses of class Permission override the method if they need to store their permissions in a particular PermissionCollection object in order to provide the correct semantics when the PermissionCollection.implies method is called. If a non-null value is returned, that PermissionCollection must be used. If null is returned, then the caller of newPermissionCollection is free to store permissions of the given type in any PermissionCollection they choose (one that uses a Hashtable, one that uses a Vector, etc).

The PermissionCollection returned by the Permission.newPermissionCollection method is a homogeneous collection, which stores only Permission objects for a given Permission type. A PermissionCollection may also be heterogeneous. For example, Permissions is a PermissionCollection subclass that represents a collection of PermissionCollections. That is, its members are each a homogeneous PermissionCollection. For example, a Permissions object might have a FilePermissionCollection for all the FilePermission objects, a SocketPermissionCollection for all the SocketPermission objects, and so on. Its add method adds a permission to the appropriate collection.

Whenever a permission is added to a heterogeneous PermissionCollection such as Permissions, and the PermissionCollection doesn't yet contain a PermissionCollection of the specified permission's type, the PermissionCollection should call the newPermissionCollection method on the permission's class to see if it requires a special PermissionCollection. If newPermissionCollection returns null, the PermissionCollection is free to store the permission in any type of PermissionCollection it desires (one using a Hashtable, one using a Vector, etc.). For example, the Permissions object uses a default PermissionCollection implementation that stores the permission objects in a Hashtable.

Subclass implementations of PermissionCollection should assume that they may be called simultaneously from multiple threads, and therefore should be synchronized properly. Furthermore, Enumerations returned via the elements method are not fail-fast. Modifications to a collection should not be performed while enumerating over that collection.

See Also:
Permission, Permissions, Serialized Form

Method Summary

abstract void
add(Permission permission)
Adds a permission object to the current collection of permission objects.
abstract Enumeration
elements()
Returns an enumeration of all the Permission objects in the collection.
abstract boolean
implies(Permission permission)
Checks to see if the specified permission is implied by the collection of Permission objects held in this PermissionCollection.
boolean
isReadOnly()
Returns true if this PermissionCollection object is marked as readonly.
void
setReadOnly()
Marks this PermissionCollection object as "readonly".
String
toString()
Returns a string describing this PermissionCollection object, providing information about all the permissions it contains.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

add

public abstract void add(Permission permission)
Adds a permission object to the current collection of permission objects.
Parameters:
permission - the Permission object to add.
Throws:
SecurityException - - if this PermissionCollection object has been marked readonly
Usages and Demos :

View More Examples of add(Permission permission)
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.security.Policy;
   4:         ...
   5: 
   6:     private PermissionCollection permColl = new JGPositivePermissionCollection();
   7:     
   8:         ...
   9:     public void addPermission(Permission permission){
  10:         permColl.add(permission);
  11:     }
  12:         ...
  13:     
  14:     public PermissionCollection getPermissions(CodeSource codesource) {

View Full Code Here
   1: import java.security.CodeSource;
   2: import java.security.PermissionCollection;
   3: import java.security.Principal;
   4:         ...
   5: 
   6:     public PermissionCollection getPermissions(Subject s,
   7:                                                CodeSource cs) {
   8:         ...
   9:         PermissionCollection pc = deferredPolicy.getPermissions(s, cs);
  10:         if (s == null)
  11:         ...
  12:                                                   "read,write,delete");
  13:             pc.add(fp);

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.security.Permissions;
   4:         ...
   5:     public void addPermission(final CodeSource codeSource, final Permission permission) {
   6:         PermissionCollection permissionCollection = (PermissionCollection)permissions
   7:                 .get(codeSource);
   8:         ...
   9:         }
  10:         permissionCollection.add(permission);
  11:     }

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.security.Policy;
   4:         ...
   5: 
   6:     protected PermissionCollection getPermissions(CodeSource codesource)
   7:     {
   8:         ...
   9: 
  10:     PermissionCollection pc = null;
  11:     if (p != null) {
  12:         ...
  13:                 while (items.hasMoreElements()) {
  14:                     pc.add((Permission)(items.nextElement()));

View Full Code Here
   1: import java.security.*;
   2: import java.security.PermissionCollection;
   3: import java.security.ProtectionDomain;
   4:         ...
   5: 
   6:     public PermissionCollection getPermissions(Subject subject, CodeSource cs)
   7:     {
   8:         ...
   9: 
  10:         PermissionCollection perms = null;
  11:         try
  12:         ...
  13:             while (enum.hasMoreElements())
  14:                 perms.add((Permission)enum.nextElement());

View Full Code Here

elements

public abstract Enumeration elements()
Returns an enumeration of all the Permission objects in the collection.
Returns:
an enumeration of all the Permissions.
Usages and Demos :

View More Examples of elements()
   1: 
   2: public class FilterPermissions extends PermissionCollection {
   3: 
   4:         ...
   5:     private PermissionCollection base;
   6:         ...
   7:     private PermissionCollection notPermitted;
   8: 
   9:         ...
  10:     public Enumeration elements() {
  11:     return base.elements();

View Full Code Here
   1: import java.security.*;
   2: import java.security.PermissionCollection;
   3: import java.security.ProtectionDomain;
   4:         ...
   5: 
   6:     public PermissionCollection getPermissions(Subject subject, CodeSource cs)
   7:     {
   8:         ...
   9: 
  10:         PermissionCollection perms = null;
  11:         try
  12:         ...
  13:         {
  14:             java.util.Enumeration enum = perms.elements();

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.util.Collection;
   4:         ...
   5: 
   6: public abstract class JGPermissionCollection extends PermissionCollection {
   7: 
   8:         ...
   9:     
  10:     public void addAll(PermissionCollection pcColl){
  11:         ...
  12:         Enumeration en = pcColl.elements();

View Full Code Here
   1:         if( perms!= null ) {
   2:         Enumeration enum=perms.elements();
   3:         while(enum.hasMoreElements()) {
   4:         ...
   5:         Policy.getPolicy().refresh();
   6:         PermissionCollection pFileP=Policy.getPolicy().getPermissions(cs);
   7:         if( pFileP!= null ) {
   8:         ...
   9:         Enumeration enum=pFileP.elements();
  10:         while(enum.hasMoreElements()) {

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.security.Policy;
   4:         ...
   5:                 String roleName = (String) roleEntry.getKey();
   6:                 PermissionCollection rolePermissions = (PermissionCollection) roleEntry.getValue();
   7:         ...
   8:                 for (Enumeration permissions = rolePermissions.elements(); permissions.hasMoreElements();) {
   9:                     Permission permission = (Permission) permissions.nextElement();

View Full Code Here

implies

public abstract boolean implies(Permission permission)
Checks to see if the specified permission is implied by the collection of Permission objects held in this PermissionCollection.
Parameters:
permission - the Permission object to compare.
Returns:
true if "permission" is implied by the permissions in the collection, false if not.
Usages and Demos :

View More Examples of implies(Permission permission)
   1: 
   2: public class FilterPermissions extends PermissionCollection {
   3: 
   4:         ...
   5:     private PermissionCollection base;
   6:         ...
   7:     private PermissionCollection notPermitted;
   8: 
   9:         ...
  10:     public boolean implies(Permission permission){
  11:     if (notPermitted.implies(permission)){

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: 
   4:         ...
   5:    {
   6:       PermissionCollection pc = p1.newPermissionCollection();
   7:       if (pc == null)
   8:         ...
   9:       {
  10:          return p1.implies(p2);
  11:       }
  12:         ...
  13:       {
  14:          return pc.implies(p2);

View Full Code Here
   1: import java.security.CodeSource;
   2: import java.security.PermissionCollection;
   3: import java.security.Principal;
   4:         ...
   5:     CimomPermission cpm = new CimomPermission(resource,operation);
   6:     PermissionCollection pcl;
   7:     AccessControlContext acc = AccessController.getContext();
   8:         ...
   9: 
  10:     return ( pcl.implies(cpm) );
  11:     }

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.PermissionCollection;
   3: import java.security.Permissions;
   4:         ...
   5:         Principal[] principals = protectionDomain.getPrincipals();
   6:         PermissionCollection perms = new Permissions();
   7:         boolean permImplied = false;
   8:         ...
   9:         {
  10:             permImplied = perms.implies(permission);
  11:         }
  12:         ...
  13: 
  14:     public PermissionCollection getPermissions(ProtectionDomain domain)

View Full Code Here
   1:         Class permClass = perm.getClass();
   2:         PermissionCollection collection;
   3:         synchronized (cachedPermissionCollections) {
   4:         ...
   5:             collection = (PermissionCollection) cachedPermissionCollections.get(permClass);
   6:             if (collection == null) {
   7:         ...
   8:         }
   9:         return collection.implies(perm);
  10:     }

View Full Code Here

isReadOnly

public boolean isReadOnly()
Returns true if this PermissionCollection object is marked as readonly. If it is readonly, no new Permission objects can be added to it using add.

By default, the object is not readonly. It can be set to readonly by a call to setReadOnly.

Returns:
true if this PermissionCollection object is marked as readonly, false otherwise.

setReadOnly

public void setReadOnly()
Marks this PermissionCollection object as "readonly". After a PermissionCollection object is marked as readonly, no new Permission objects can be added to it using add.

toString

public String toString()
Returns a string describing this PermissionCollection object, providing information about all the permissions it contains. The format is:
 super.toString() (
   // enumerate all the Permission
   // objects and call toString() on them,
   // one per line..
 )
super.toString is a call to the toString method of this object's superclass, which is Object. The result is this PermissionCollection's type name followed by this object's hashcode, thus enabling clients to differentiate different PermissionCollections object, even if they contain the same permissions.
Overrides:
toString in interface Object
Returns:
information about this PermissionCollection object, as described above.
Usages and Demos :

View More Examples of toString()
   1:             }
   2:             return new JSTKResult(null, true, msg.toString());
   3:         }
   4:         ...
   5:             }
   6:             return new JSTKResult(null, true, sb.toString());
   7:         }
   8:         ...
   9: 
  10:                 return new JSTKResult(null, true, baos.toString());
  11:             } catch (IOException ioe){
  12:         ...
  13:                 }
  14:                 PermissionCollection permsColl = pDomain.getPermissions();

View Full Code Here
   1: import java.security.AccessControlContext;
   2: import java.security.PermissionCollection;
   3: import java.security.Permissions;
   4:         ...
   5: 
   6:     protected PermissionCollection getPermissions(CodeSource codesource)
   7:     {
   8:         ...
   9:         PermissionCollection perms = super.getPermissions(codesource);
  10:         perms.add(new RuntimePermission("exitVM"));
  11:         ...
  12:         init();
  13:     return perms.toString();

View Full Code Here