This rule permits key operations the java virtual machine
Chapter 5. The Access Controller 95
Second, the exception handling is somewhat new: we must list the exceptions that the socket constructor can throw in the run( ) method of our embedded class. If either of those exceptions is thrown, it will be encapsulated into a PrivilegedActionException and thrown back to the network monitor, where we can retrieve the actual exception with the getException( ) method.
import java.security.*;
public class PayrollApp {
NetworkMonitor nm;
public void init( ) {
class doInit implements PrivilegedAction { public Object run( ) {
nm = new NetworkMonitor( );
return nm;
}
}
doInit di = new doInit( );
AccessController.doPrivileged(di);
}
}
5.5.1 Access Control Contexts
The access controller works by examining the protection domains of every class on the stack. Sometimes, however, you want the access controller to examine the protection domains of a different set of classes. You do that by using the AccessControlContext class (java.security.AccessControlContext):
5.6 Guarded Objects
The notion of permissions and the access controller can be encapsulated into a single object: a guarded object, which is implemented by the GuardedObject class (java.security.GuardedObject). This class allows you to embed another object within it in such a way that all access to the object will first have to go through a guard (which, typically, is the access controller).
public void checkGuard(Object o)
See if access to the given object should be granted. If access is not
granted, this method should throw an AccessControlException; otherwise
it should silently return.