Top Description Inners Constructors Methods
java.security

public final Class AccessController

extends Object
Class Inheritance
Annotations
@Deprecated
since:17
forRemoval:true
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target, java.lang.ref.Reference, jdk.internal.vm.annotation.Hidden, .DontInline, .ForceInline, .ReservedStackAccess, sun.security.util.Debug, .SecurityConstants, jdk.internal.reflect.CallerSensitive, .Reflection

Deprecated

for removal since 17.

This class is only useful in conjunction with the Security Manager, which is deprecated and subject to removal in a future release. Consequently, this class is also deprecated and subject to removal. There is no replacement for the Security Manager or this class.

The AccessController class is used for access control operations and decisions.

More specifically, the AccessController class is used for three purposes:

The checkPermission method determines whether the access request indicated by a specified permission should be granted or denied. A sample call appears below. In this example, checkPermission will determine whether or not to grant "read" access to the file named "testFile" in the "/temp" directory.


FilePermission perm = new FilePermission("/temp/testFile", "read");
AccessController.checkPermission(perm);

If a requested access is allowed, checkPermission returns quietly. If denied, an AccessControlException is thrown. AccessControlException can also be thrown if the requested permission is of an incorrect type or contains an invalid value. Such information is given whenever possible. Suppose the current thread traversed m callers, in the order of caller 1 to caller 2 to caller m. Then caller m invoked the checkPermission method. The checkPermission method determines whether access is granted or denied based on the following algorithm:

 for (int i = m; i > 0; i--) {

    if (caller i's domain does not have the permission)
        throw AccessControlException

    else if (caller i is marked as privileged) {
        if (a context was specified in the call to doPrivileged)
            context.checkPermission(permission)
        if (limited permissions were specified in the call to doPrivileged) {
            for (each limited permission) {
                if (the limited permission implies the requested permission)
                    return;
            }
        } else
            return;
    }
}

// Next, check the context inherited when the thread was created.
// Whenever a new thread is created, the AccessControlContext at
// that time is stored and associated with the new thread, as the
// "inherited" context.

inheritedContext.checkPermission(permission);

A caller can be marked as being "privileged" (see doPrivileged and below). When making access control decisions, the checkPermission method stops checking if it reaches a caller that was marked as "privileged" via a doPrivileged call without a context argument (see below for information about a context argument). If that caller's domain has the specified permission and at least one limiting permission argument (if any) implies the requested permission, no further checking is done and checkPermission returns quietly, indicating that the requested access is allowed. If that domain does not have the specified permission, an exception is thrown, as usual. If the caller's domain had the specified permission but it was not implied by any limiting permission arguments given in the call to doPrivileged then the permission checking continues until there are no more callers or another doPrivileged call matches the requested permission and returns normally.

The normal use of the "privileged" feature is as follows. If you don't need to return a value from within the "privileged" block, do the following:

 somemethod() {
    ...normal code here...
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        public Void run() {
            // privileged code goes here, for example:
            System.loadLibrary("awt");
            return null; // nothing to return
        }
    });
    ...normal code here...
}

PrivilegedAction is an interface with a single method, named run. The above example shows creation of an implementation of that interface; a concrete implementation of the run method is supplied. When the call to doPrivileged is made, an instance of the PrivilegedAction implementation is passed to it. The doPrivileged method calls the run method from the PrivilegedAction implementation after enabling privileges, and returns the run method's return value as the doPrivileged return value (which is ignored in this example).

If you need to return a value, you can do something like the following:

 somemethod() {
    ...normal code here...
    String user = AccessController.doPrivileged(
        new PrivilegedAction<String>() {
        public String run() {
            return System.getProperty("user.name");
            }
        });
    ...normal code here...
}

