Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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

Method Summary
`AccessControlContext` | `getAccessControlContext()` Returns access control context portion of snapshotted security context.
`PrivilegedAction` | `wrap(PrivilegedAction action)` Returns a security context-restoring `PrivilegedAction` that wraps the given action, or returns the action itself if the security context does not include any non-`AccessControlContext` state to restore.
`PrivilegedExceptionAction` | `wrap(PrivilegedExceptionAction action)` Returns a security context-restoring `PrivilegedExceptionAction` that wraps the given action, or returns the action itself if the security context does not include any non-`AccessControlContext` state to restore.

Method Detail

### wrap

    public PrivilegedAction wrap(PrivilegedAction action)

  Returns a security context-restoring `PrivilegedAction` that wraps the given action, or returns the action itself if the security context does not include any non-`AccessControlContext` state to restore. The `run` method of the "wrapper" action (if any) restores the non-`AccessControlContext` state of the security context before invoking the `run` method of the wrapped action, and unrestores that state after the wrapped action's `run` method has completed (normally or otherwise). The value returned or exception thrown by the wrapped action's `run` method is propagated through the `run` method of the wrapper action.

  Parameters:
    `action` - the action to be wrapped
  Returns:
    security context-restoring action wrapping `action`, or `action` if no wrapping is necessary
  Throws:
    `NullPointerException` - if `action` is `null`

### wrap

    public PrivilegedExceptionAction wrap(PrivilegedExceptionAction action)

  Returns a security context-restoring `PrivilegedExceptionAction` that wraps the given action, or returns the action itself if the security context does not include any non-`AccessControlContext` state to restore. The `run` method of the "wrapper" action (if any) restores the non-`AccessControlContext` state of the security context before invoking the `run` method of the wrapped action, and unrestores that state after the wrapped action's `run` method has completed (normally or otherwise). The value returned or exception thrown by the wrapped action's `run` method is propagated through the `run` method of the wrapper action.

  Parameters:
    `action` - the action to be wrapped
  Returns:
    security context-restoring action wrapping `action`, or `action` if no wrapping is necessary
  Throws:
    `NullPointerException` - if `action` is `null`

### getAccessControlContext

    public AccessControlContext getAccessControlContext()

  Returns access control context portion of snapshotted security context.

  Returns:
    access control context portion of snapshotted security context

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004 Sun Microsystems, Inc. All rights reserved