| < Day Day Up > |
8.2 Java Permissions
In the Java language, an
authorization
, or
permission
, is the right to access a protected resource. The
java.security
package provides the abstract class
Permission
to represent the right to access a resource. The
Permission
class is subclassed to represent specific access rights. Several subclasses of this class are available in the Java
You can define your own specific Permission classes by subclassing this class or by using available concrete subclasses, such as java.security.BasicPermission . Custom Permission s designed for network distribution can be signed. At runtime, the JVM will check the signature to authenticate the originator of the code.
Although each
Permission
class subclasses, directly or indirectly, the
Permission
class in package
java.security
, specific access rights are represented by
Permission
classes that are
Figure 8.3. Permission API Inheritance Tree
8.2.1 Permission Target and ActionsPermission s may have a target and an optional list of actions. A target represents a protected system resource, and an action represents the type of access on the resource. For example, in java.io.FilePermission "C:\AUTOEXEC.BAT", "read, write, execute" , the target object is the local file C:\AUTOEXEC.BAT , and the actions are read, write, and execute. Some Permission s have only a target. For example, the java.lang.RuntimePermission with target "exitVM" protects the JVM against those codes that attempt to exit the JVM, but no action list is associated with this type of resource. Finally, some Permission s may not have a target. This is the case, for example, for java.security.AllPermission , which grants code full access to all the system resources. 8.2.2 The PermissionCollection and Permissions Classes
Associated with the
Permission
class are also the abstract class
java.security.PermissionCollection
and the final class
java.security.Permissions
. The former represents a collection of homogeneous
Permission
s, such as a set of
FilePermission
s. The latter is a
PermissionCollection
subclass and is used to
Figure 8.4. Relation between the Permission , PermissionCollection , and Permissions Classes
Permission classes are responsible for defining the type of PermissionCollection in which they should be grouped. The type of PermissionCollection is defined by overriding the newPermissionCollection() method inherited from the Permission superclass. 8.2.3 The implies() Method in the Permission ClassWhen implementing a subclass of the Permission class, it is crucial to implement the abstract method implies() , which returns a boolean . Here, a implies b means that granting an application Permission a automatically grants it Permission b too. For example, giving some code AllPermission implies giving all the rest of the Permission s. Similarly, the Permission java.io.FilePermission "/tmp/*", "read" implies the Permission java.io.FilePermission "/tmp/readme.txt", "read" . The BasicPermission class offers a simple implementation of the implies() method, which is sufficient in most cases for those custom Permissions that have only a target. If the custom Permission requires the concept of an action too, it is advisable to directly subclass the Permission class. 8.2.4 The implies() Method in PermissionCollection and PermissionsThe PermissionCollection class also has an implies() method that takes a Permission object as a parameter and returns a boolean . Because Permissions subclasses PermissionCollection , an implies() method that takes a Permission object as a parameter and returns a boolean is also available in the Permissions class.
When
implies()
is invoked on a
Permissions
object with a
Permission
parameter, the
Permissions
object invokes the
implies()
method on the
PermissionCollection
of the specified
Permission
parameter, passing it the
Permission
object as a parameter. The
PermissionCollection
object, in
8.2.5 Permission s Implicitly Equivalent to AllPermissionFrom what we said about AllPermission , it is clear that much caution is needed when granting this Permission . In this section, we study other Permission s that are implicitly equivalent to AllPermission . Extreme care should be used when granting AllPermission and any of the following Permission s.
|
| < Day Day Up > |