javax.security.auth

Class Subject

public final class Subject extends Object implements Serializable

Constructor Summary
Subject()
Subject(boolean readOnly, Set<? extends Principal> principals, Set<?> pubCred, Set<?> privCred)
Method Summary
static ObjectdoAs(Subject subject, PrivilegedAction action)

Run a method as another subject.

static ObjectdoAs(Subject subject, PrivilegedExceptionAction action)

Run a method as another subject.

static ObjectdoAsPrivileged(Subject subject, PrivilegedAction action, AccessControlContext acc)

Run a method as another subject.

static ObjectdoAsPrivileged(Subject subject, PrivilegedExceptionAction action, AccessControlContext acc)

Run a method as another subject.

booleanequals(Object o)
Set<Principal>getPrincipals()
<T extends Principal> Set<T>getPrincipals(Class<T> clazz)
Set<Object>getPrivateCredentials()
<T> Set<T>getPrivateCredentials(Class<T> clazz)
Set<Object>getPublicCredentials()
<T> Set<T>getPublicCredentials(Class<T> clazz)
static SubjectgetSubject(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.

inthashCode()
booleanisReadOnly()

Returns whether or not this subject is read-only.

voidsetReadOnly()

Marks this subject as read-only.

StringtoString()

Constructor Detail

Subject

public Subject()

Subject

public Subject(boolean readOnly, Set<? extends Principal> principals, Set<?> pubCred, Set<?> privCred)

Method Detail

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)

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)

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)

getPrincipals

public Set<Principal> getPrincipals()

getPrincipals

public <T extends Principal> Set<T> getPrincipals(Class<T> clazz)

getPrivateCredentials

public Set<Object> getPrivateCredentials()

getPrivateCredentials

public <T> Set<T> getPrivateCredentials(Class<T> clazz)

getPublicCredentials

public Set<Object> getPublicCredentials()

getPublicCredentials

public <T> Set<T> getPublicCredentials(Class<T> clazz)

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.

hashCode

public int hashCode()

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()