If the action performed in your run method could throw a "checked" exception (those listed in the throws clause of a method), then you need to use the PrivilegedExceptionAction interface instead of the PrivilegedAction interface:

 somemethod() throws FileNotFoundException {
    ...normal code here...
    try {
        FileInputStream fis = AccessController.doPrivileged(
        new PrivilegedExceptionAction<FileInputStream>() {
            public FileInputStream run() throws FileNotFoundException {
                return new FileInputStream("someFile");
            }
        });
    } catch (PrivilegedActionException e) {
        // e.getException() should be an instance of FileNotFoundException,
        // as only "checked" exceptions will be "wrapped" in a
        // PrivilegedActionException.
        throw (FileNotFoundException) e.getException();
    }
    ...normal code here...
 }

Be *very* careful in your use of the "privileged" construct, and always remember to make the privileged code section as small as possible. You can pass Permission arguments to further limit the scope of the "privilege" (see below).

Note that checkPermission always performs security checks within the context of the currently executing thread. Sometimes a security check that should be made within a given context will actually need to be done from within a different context (for example, from within a worker thread). The getContext method and AccessControlContext class are provided for this situation. 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()

AccessControlContext itself has a checkPermission method that makes access decisions based on the context it encapsulates, rather than that of the current execution thread. Code within a different context can thus call that method on the previously-saved AccessControlContext object. A sample call is the following:


acc.checkPermission(permission)

There are also times where you don't know a priori which permissions to check the context against. In these cases you can use the doPrivileged method that takes a context. You can also limit the scope of the privileged code by passing additional Permission parameters.

 somemethod() {
    AccessController.doPrivileged(new PrivilegedAction<Object>() {
        public Object run() {
            // Code goes here. Any permission checks within this
            // run method will require that the intersection of the
            // caller's protection domain and the snapshot's
            // context have the desired permission. If a requested
            // permission is not implied by the limiting FilePermission
            // argument then checking of the thread continues beyond the
            // caller of doPrivileged.
        }
    }, acc, new FilePermission("/temp/*", read));
    ...normal code here...
}

Passing a limiting Permission argument of an instance of AllPermission is equivalent to calling the equivalent doPrivileged method without limiting Permission arguments. Passing a zero length array of Permission disables the code privileges so that checking always continues beyond the caller of that doPrivileged method.

Authors
Li Gong, Roland Schemers
Since
1.2
See Also
AccessControlContext

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
private
AccessController()

Don't allow anyone to instantiate an AccessController

Method Summary

Modifier and TypeMethod and Description
private static AccessControlContext
checkContext(AccessControlContext context, Class<?> caller)

Deprecated as a consequence of AccessControlContext being deprecated.
public static void
checkPermission(Permission
the requested permission.
perm
)

Determines whether the access request indicated by the specified permission should be allowed or denied, based on the current AccessControlContext and security policy.

private static AccessControlContext
createWrapper(DomainCombiner combiner, Class<?> caller, AccessControlContext parent, AccessControlContext context, Permission[] perms)

Deprecated as a consequence of DomainCombiner and AccessControlContext being deprecated.
Create a wrapper to contain the limited privilege scope data.
public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivileged
(PrivilegedAction<T>
the action to be performed.
action
)

Performs the specified PrivilegedAction with privileges enabled.

public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivileged
(PrivilegedAction<T>
the action to be performed.
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext.
public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivileged
(PrivilegedAction<T>
the action to be performed.
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
,
Permission...
the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.
perms
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments.
public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the action's run method
doPrivileged
(PrivilegedExceptionAction<T>
the action to be performed
action
)

Performs the specified PrivilegedExceptionAction with privileges enabled.

public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the action's run method
doPrivileged
(PrivilegedExceptionAction<T>
the action to be performed
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext.
public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivileged
(PrivilegedExceptionAction<T>
the action to be performed.
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
,
Permission...
the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.
perms
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments.
public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivilegedWithCombiner
(PrivilegedAction<T>
the action to be performed.
action
)

Performs the specified PrivilegedAction with privileges enabled.

public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivilegedWithCombiner
(PrivilegedAction<T>
the action to be performed.
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
,
Permission...
the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.
perms
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments.
public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the action's run method
doPrivilegedWithCombiner
(PrivilegedExceptionAction<T>
the action to be performed.
action
)

Performs the specified PrivilegedExceptionAction with privileges enabled.

public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the action's run method.
doPrivilegedWithCombiner
(PrivilegedExceptionAction<T>
the action to be performed.
action
,
AccessControlContext
an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.
context
,
Permission...
the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.
perms
)

Deprecated as a consequence of AccessControlContext being deprecated.
Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments.
private static native void
ensureMaterializedForStackWalk(Object o)

The value needs to be physically located in the frame, so that it can be found by a stack walk.

private static <T> T
executePrivileged(PrivilegedAction<T> action, AccessControlContext context, Class<?> caller)

Deprecated as a consequence of AccessControlContext being deprecated.
Execute the action as privileged.
private static <T> T
executePrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Class<?> caller)

Deprecated as a consequence of AccessControlContext being deprecated.
Execute the action as privileged.
public static AccessControlContext

Returns:

the AccessControlContext based on the current context.
getContext
()

Deprecated as a consequence of AccessControlContext being deprecated.
This method takes a "snapshot" of the current calling context, which includes the current thread's inherited AccessControlContext and any limited privilege scope, and places it in an AccessControlContext object.
pack-priv static native AccessControlContext
getInheritedAccessControlContext()

Deprecated as a consequence of AccessControlContext being deprecated.
Returns the "inherited" AccessControlContext.
private static AccessControlContext
getInnocuousAcc()

Deprecated as a consequence of AccessControlContext being deprecated.
private static native ProtectionDomain
getProtectionDomain(final Class<?> caller)

private static native AccessControlContext

Returns:

the access control context based on the current stack or null if there was only privileged system code.
getStackAccessControlContext
()

Deprecated as a consequence of AccessControlContext being deprecated.
Returns the AccessControlContext.
private static boolean
isPrivileged()

Sanity check that the caller context is indeed privileged.

private static AccessControlContext
preserveCombiner(DomainCombiner combiner, Class<?> caller)

Deprecated as a consequence of DomainCombiner and AccessControlContext being deprecated.
preserve the combiner across the doPrivileged call
private static PrivilegedActionException
wrapException(Exception e)

Wrap an exception.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AccessControllerback to summary
private AccessController()

Don't allow anyone to instantiate an AccessController

Method Detail

checkContextback to summary
private static AccessControlContext checkContext(AccessControlContext context, Class<?> caller)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
checkPermissionback to summary
public static void checkPermission(Permission perm) throws AccessControlException

Determines whether the access request indicated by the specified permission should be allowed or denied, based on the current AccessControlContext and security policy. This method quietly returns if the access request is permitted, or throws an AccessControlException otherwise. The getPermission method of the AccessControlException returns the Permission object instance (perm}.

Parameters
perm:Permission

the requested permission.

Annotations
@SuppressWarnings:removal
Exceptions
AccessControlException:
if the specified permission is not permitted, based on the current security policy.
NullPointerException:
if the specified permission is null and is checked based on the security policy currently in effect.
createWrapperback to summary
private static AccessControlContext createWrapper(DomainCombiner combiner, Class<?> caller, AccessControlContext parent, AccessControlContext context, Permission[] perms)

Deprecated

as a consequence of DomainCombiner and AccessControlContext being deprecated. See corresponding docs for further information.

Create a wrapper to contain the limited privilege scope data.

Annotations
@SuppressWarnings:removal
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedAction<T> action)

Performs the specified PrivilegedAction with privileges enabled. The action is performed with all of the permissions possessed by the caller's protection domain.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
action:PrivilegedAction<T>

the action to be performed.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
NullPointerException:
if the action is null
See Also
doPrivileged(PrivilegedAction, AccessControlContext), doPrivileged(PrivilegedExceptionAction), doPrivilegedWithCombiner(PrivilegedAction), java.security.DomainCombiner
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
action:PrivilegedAction<T>

the action to be performed.

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
NullPointerException:
if the action is null
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedExceptionAction, AccessControlContext)
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context, Permission... perms)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
action:PrivilegedAction<T>

the action to be performed.

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

perms:Permission[]

the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
NullPointerException:
if action or perms or any element of perms is null
Since
1.8
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedExceptionAction, AccessControlContext)
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException

Performs the specified PrivilegedExceptionAction with privileges enabled. The action is performed with all of the permissions possessed by the caller's protection domain.

If the action's run method throws an unchecked exception, it will propagate through this method.

Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
action:PrivilegedExceptionAction<T>

the action to be performed

Returns:T

the value returned by the action's run method

Annotations
@CallerSensitive
Exceptions
PrivilegedActionException:
if the specified action's run method threw a checked exception
NullPointerException:
if the action is null
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedExceptionAction, AccessControlContext), doPrivilegedWithCombiner(PrivilegedExceptionAction), java.security.DomainCombiner
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context) throws PrivilegedActionException

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an unchecked exception, it will propagate through this method.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
action:PrivilegedExceptionAction<T>

the action to be performed

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

Returns:T

the value returned by the action's run method

Annotations
@CallerSensitive
Exceptions
PrivilegedActionException:
if the specified action's run method threw a checked exception
NullPointerException:
if the action is null
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedAction, AccessControlContext)
doPrivilegedback to summary
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Permission... perms) throws PrivilegedActionException

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
action:PrivilegedExceptionAction<T>

the action to be performed.

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

perms:Permission[]

the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
PrivilegedActionException:
if the specified action's run method threw a checked exception
NullPointerException:
if action or perms or any element of perms is null
Since
1.8
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedAction, AccessControlContext)
doPrivilegedWithCombinerback to summary
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action)

Performs the specified PrivilegedAction with privileges enabled. The action is performed with all of the permissions possessed by the caller's protection domain.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

This method preserves the current AccessControlContext's DomainCombiner (which may be null) while the action is performed.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
action:PrivilegedAction<T>

the action to be performed.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
NullPointerException:
if the action is null
Since
1.6
See Also
doPrivileged(PrivilegedAction), java.security.DomainCombiner
doPrivilegedWithCombinerback to summary
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action, AccessControlContext context, Permission... perms)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

This method preserves the current AccessControlContext's DomainCombiner (which may be null) while the action is performed.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
action:PrivilegedAction<T>

the action to be performed.

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

perms:Permission[]

the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
NullPointerException:
if action or perms or any element of perms is null
Since
1.8
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedExceptionAction, AccessControlContext), java.security.DomainCombiner
doPrivilegedWithCombinerback to summary
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) throws PrivilegedActionException

Performs the specified PrivilegedExceptionAction with privileges enabled. The action is performed with all of the permissions possessed by the caller's protection domain.

If the action's run method throws an unchecked exception, it will propagate through this method.

This method preserves the current AccessControlContext's DomainCombiner (which may be null) while the action is performed.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
action:PrivilegedExceptionAction<T>

the action to be performed.

Returns:T

the value returned by the action's run method

Annotations
@CallerSensitive
Exceptions
PrivilegedActionException:
if the specified action's run method threw a checked exception
NullPointerException:
if the action is null
Since
1.6
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedExceptionAction, AccessControlContext), java.security.DomainCombiner
doPrivilegedWithCombinerback to summary
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action, AccessControlContext context, Permission... perms) throws PrivilegedActionException

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Performs the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext and with a privilege scope limited by specified Permission arguments. The action is performed with the intersection of the permissions possessed by the caller's protection domain, and those possessed by the domains represented by the specified AccessControlContext.

If the action's run method throws an (unchecked) exception, it will propagate through this method.

This method preserves the current AccessControlContext's DomainCombiner (which may be null) while the action is performed.

If a security manager is installed and the specified AccessControlContext was not created by system code and the caller's ProtectionDomain has not been granted the "createAccessControlContext" java.security.SecurityPermission, then the action is performed with no permissions.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
action:PrivilegedExceptionAction<T>

