Package net.jini.security
Interface SecurityContext
public interface SecurityContext
Interface implemented by objects representing security contexts, returned from the
getContext method of the Security class, which in turn may obtain
them from a security manager or policy provider implementing the SecurityContextSource interface. Each SecurityContext
contains an AccessControlContext instance representing the access control context in
place when the security context was snapshotted; this instance can be passed to one of the
doPrivileged methods of the AccessController class to restore
the AccessControlContext portion of the overall security context. Additional state
(if any) carried by the security context can be restored for the duration of a PrivilegedAction or PrivilegedExceptionAction by passing that action to the appropriate
wrap method of the SecurityContext instance, and then executing the returned
"wrapper" action. These two operations--restoring the access control context, and restoring any
additional context encapsulated by the SecurityContext instance--should be performed
in conjunction with a single AccessController.doPrivileged call, as illustrated
below:
// snapshot context
SecurityContext ctx = Security.getContext();
// restore context
AccessController.doPrivileged(
ctx.wrap(action), ctx.getAccessControlContext());
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionReturns access control context portion of snapshotted security context.wrap(PrivilegedAction action) Returns a security context-restoringPrivilegedActionthat wraps the given action, or returns the action itself if the security context does not include any non-AccessControlContextstate to restore.wrap(PrivilegedExceptionAction action) Returns a security context-restoringPrivilegedExceptionActionthat wraps the given action, or returns the action itself if the security context does not include any non-AccessControlContextstate to restore.
-
Method Details
-
wrap
Returns a security context-restoringPrivilegedActionthat wraps the given action, or returns the action itself if the security context does not include any non-AccessControlContextstate to restore. Therunmethod of the "wrapper" action (if any) restores the non-AccessControlContextstate of the security context before invoking therunmethod of the wrapped action, and unrestores that state after the wrapped action'srunmethod has completed (normally or otherwise). The value returned or exception thrown by the wrapped action'srunmethod is propagated through therunmethod of the wrapper action.- Parameters:
action- the action to be wrapped- Returns:
- security context-restoring action wrapping
action, oractionif no wrapping is necessary - Throws:
NullPointerException- ifactionisnull
-
wrap
Returns a security context-restoringPrivilegedExceptionActionthat wraps the given action, or returns the action itself if the security context does not include any non-AccessControlContextstate to restore. Therunmethod of the "wrapper" action (if any) restores the non-AccessControlContextstate of the security context before invoking therunmethod of the wrapped action, and unrestores that state after the wrapped action'srunmethod has completed (normally or otherwise). The value returned or exception thrown by the wrapped action'srunmethod is propagated through therunmethod of the wrapper action.- Parameters:
action- the action to be wrapped- Returns:
- security context-restoring action wrapping
action, oractionif no wrapping is necessary - Throws:
NullPointerException- ifactionisnull
-
getAccessControlContext
AccessControlContext getAccessControlContext()Returns access control context portion of snapshotted security context.- Returns:
- access control context portion of snapshotted security context
-