aicas logoJamaica 3.2 release 62

javax.security.auth
Class Subject

java.lang.Object
  extended by javax.security.auth.Subject
All Implemented Interfaces:
Serializable

public final class Subject
extends Object
implements Serializable

See Also:
Serialized Form

Constructor Summary
Subject()
           
Subject(boolean readOnly, Set principals, Set pubCred, Set privCred)
           
 
Method Summary
static Object doAs(Subject subject, PrivilegedAction action)
          Run a method as another subject.
static Object doAs(Subject subject, PrivilegedExceptionAction action)
          Run a method as another subject.
static Object doAsPrivileged(Subject subject, PrivilegedAction action, AccessControlContext acc)
          Run a method as another subject.
static Object doAsPrivileged(Subject subject, PrivilegedExceptionAction action, AccessControlContext acc)
          Run a method as another subject.
 boolean equals(Object o)
          equals compares this object to another object.
 Set getPrincipals()
           
 Set getPrincipals(Class clazz)
           
 Set getPrivateCredentials()
           
 Set getPrivateCredentials(Class clazz)
           
 Set getPublicCredentials()
           
 Set getPublicCredentials(Class clazz)
           
static Subject getSubject(AccessControlContext context)
          Returns the subject associated with the given AccessControlContext.
 int hashCode()
          hashCode returns a hash code for this object.
 boolean isReadOnly()
          Returns whether or not this subject is read-only.
 void setReadOnly()
          Marks this subject as read-only.
 String toString()
          toString creates a printable string that represents this object for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Subject

public Subject()

Subject

public Subject(boolean readOnly,
               Set principals,
               Set pubCred,
               Set privCred)
Method Detail

getSubject

public static Subject getSubject(AccessControlContext context)

Returns the subject associated with the given AccessControlContext.

All this method does is retrieve the Subject object from the supplied context's DomainCombiner, if any, and if it is an instance of a SubjectDomainCombiner.

Parameters:
context - The context to retrieve the subject from.
Returns:
The subject assoctiated with the context, or null if there is none.
Throws:
NullPointerException - If subject is null.
SecurityException - If the caller does not have permission to get the subject ("getSubject" target of AuthPermission.

doAs

public static Object doAs(Subject subject,
                          PrivilegedAction action)

Run a method as another subject. This method will obtain the current AccessControlContext for this thread, then creates another with a SubjectDomainCombiner with the given subject. The supplied action will then be run with the modified context.

Parameters:
subject - The subject to run as.
action - The action to run.
Returns:
The value returned by the privileged action.
Throws:
SecurityException - If the caller is not allowed to run under a different identity ("doAs" target of AuthPermission.

doAs

public static Object doAs(Subject subject,
                          PrivilegedExceptionAction action)
                   throws PrivilegedActionException

Run a method as another subject. This method will obtain the current AccessControlContext for this thread, then creates another with a SubjectDomainCombiner with the given subject. The supplied action will then be run with the modified context.

Parameters:
subject - The subject to run as.
action - The action to run.
Returns:
The value returned by the privileged action.
Throws:
SecurityException - If the caller is not allowed to run under a different identity ("doAs" target of AuthPermission.
PrivilegedActionException - If the action throws an exception.

doAsPrivileged

public static Object doAsPrivileged(Subject subject,
                                    PrivilegedAction action,
                                    AccessControlContext acc)

Run a method as another subject. This method will create a new AccessControlContext derived from the given one, with a SubjectDomainCombiner with the given subject. The supplied action will then be run with the modified context.

Parameters:
subject - The subject to run as.
action - The action to run.
acc - The context to use.
Returns:
The value returned by the privileged action.
Throws:
SecurityException - If the caller is not allowed to run under a different identity ("doAsPrivileged" target of AuthPermission.

doAsPrivileged

public static Object doAsPrivileged(Subject subject,
                                    PrivilegedExceptionAction action,
                                    AccessControlContext acc)
                             throws PrivilegedActionException

Run a method as another subject. This method will create a new AccessControlContext derived from the given one, with a SubjectDomainCombiner with the given subject. The supplied action will then be run with the modified context.

Parameters:
subject - The subject to run as.
action - The action to run.
acc - The context to use.
Returns:
The value returned by the privileged action.
Throws:
SecurityException - If the caller is not allowed to run under a different identity ("doAsPrivileged" target of AuthPermission.
PrivilegedActionException - If the action throws an exception.

equals

public boolean equals(Object o)
Description copied from class: Object
equals compares this object to another object.

Equals must be symmetric (a.equals(b) == b.equals(a)), reflexive (a.equals(a)==true) and transitive (a.equals(b) && b.equals(c) IMPLIES (a.equals(c))) and not change over time (a.equals(b) == a.equals(b)). a.equals(null) should always return false.

If a.equals(b) is true for two objects a and b, then a.hashCode()==b.hashCode() must hold.

The default implementation of equals returns this==other.

Overrides:
equals in class Object
Parameters:
o - the other object.
Returns:
if this and other are considered equal.

getPrincipals

public Set getPrincipals()

getPrincipals

public Set getPrincipals(Class clazz)

getPrivateCredentials

public Set getPrivateCredentials()

getPrivateCredentials

public Set getPrivateCredentials(Class clazz)

getPublicCredentials

public Set getPublicCredentials()

getPublicCredentials

public Set getPublicCredentials(Class clazz)

hashCode

public int hashCode()
Description copied from class: Object
hashCode returns a hash code for this object. The hash code must be equal for two objects a and b if a.equals(b) is true.

The default implementation returns System.identityHashCode(this).

Overrides:
hashCode in class Object
Returns:
a hash code value.

isReadOnly

public boolean isReadOnly()

Returns whether or not this subject is read-only.

Returns:
True is this subject is read-only.

setReadOnly

public void setReadOnly()

Marks this subject as read-only.

Throws:
SecurityException - If the caller does not have permission to set this subject as read-only ("setReadOnly" target of AuthPermission.

toString

public String toString()
Description copied from class: Object
toString creates a printable string that represents this object for debugging purposes.

The default implementation returns getClass().getName() + '@' + Integer.toHexString(hashCode()).

Overrides:
toString in class Object
Returns:
a string identifying this object.

aicas logoJamaica 3.2 release 62

aicas GmbH, Karlsruhe - Germany    www.aicas.com
Copyright 2001-2008 aicas GmbH. All Rights Reserved.