AccessControlContext (Java SE 9 & JDK 9 ) (original) (raw)

An AccessControlContext is used to make system resource access decisions based on the context it encapsulates.

More specifically, it encapsulates a context and has a single method, checkPermission, that is equivalent to the checkPermission method in the AccessController class, with one difference: The AccessControlContextcheckPermission method makes access decisions based on the context it encapsulates, rather than that of the current execution thread.

Thus, the purpose of AccessControlContext is for those situations where a security check that should be made within a given context actually needs to be done from within a_different_ context (for example, from within a worker thread).

An AccessControlContext is created by calling theAccessController.getContext method. The getContext method takes a "snapshot" of the current calling context, and places it in an AccessControlContext object, which it returns. A sample call is the following:

AccessControlContext acc = AccessController.getContext()

Code within a different context can subsequently call thecheckPermission method on the previously-saved AccessControlContext object. A sample call is the following:

acc.checkPermission(permission)