|< Day Day Up >|
8.2 Java Permissions
In the Java language, an
, is the right to access a protected resource. The
package provides the abstract class
to represent the right to access a resource. The
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.
class subclasses, directly or indirectly, the
class in package
, specific access rights are represented by
classes that are
Figure 8.3. Permission API Inheritance Tree
8.2.1 Permission Target and Actions
Permission 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
class are also the abstract class
and the final class
. The former represents a collection of homogeneous
s, such as a set of
s. The latter is a
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 Class
When 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 Permissions
The 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.
is invoked on a
object with a
object invokes the
method on the
of the specified
parameter, passing it the
object as a parameter. The
8.2.5 Permission s Implicitly Equivalent to AllPermission
From 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 >|