java.security
Class Permission

java.lang.Object
  extended by java.security.Permission
All Implemented Interfaces:
Serializable, Guard
Direct Known Subclasses:
AllPermission, BasicPermission, FilePermission, MBeanPermission, PrivateCredentialPermission, ServicePermission, SocketPermission, UnresolvedPermission

public abstract class Permission
extends Object
implements Guard, Serializable

This class is the abstract superclass of all classes that implement the concept of a permission. A permission consists of a permission name and optionally a list of actions that relate to the permission. The actual meaning of the name of the permission is defined only in the context of a subclass. It may name a resource to which access permissions are granted (for example, the name of a file) or it might represent something else entirely. Similarly, the action list only has meaning within the context of a subclass. Some permission names may have no actions associated with them. That is, you either have the permission or you don't.

The most important method in this class is implies. This checks whether if one has this permission, then the specified permission is also implied. As a conceptual example, consider the permissions "Read All Files" and "Read File foo". The permission "Read All Files" implies that the caller has permission to read the file foo.

Permission's must be immutable - do not change their state after creation.

Since:
1.1
See Also:
Permissions, PermissionCollection, Serialized Form

Constructor Summary
Permission(String name)
          Create an instance with the specified name.
 
Method Summary
 void checkGuard(Object obj)
          This method implements the Guard interface for this class.
abstract  boolean equals(Object obj)
          Check to see if this object equals obj.
abstract  String getActions()
          This method returns the list of actions for this Permission as a String.
 String getName()
          Get the name of this Permission.
abstract  int hashCode()
          This method returns a hash code for this Permission.
abstract  boolean implies(Permission perm)
          This method tests whether this Permission implies that the specified Permission is also granted.
 PermissionCollection newPermissionCollection()
          This method returns an empty PermissionCollection object that can store permissions of this type, or null if no such collection is defined.
 String toString()
          This method returns a String representation of this Permission object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Permission

public Permission(String name)
Create an instance with the specified name.

Parameters:
name - the permission name
Method Detail

checkGuard

public void checkGuard(Object obj)
This method implements the Guard interface for this class. It calls the checkPermission method in SecurityManager with this Permission as its argument. This method returns silently if the security check succeeds or throws an exception if it fails.

Specified by:
checkGuard in interface Guard
Parameters:
obj - the Object being guarded - ignored by this class
Throws:
SecurityException - if the security check fails
See Also:
GuardedObject, SecurityManager.checkPermission(Permission)

implies

public abstract boolean implies(Permission perm)
This method tests whether this Permission implies that the specified Permission is also granted.

Parameters:
perm - the Permission to test against
Returns:
true if perm is implied by this

equals

public abstract boolean equals(Object obj)
Check to see if this object equals obj. Use implies, rather than equals, when making access control decisions.

Overrides:
equals in class Object
Parameters:
obj - the object to compare to
Returns:
whether this Object is semantically equal to another
See Also:
Object.hashCode()

hashCode

public abstract int hashCode()
This method returns a hash code for this Permission. It must satisfy the contract of Object.hashCode: it must be the same for all objects that equals considers to be the same.

Overrides:
hashCode in class Object
Returns:
a hash value
See Also:
Object.equals(Object), System.identityHashCode(Object)

getName

public final String getName()
Get the name of this Permission.

Returns:
the name

getActions

public abstract String getActions()
This method returns the list of actions for this Permission as a String. The string should be in canonical order, for example, both new FilePermission(f, "write,read") and new FilePermission(f, "read,write") have the action list "read,write".

Returns:
the action list for this Permission

newPermissionCollection

public PermissionCollection newPermissionCollection()
This method returns an empty PermissionCollection object that can store permissions of this type, or null if no such collection is defined. Subclasses must override this to provide an appropriate collection when one is needed to accurately calculate implies.

Returns:
a new PermissionCollection

toString

public String toString()
This method returns a String representation of this Permission object. This is in the format: '(' + getClass().getName() + ' ' + getName() + ' ' + getActions + ')'.

Overrides:
toString in class Object
Returns:
this object as a String
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)