java.security
Class AccessControlContext

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.security.AccessControlContext

public final class AccessControlContext
extends Object sample code for java.lang.Object definition code for java.lang.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 AccessControlContext checkPermission 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 the checkPermission method on the previously-saved AccessControlContext object. A sample call is the following:

 
   acc.checkPermission(permission)
 
 

See Also:
AccessController sample code for java.security.AccessController definition code for java.security.AccessController

Constructor Summary
AccessControlContext sample code for java.security.AccessControlContext.AccessControlContext(java.security.AccessControlContext, java.security.DomainCombiner) definition code for java.security.AccessControlContext.AccessControlContext(java.security.AccessControlContext, java.security.DomainCombiner) (AccessControlContext sample code for java.security.AccessControlContext definition code for java.security.AccessControlContext  acc, DomainCombiner sample code for java.security.DomainCombiner definition code for java.security.DomainCombiner  combiner)
          Create a new AccessControlContext with the given AccessControlContext and DomainCombiner.
AccessControlContext sample code for java.security.AccessControlContext.AccessControlContext(java.security.ProtectionDomain[]) definition code for java.security.AccessControlContext.AccessControlContext(java.security.ProtectionDomain[]) (ProtectionDomain sample code for java.security.ProtectionDomain definition code for java.security.ProtectionDomain [] context)
          Create an AccessControlContext with the given set of ProtectionDomains.
 
Method Summary
 void checkPermission sample code for java.security.AccessControlContext.checkPermission(java.security.Permission) definition code for java.security.AccessControlContext.checkPermission(java.security.Permission) (Permission sample code for java.security.Permission definition code for java.security.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 sample code for java.security.AccessControlContext.equals(java.lang.Object) definition code for java.security.AccessControlContext.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Checks two AccessControlContext objects for equality.
 DomainCombiner sample code for java.security.DomainCombiner definition code for java.security.DomainCombiner getDomainCombiner sample code for java.security.AccessControlContext.getDomainCombiner() definition code for java.security.AccessControlContext.getDomainCombiner() ()
          Get the DomainCombiner associated with this AccessControlContext.
 int hashCode sample code for java.security.AccessControlContext.hashCode() definition code for java.security.AccessControlContext.hashCode() ()
          Returns the hash code value for this context.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

AccessControlContext sample code for java.security.AccessControlContext(java.security.ProtectionDomain[]) definition code for java.security.AccessControlContext(java.security.ProtectionDomain[])

public AccessControlContext(ProtectionDomain sample code for java.security.ProtectionDomain definition code for java.security.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 sample code for java.security.AccessControlContext(java.security.AccessControlContext, java.security.DomainCombiner) definition code for java.security.AccessControlContext(java.security.AccessControlContext, java.security.DomainCombiner)

public AccessControlContext(AccessControlContext sample code for java.security.AccessControlContext definition code for java.security.AccessControlContext  acc,
                            DomainCombiner sample code for java.security.DomainCombiner definition code for java.security.DomainCombiner  combiner)
Create a new AccessControlContext with the given AccessControlContext and DomainCombiner. This constructor associates the provided DomainCombiner with the provided AccessControlContext.

Parameters:
acc - the AccessControlContext associated with the provided DomainCombiner.

combiner - the DomainCombiner to be associated with the provided AccessControlContext.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the provided context is null.

SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if the caller does not have permission to invoke this constructor.
Method Detail

getDomainCombiner sample code for java.security.AccessControlContext.getDomainCombiner() definition code for java.security.AccessControlContext.getDomainCombiner()

public DomainCombiner sample code for java.security.DomainCombiner definition code for java.security.DomainCombiner  getDomainCombiner()
Get the DomainCombiner associated with this AccessControlContext.

Returns:
the DomainCombiner associated with this AccessControlContext, or null if there is none.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if the caller does not have permission to get the DomainCombiner associated with this AccessControlContext.

checkPermission sample code for java.security.AccessControlContext.checkPermission(java.security.Permission) definition code for java.security.AccessControlContext.checkPermission(java.security.Permission)

public void checkPermission(Permission sample code for java.security.Permission definition code for java.security.Permission  perm)
                     throws AccessControlException sample code for java.security.AccessControlException definition code for java.security.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 sample code for java.security.AccessControlException definition code for java.security.AccessControlException - if the specified permission is not permitted, based on the current security policy and the context encapsulated by this object.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the permission to check for is null.

equals sample code for java.security.AccessControlContext.equals(java.lang.Object) definition code for java.security.AccessControlContext.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.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 sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
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:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

hashCode sample code for java.security.AccessControlContext.hashCode() definition code for java.security.AccessControlContext.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 sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code value for this context.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable