AccessControlContext (Java 2 Platform SE 5.0) (original) (raw)
java.security
Class AccessControlContext
java.lang.Object
java.security.AccessControlContext
public final class AccessControlContext
extends Object
An AccessControlContext is used to make system resource access decisions based on the context it encapsulates.
More specifically, it encapsulates a context and has a single method, checkPermission
, that is equivalent to the checkPermission
method in the AccessController class, with one difference: The AccessControlContextcheckPermission
method makes access decisions based on the context it encapsulates, rather than that of the current execution thread.
Thus, the purpose of AccessControlContext is for those situations where a security check that should be made within a given context actually needs to be done from within a_different_ context (for example, from within a worker thread).
An AccessControlContext is created by calling the AccessController.getContext
method. 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()
Code within a different context can subsequently call thecheckPermission
method on the previously-saved AccessControlContext object. A sample call is the following:
acc.checkPermission(permission)
See Also:
Constructor Summary |
---|
[AccessControlContext](../../java/security/AccessControlContext.html#AccessControlContext%28java.security.AccessControlContext, java.security.DomainCombiner%29)(AccessControlContext acc,DomainCombiner combiner) Create a new AccessControlContext with the givenAccessControlContext and DomainCombiner. |
AccessControlContext(ProtectionDomain[] context) Create an AccessControlContext with the given set of ProtectionDomains. |
Method Summary | |
---|---|
void | checkPermission(Permission perm) Determines whether the access request indicated by the specified permission should be allowed or denied, based on the security policy currently in effect, and the context in this object. |
boolean | equals(Object obj) Checks two AccessControlContext objects for equality. |
DomainCombiner | getDomainCombiner() Get the DomainCombiner associated with thisAccessControlContext. |
int | hashCode() Returns the hash code value for this context. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
AccessControlContext
public AccessControlContext(ProtectionDomain[] context)
Create an AccessControlContext with the given set of ProtectionDomains. Context must not be null. Duplicate domains will be removed from the context.
Parameters:
context
- the ProtectionDomains associated with this context. The non-duplicate domains are copied from the array. Subsequent changes to the array will not affect this AccessControlContext.
AccessControlContext
public AccessControlContext(AccessControlContext acc, DomainCombiner combiner)
Create a new AccessControlContext
with the givenAccessControlContext
and DomainCombiner
. This constructor associates the providedDomainCombiner
with the providedAccessControlContext
.
Parameters:
acc
- the AccessControlContext
associated with the provided DomainCombiner
.
combiner
- the DomainCombiner
to be associated with the provided AccessControlContext
.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if the providedcontext
is null
.
[SecurityException](../../java/lang/SecurityException.html "class in java.lang")
- if the caller does not have permission to invoke this constructor.
Method Detail |
---|
getDomainCombiner
public DomainCombiner getDomainCombiner()
Get the DomainCombiner
associated with thisAccessControlContext
.
Returns:
the DomainCombiner
associated with thisAccessControlContext
, or null
if there is none.
Throws:
[SecurityException](../../java/lang/SecurityException.html "class in java.lang")
- if the caller does not have permission to get the DomainCombiner
associated with thisAccessControlContext
.
checkPermission
public void checkPermission(Permission perm) throws AccessControlException
Determines whether the access request indicated by the specified permission should be allowed or denied, based on the security policy currently in effect, and the context in this object.
This method quietly returns if the access request is permitted, or throws a suitable AccessControlException otherwise.
Parameters:
perm
- the requested permission.
Throws:
[AccessControlException](../../java/security/AccessControlException.html "class in java.security")
- if the specified permission is not permitted, based on the current security policy and the context encapsulated by this object.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if the permission to check for is null.
equals
public boolean equals(Object obj)
Checks two AccessControlContext objects for equality. Checks that obj is an AccessControlContext and has the same set of ProtectionDomains as this context.
Overrides:
[equals](../../java/lang/Object.html#equals%28java.lang.Object%29)
in class [Object](../../java/lang/Object.html "class in java.lang")
Parameters:
obj
- the object we are testing for equality with this object.
Returns:
true if obj is an AccessControlContext, and has the same set of ProtectionDomains as this context, false otherwise.
See Also:
hashCode
public int hashCode()
Returns the hash code value for this context. The hash code is computed by exclusive or-ing the hash code of all the protection domains in the context together.
Overrides:
[hashCode](../../java/lang/Object.html#hashCode%28%29)
in class [Object](../../java/lang/Object.html "class in java.lang")
Returns:
a hash code value for this context.
See Also:
Object.equals(java.lang.Object), Hashtable
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.