Final

java.security
Class AccessController

java.lang.Object
  |
  +--java.security.AccessController

public final class AccessController
extends Object

Checks access to system resources. Supports marking of code as priveleged. Makes context snapshots to allow checking from other contexts.


Method Summary
static void checkPermission(Permission perm)
          Checks whether the running program is allowed to access the resource being guarded by the given Permission argument.
static Object doPrivileged(PrivilegedAction action)
          Performs the privileged action specified by action.
static Object doPrivileged(PrivilegedAction action, AccessControlContext context)
          Performs the privileged action specified by action.
static Object doPrivileged(PrivilegedExceptionAction action)
          Performs the privileged action specified by action.
static Object doPrivileged(PrivilegedExceptionAction action, AccessControlContext context)
          Performs the privileged action specified by action.
static AccessControlContext getContext()
          Answers the access controller context of the current thread, including the inherited ones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkPermission

public static void checkPermission(Permission perm)
                            throws AccessControlException
Checks whether the running program is allowed to access the resource being guarded by the given Permission argument.

Parameters:
perm - the permission to check
Throws:
AccessControlException - if access is not allowed.

getContext

public static AccessControlContext getContext()
Answers the access controller context of the current thread, including the inherited ones. It basically retrieves all the protection domains from the calling stack and creates an AccessControlContext with them.

Returns:
an AccessControlContext which captures the current state
See Also:
AccessControlContext

doPrivileged

public static Object doPrivileged(PrivilegedAction action)
Performs the privileged action specified by action.

When permission checks are made, if the permission has been granted by all frames below and including the one representing the call to this method, then the permission is granted. In otherwords, the check stops here. Any unchecked exception generated by this method will propagate up the chain.

Parameters:
action - The PrivilegedAction to performed
Returns:
the result of the PrivilegedAction
See Also:
doPrivileged(PrivilegedAction)

doPrivileged

public static Object doPrivileged(PrivilegedAction action,
                                  AccessControlContext context)
Performs the privileged action specified by action.

When permission checks are made, if the permission has been granted by all frames below and including the one representing the call to this method, then the permission is granted iff it is granted by the AccessControlContext context. In otherwords, no more checking of the current stack is performed. Instead, the passed in context is checked. Any unchecked exception generated by this method will propagate up the chain.

Parameters:
action - The PrivilegedAction to performed
context - The AccessControlContext to check
Returns:
the result of the PrivilegedAction
See Also:
doPrivileged(PrivilegedAction)

doPrivileged

public static Object doPrivileged(PrivilegedExceptionAction action)
                           throws PrivilegedActionException
Performs the privileged action specified by action.

When permission checks are made, if the permission has been granted by all frames below and including the one representing the call to this method, then the permission is granted. In otherwords, the check stops here. Any unchecked exception generated by this method will propagate up the chain. However, checked exceptions will be caught an re-thrown as PrivilegedActionExceptions

Parameters:
action - The PrivilegedExceptionAction to performed
Returns:
the result of the PrivilegedExceptionAction
Throws:
PrivilegedActionException - when a checked exception occurs when performing the action
See Also:
doPrivileged(PrivilegedAction)

doPrivileged

public static Object doPrivileged(PrivilegedExceptionAction action,
                                  AccessControlContext context)
                           throws PrivilegedActionException
Performs the privileged action specified by action.

When permission checks are made, if the permission has been granted by all frames below and including the one representing the call to this method, then the permission is granted iff it is granted by the AccessControlContext context. In otherwords, no more checking of the current stack is performed. Instead, the passed in context is checked. Any unchecked exception generated by this method will propagate up the chain. However, checked exceptions will be caught an re-thrown as PrivilegedActionExceptions

Parameters:
action - The PrivilegedExceptionAction to performed
context - The AccessControlContext to check
Returns:
the result of the PrivilegedExceptionAction
Throws:
PrivilegedActionException - when a checked exception occurs when performing the action
See Also:
doPrivileged(PrivilegedAction)

Final

Licensed Materials - Property of IBM
(C) Copyright IBM Corp. 2006 All Rights Reserved.