public final class

AccessController

extends Object
java.lang.Object
   ↳ java.security.AccessController

Class Overview

AccessController provides static methods to perform access control checks and privileged operations.

Summary

Public Methods
static void checkPermission(Permission permission)
Checks the specified permission against the VM's current security policy.
static <T> T doPrivileged(PrivilegedExceptionAction<T> action)
Returns the result of executing the specified privileged action.
static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context)
Returns the result of executing the specified privileged action.
static <T> T doPrivileged(PrivilegedAction<T> action)
Returns the result of executing the specified privileged action.
static <T> T doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context)
Returns the result of executing the specified privileged action.
static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action)
static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
static AccessControlContext getContext()
Returns the AccessControlContext for the current Thread including the inherited access control context of the thread that spawned the current thread (recursively).
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void checkPermission (Permission permission)

Since: API Level 1

Checks the specified permission against the VM's current security policy. The check is performed in the context of the current thread. This method returns silently if the permission is granted, otherwise an AccessControlException is thrown.

A permission is considered granted if every ProtectionDomain in the current execution context has been granted the specified permission. If privileged operations are on the execution context, only the ProtectionDomains from the last privileged operation are taken into account.

This method delegates the permission check to checkPermission(Permission) on the current callers' context obtained by getContext().

Parameters
permission the permission to check against the policy
Throws
AccessControlException if the specified permission is not granted
NullPointerException if the specified permission is null

public static T doPrivileged (PrivilegedExceptionAction<T> action)

Since: API Level 1

Returns the result of executing the specified privileged action. Only the ProtectionDomain of the direct caller of this method and the ProtectionDomains of all subsequent classes in the call chain are checked to be granted the necessary permission if access checks are performed.

If a checked exception is thrown by the action's run method, it will be wrapped and propagated through this method.

If an instance of RuntimeException is thrown during the execution of the PrivilegedAction#run() method of the given action, it will be propagated through this method.

Parameters
action the action to be executed with privileges
Returns
  • the result of executing the privileged action
Throws
PrivilegedActionException if the action's run method throws any checked exception
NullPointerException if the specified action is null

public static T doPrivileged (PrivilegedAction<T> action, AccessControlContext context)

Since: API Level 1

Returns the result of executing the specified privileged action. The ProtectionDomain of the direct caller of this method, the ProtectionDomains of all subsequent classes in the call chain and all ProtectionDomains of the given context are checked to be granted the necessary permission if access checks are performed.

If an instance of RuntimeException is thrown during the execution of the PrivilegedAction#run() method of the given action, it will be propagated through this method.

Parameters
action the action to be executed with privileges
context the AccessControlContext whose protection domains are checked additionally
Returns
  • the result of executing the privileged action
Throws
NullPointerException if the specified action is null

public static T doPrivileged (PrivilegedAction<T> action)

Since: API Level 1

Returns the result of executing the specified privileged action. Only the ProtectionDomain of the direct caller of this method and the ProtectionDomains of all subsequent classes in the call chain are checked to be granted the necessary permission if access checks are performed.

If an instance of RuntimeException is thrown during the execution of the PrivilegedAction#run() method of the given action, it will be propagated through this method.

Parameters
action the action to be executed with privileges
Returns
  • the result of executing the privileged action
Throws
NullPointerException if the specified action is null

public static T doPrivileged (PrivilegedExceptionAction<T> action, AccessControlContext context)

Since: API Level 1

Returns the result of executing the specified privileged action. The ProtectionDomain of the direct caller of this method, the ProtectionDomains of all subsequent classes in the call chain and all ProtectionDomains of the given context are checked to be granted the necessary permission if access checks are performed.

If a checked exception is thrown by the action's run method, it will be wrapped and propagated through this method.

If an instance of RuntimeException is thrown during the execution of the PrivilegedAction#run() method of the given action, it will be propagated through this method.

Parameters
action the action to be executed with privileges
context the AccessControlContext whose protection domains are checked additionally
Returns
  • the result of executing the privileged action
Throws
PrivilegedActionException if the action's run method throws any checked exception
NullPointerException if the specified action is null

public static T doPrivilegedWithCombiner (PrivilegedAction<T> action)

Since: API Level 9

public static T doPrivilegedWithCombiner (PrivilegedExceptionAction<T> action)

Since: API Level 9

public static AccessControlContext getContext ()

Since: API Level 1

Returns the AccessControlContext for the current Thread including the inherited access control context of the thread that spawned the current thread (recursively).

The returned context may be used to perform access checks at a later point in time, possibly by another thread.

Returns
  • the AccessControlContext for the current Thread
See Also