the action to be performed.

context:AccessControlContext

an access control context representing the restriction to be applied to the caller's domain's privileges before performing the specified action. If the context is null, then no additional restriction is applied.

perms:Permission[]

the Permission arguments which limit the scope of the caller's privileges. The number of arguments is variable.

Returns:T

the value returned by the action's run method.

Annotations
@CallerSensitive
Exceptions
PrivilegedActionException:
if the specified action's run method threw a checked exception
NullPointerException:
if action or perms or any element of perms is null
Since
1.8
See Also
doPrivileged(PrivilegedAction), doPrivileged(PrivilegedAction, AccessControlContext), java.security.DomainCombiner
ensureMaterializedForStackWalkback to summary
private static native void ensureMaterializedForStackWalk(Object o)

The value needs to be physically located in the frame, so that it can be found by a stack walk.

Annotations
@Hidden
executePrivilegedback to summary
private static <T> T executePrivileged(PrivilegedAction<T> action, AccessControlContext context, Class<?> caller)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Execute the action as privileged. The VM recognizes this method as special, so any changes to the name or signature require corresponding changes in getStackAccessControlContext().

Annotations
@Hidden
@ForceInline
executePrivilegedback to summary
private static <T> T executePrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Class<?> caller) throws Exception

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Execute the action as privileged. The VM recognizes this method as special, so any changes to the name or signature require corresponding changes in getStackAccessControlContext().

Annotations
@Hidden
@ForceInline
getContextback to summary
public static AccessControlContext getContext()

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

This method takes a "snapshot" of the current calling context, which includes the current thread's inherited AccessControlContext and any limited privilege scope, and places it in an AccessControlContext object. This context may then be checked at a later point, possibly in another thread.

Returns:AccessControlContext

the AccessControlContext based on the current context.

Annotations
@SuppressWarnings:removal
See Also
AccessControlContext
getInheritedAccessControlContextback to summary
pack-priv static native AccessControlContext getInheritedAccessControlContext()

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Returns the "inherited" AccessControlContext. This is the context that existed when the thread was created. Package private so AccessControlContext can use it.

Annotations
@SuppressWarnings:removal
getInnocuousAccback to summary
private static AccessControlContext getInnocuousAcc()

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
getProtectionDomainback to summary
private static native ProtectionDomain getProtectionDomain(final Class<?> caller)
getStackAccessControlContextback to summary
private static native AccessControlContext getStackAccessControlContext()

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Returns the AccessControlContext. i.e., it gets the protection domains of all the callers on the stack, starting at the first class with a non-null ProtectionDomain.

Returns:AccessControlContext

the access control context based on the current stack or null if there was only privileged system code.

Annotations
@SuppressWarnings:removal
isPrivilegedback to summary
private static boolean isPrivileged()

Sanity check that the caller context is indeed privileged. Used by executePrivileged to make sure the frame is properly recognized by the VM.

preserveCombinerback to summary
private static AccessControlContext preserveCombiner(DomainCombiner combiner, Class<?> caller)

Deprecated

as a consequence of DomainCombiner and AccessControlContext being deprecated. See corresponding docs for further information.

preserve the combiner across the doPrivileged call

Annotations
@SuppressWarnings:removal
wrapExceptionback to summary
private static PrivilegedActionException wrapException(Exception e)

Wrap an exception. The annotations are used in a best effort to avoid StackOverflowError in the caller. Inlining the callees as well and tail-call elimination could also help here, but are not needed for correctness, only quality of implementation.

Annotations
@Hidden
@ForceInline
@ReservedStackAccess
java.security back to summary

private Class AccessController.AccHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final AccessControlContext
innocuousAcc

Deprecated as a consequence of AccessControlContext being deprecated.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

innocuousAccback to summary
pack-priv static final AccessControlContext innocuousAcc

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal

Constructor Detail

AccHolderback to summary
private AccHolder()