java.security

Class Permissions

Implemented Interfaces:
Serializable

public final class Permissions
extends PermissionCollection
implements Serializable

This class represents a heterogeneous collection of Permissions. That is, it contains different types of Permission objects, organized into PermissionCollections. For example, if any java.io.FilePermission objects are added to an instance of this class, they are all stored in a single PermissionCollection. It is the PermissionCollection returned by a call to the newPermissionCollection method in the FilePermission class. Similarly, any java.lang.RuntimePermission objects are stored in the PermissionCollection returned by a call to the newPermissionCollection method in the RuntimePermission class. Thus, this class represents a collection of PermissionCollections.

When the add method is called to add a Permission, the Permission is stored in the appropriate PermissionCollection. If no such collection exists yet, the Permission object's class is determined and the newPermissionCollection method is called on that class to create the PermissionCollection and add it to the Permissions object. If newPermissionCollection returns null, then a default PermissionCollection that uses a hashtable will be created and used. Each hashtable entry stores a Permission object as both the key and the value.

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, PermissionCollection, AllPermission, Serialized Form

Constructor Summary

Permissions()
Creates a new Permissions object containing no PermissionCollections.

Method Summary

void
add(Permission permission)
Adds a permission object to the PermissionCollection for the class the permission belongs to.
Enumeration
elements()
Returns an enumeration of all the Permission objects in all the PermissionCollections in this Permissions object.
boolean
implies(Permission permission)
Checks to see if this object's PermissionCollection for permissions of the specified permission's type implies the permissions expressed in the permission object.

Methods inherited from class java.security.PermissionCollection

add, elements, implies, isReadOnly, setReadOnly, toString

Methods inherited from class java.lang.Object

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

Constructor Details

Permissions

public Permissions()
Creates a new Permissions object containing no PermissionCollections.
Usages and Demos :

View More Examples of Permissions()
   1:     this.base = base;
   2:     PermissionCollection col = new Permissions();
   3:     col.add(notPermitted);
   4:     this.notPermitted = col;
   5:     }

View Full Code Here
   1:             allow = b;
   2:             perms = new Permissions();
   3:             if (allow)
   4:                 perms.add(new AllPermission());
   5:         }

View Full Code Here
   1:       
   2:       perms = new Permissions();
   3:       perms.add(new java.util.PropertyPermission("*","read"));
   4:       perms.add(new java.lang.RuntimePermission("queuePrintJob"));
   5:       perms.add(new java.net.SocketPermission("*","connect"));

View Full Code Here
   1:     {
   2:         return new Permissions();
   3:     }
   4: 
   5:     public boolean implies( ProtectionDomain domain, Permission perm )

View Full Code Here
   1:         if (permissionCollection == null) {
   2:             permissionCollection = new Permissions();
   3:             permissions.put(codeSource, permissionCollection);
   4:         }
   5:         permissionCollection.add(permission);

View Full Code Here

Method Details

add

public void add(Permission permission)
Adds a permission object to the PermissionCollection for the class the permission belongs to. For example, if permission is a FilePermission, it is added to the FilePermissionCollection stored in this Permissions object. This method creates a new PermissionCollection object (and adds the permission to it) if an appropriate collection does not yet exist.

Overrides:
add in interface PermissionCollection
Parameters:
permission - the Permission object to add.
Throws:
SecurityException - if this Permissions object is marked as readonly.
Usages and Demos :

View More Examples of add(Permission permission)
   1:         boolean allow;
   2:         Permissions perms;
   3: 
   4:         ...
   5:             allow = b;
   6:             perms = new Permissions();
   7:             if (allow)
   8:         ...
   9:                              "Can?t add to this collection");
  10:             perms.add(p);
  11:         }

View Full Code Here
   1: import java.security.PermissionCollection;
   2: import java.security.Permissions;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private Permissions others;
   7: 
   8:         ...
   9:     private Permissions permissions = new Permissions();
  10: 
  11:         ...
  12:                 }
  13:                 resources.add(permission);

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.Permissions;
   3: 
   4:         ...
   5: 
   6:     private Permissions permissions = new Permissions();
   7:     private static final Permission setSecurityManagerPerm =
   8:         ...
   9:     public MockSecurityManager() {
  10:         permissions.add(setSecurityManagerPerm);
  11:     }
  12:         ...
  13:     public void addPermission(Permission p) {
  14:         permissions.add(p);

View Full Code Here
   1:     protected void addDefaultPermissions( Context context,String base,
   2:                       Permissions p )
   3:     {
   4:         ...
   5:     if( fp != null )
   6:         p.add((Permission)fp);
   7:     
   8:         ...
   9:         
  10:         Permissions p = (Permissions)context.getPermissions();
  11:         
  12:         ...
  13:         while(enum.hasMoreElements()) {
  14:             p.add((Permission)enum.nextElement());

View Full Code Here
   1: import java.security.PermissionCollection;
   2: import java.security.Permissions;
   3: import java.security.Principal;
   4:         ...
   5:     private HashMap principalRoleMapping = new HashMap();
   6:     private Permissions unchecked = null;
   7:         ...
   8:     private Permissions excluded = null;
   9: 
  10:         ...
  11:             }
  12:             roles.add(role);

View Full Code Here

elements

public Enumeration elements()
Returns an enumeration of all the Permission objects in all the PermissionCollections in this Permissions object.
Overrides:
elements in interface PermissionCollection
Returns:
an enumeration of all the Permissions.
Usages and Demos :

View More Examples of elements()
   1:         boolean allow;
   2:         Permissions perms;
   3: 
   4:         ...
   5:             allow = b;
   6:             perms = new Permissions();
   7:             if (allow)
   8:         ...
   9:         public Enumeration elements() {
  10:             return perms.elements();
  11:         }

View Full Code Here
   1: import java.security.CodeSource;
   2: import java.security.Permissions;
   3: import java.security.Permission;
   4:         ...
   5: 
   6:   private static Permissions defaultPerms = new Permissions();
   7:   static {
   8:         ...
   9:       defaultPerms = new Permissions();
  10:       for (Enumeration enu = perms.elements(); enu.hasMoreElements();) {
  11:         defaultPerms.add((Permission)enu.nextElement());
  12:         ...
  13:       PermissionCollection parentPc = super.getPermissions(cs);
  14:       for (Enumeration enu = parentPc.elements(); enu.hasMoreElements();) {

View Full Code Here
   1: import java.security.Permission;
   2: import java.security.Permissions;
   3: import java.security.Principal;
   4:         ...
   5:             pms.removePermissions(user);
   6:             Permissions permissions = pms.getPermissions(user);
   7:             assertEquals(
   8:         ...
   9:                 0,
  10:                 (Collections.list(permissions.elements())).size());
  11:         }
  12:         ...
  13:                     + "}, in collection of size == 1, actual size: "
  14:                     + (Collections.list(permCol1.elements())).size(),

View Full Code Here
   1: 
   2:     private Permissions excludedPermissions = null;
   3:         ...
   4:     private Permissions uncheckedPermissions = null;
   5:     private HashMap rolePermissionsTable = null;
   6:         ...
   7: 
   8:     public void addToRole(String roleName, PermissionCollection permissions)
   9:     throws PolicyContextException
  10:         ...
  11:         checkSetPolicyPermission();
  12:         for(Enumeration e = permissions.elements(); e.hasMoreElements();) {

View Full Code Here

implies

public boolean implies(Permission permission)
Checks to see if this object's PermissionCollection for permissions of the specified permission's type implies the permissions expressed in the permission object. Returns true if the combination of permissions in the appropriate PermissionCollection (e.g., a FilePermissionCollection for a FilePermission) together imply the specified permission.

For example, suppose there is a FilePermissionCollection in this Permissions object, and it contains one FilePermission that specifies "read" access for all files in all subdirectories of the "/tmp" directory, and another FilePermission that specifies "write" access for all files in the "/tmp/scratch/foo" directory. Then if the implies method is called with a permission specifying both "read" and "write" access to files in the "/tmp/scratch/foo" directory, true is returned.

Additionally, if this PermissionCollection contains the AllPermission, this method will always return true.

Overrides:
implies in interface PermissionCollection
Parameters:
permission - the Permission object to check.
Returns:
true if "permission" is implied by the permissions in the PermissionCollection it belongs to, false if not.
Usages and Demos :

View More Examples of implies(Permission permission)
   1: import java.security.PermissionCollection;
   2: import java.security.Permissions;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private Permissions others;
   7: 
   8:         ...
   9:     private Permissions permissions = new Permissions();
  10: 
  11:         ...
  12:     {
  13:         return permissions.implies(permission);

View Full Code Here
   1: import java.security.PermissionCollection;
   2: import java.security.Permissions;
   3: import java.security.ProtectionDomain;
   4:         ...
   5:     static class AdjustablePolicy extends java.security.Policy {
   6:         Permissions perms = new Permissions();
   7: 
   8:         ...
   9:         public boolean implies(ProtectionDomain pd, Permission p) {
  10:             return perms.implies(p);
  11:         }

View Full Code Here
   1:     static class AdjustablePolicy extends java.security.Policy {
   2:         Permissions perms = new Permissions();
   3:         AdjustablePolicy() { }
   4:         ...
   5:         void addPermission(Permission perm) { perms.add(perm); }
   6:         void clearPermissions() { perms = new Permissions(); }
   7:         public PermissionCollection getPermissions(CodeSource cs) {
   8:         ...
   9:         public boolean implies(ProtectionDomain pd, Permission p) {
  10:             return perms.implies(p);
  11:         }

View Full Code Here