Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Both the single and double argument checkPermission() methods defer to the single argument java.security.AccessController.checkPermission(Permission perm) method. When invoked directly, this method operates only on the current execution context and as a result, does not supersede the security manager's two argument version.

There is also another (cleaner and preferable) way to handle the A cleaner approach to making a security check from a different context . This is accomplished by taking is to take a snapshot of the current execution context in which the check must be performed, using the java.security.AccessController.getContext() method that returns an AccessControlContext object. The AccessControlContext class itself defines a checkPermission() method that encapsulates a context instead of accepting the current executing context as a parameter. This is allows the check to be performed at a later time, as shown below.

Code Block
bgColor#ccccff
// Take the snapshot of the required context, store in acc and pass it to another context
AccessControlContext acc = AccessController.getContext();

// Accept acc in another context and invoke checkPermission() on it
acc.checkPermission(perm);

...