# Subject

public final class **Subject** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Serializable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Serializable.html) <br />

A `Subject` represents a grouping of related information
for a single entity, such as a person.
Such information includes the Subject's identities as well as
its security-related attributes
(passwords and cryptographic keys, for example).

Subjects may potentially have multiple identities.
Each identity is represented as a `Principal`
within the `Subject`. Principals simply bind names to a
`Subject`. For example, a `Subject` that happens
to be a person, Alice, might have two Principals:
one which binds "Alice Bar", the name on her driver license,
to the `Subject`, and another which binds,
"999-99-9999", the number on her student identification card,
to the `Subject`. Both Principals refer to the same
`Subject` even though each has a different name.

A `Subject` may also own security-related attributes,
which are referred to as credentials.
Sensitive credentials that require special protection, such as
private cryptographic keys, are stored within a private credential
`Set`. Credentials intended to be shared, such as
public key certificates or Kerberos server tickets are stored
within a public credential `Set`. Different permissions
are required to access and modify the different credential Sets.

To retrieve all the Principals associated with a `Subject`,
invoke the `getPrincipals` method. To retrieve
all the public or private credentials belonging to a `Subject`,
invoke the `getPublicCredentials` method or
`getPrivateCredentials` method, respectively.
To modify the returned `Set` of Principals and credentials,
use the methods defined in the `Set` class.
For example:

```
      Subject subject;
      Principal principal;
      Object credential;

      // add a Principal and credential to the Subject
      subject.getPrincipals().add(principal);
      subject.getPublicCredentials().add(credential);
 
```

This `Subject` class implements `Serializable`.
While the Principals associated with the `Subject` are serialized,
the credentials associated with the `Subject` are not.
Note that the `java.security.Principal` class
does not implement `Serializable`. Therefore all concrete
`Principal` implementations associated with Subjects
must implement `Serializable`.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DomainCombiner.html`

### Public Constructor Summary

|---|---|
|   | [Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#Subject())() Create an instance of a `Subject` with an empty `Set` of Principals and empty Sets of public and private credentials. |
|   | [Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#Subject(boolean,%20java.util.Set<?%20extends%20java.security.Principal>,%20java.util.Set<?>,%20java.util.Set<?>))(boolean readOnly, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<? extends [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)\> principals, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<?\> pubCredentials, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<?\> privCredentials) Create an instance of a `Subject` with Principals and credentials. |

### Public Method Summary

|---|---|
| static \<T\> T | [doAs](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#doAs(javax.security.auth.Subject,%20java.security.PrivilegedExceptionAction<T>))([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedExceptionAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedExceptionAction.html)\<T\> action) Perform work as a particular `Subject`. |
| static \<T\> T | [doAs](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#doAs(javax.security.auth.Subject,%20java.security.PrivilegedAction<T>))([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedAction.html)\<T\> action) Perform work as a particular `Subject`. |
| static \<T\> T | [doAsPrivileged](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#doAsPrivileged(javax.security.auth.Subject,%20java.security.PrivilegedExceptionAction<T>,%20java.security.AccessControlContext))([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedExceptionAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedExceptionAction.html)\<T\> action, [AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc) Perform privileged work as a particular `Subject`. |
| static \<T\> T | [doAsPrivileged](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#doAsPrivileged(javax.security.auth.Subject,%20java.security.PrivilegedAction<T>,%20java.security.AccessControlContext))([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedAction.html)\<T\> action, [AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc) Perform privileged work as a particular `Subject`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Compares the specified Object with this `Subject` for equality. |
| [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)\> | [getPrincipals](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPrincipals())() Return the `Set` of Principals associated with this `Subject`. |
| \<T extends [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)\> [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\> | [getPrincipals](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPrincipals(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c) Return a `Set` of Principals associated with this `Subject` that are instances or subclasses of the specified `Class`. |
| \<T\> [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\> | [getPrivateCredentials](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPrivateCredentials(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c) Return a `Set` of private credentials associated with this `Subject` that are instances or subclasses of the specified `Class`. |
| [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)\> | [getPrivateCredentials](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPrivateCredentials())() Return the `Set` of private credentials held by this `Subject`. |
| [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)\> | [getPublicCredentials](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPublicCredentials())() Return the `Set` of public credentials held by this `Subject`. |
| \<T\> [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\> | [getPublicCredentials](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getPublicCredentials(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c) Return a `Set` of public credentials associated with this `Subject` that are instances or subclasses of the specified `Class`. |
| static [Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) | [getSubject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#getSubject(java.security.AccessControlContext))([AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc) Get the `Subject` associated with the provided `AccessControlContext`. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#hashCode())() Returns a hashcode for this `Subject`. |
| boolean | [isReadOnly](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#isReadOnly())() Query whether this `Subject` is read-only. |
| void | [setReadOnly](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#setReadOnly())() Set this `Subject` to be read-only. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html#toString())() Return the String representation of this `Subject`. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**Subject**
()

Create an instance of a `Subject`
with an empty `Set` of Principals and empty
Sets of public and private credentials.

The newly constructed Sets check whether this `Subject`
has been set read-only before permitting subsequent modifications.
The newly created Sets also prevent illegal modifications
by ensuring that callers have sufficient permissions.

To modify the Principals Set, the caller must have
`AuthPermission("modifyPrincipals")`.
To modify the public credential Set, the caller must have
`AuthPermission("modifyPublicCredentials")`.
To modify the private credential Set, the caller must have
`AuthPermission("modifyPrivateCredentials")`.

#### public
**Subject**
(boolean readOnly, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<? extends [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)\> principals, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<?\> pubCredentials, [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<?\> privCredentials)

Create an instance of a `Subject` with
Principals and credentials.

The Principals and credentials from the specified Sets
are copied into newly constructed Sets.
These newly created Sets check whether this `Subject`
has been set read-only before permitting subsequent modifications.
The newly created Sets also prevent illegal modifications
by ensuring that callers have sufficient permissions.

To modify the Principals Set, the caller must have
`AuthPermission("modifyPrincipals")`.
To modify the public credential Set, the caller must have
`AuthPermission("modifyPublicCredentials")`.
To modify the private credential Set, the caller must have
`AuthPermission("modifyPrivateCredentials")`.

<br />

##### Parameters

| readOnly | true if the `Subject` is to be read-only, and false otherwise. <br /> |
| principals | the `Set` of Principals to be associated with this `Subject`. <br /> |
| pubCredentials | the `Set` of public credentials to be associated with this `Subject`. <br /> |
| privCredentials | the `Set` of private credentials to be associated with this `Subject`. |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `principals`, `pubCredentials`, or `privCredentials` are `null`. |
|---|---|

## Public Methods

#### public static T
**doAs**
([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedExceptionAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedExceptionAction.html)\<T\> action)

Perform work as a particular `Subject`.

This method first retrieves the current Thread's
`AccessControlContext` via
`AccessController.getContext`,
and then instantiates a new `AccessControlContext`
using the retrieved context along with a new
`SubjectDomainCombiner` (constructed using
the provided `Subject`).
Finally, this method invokes `AccessController.doPrivileged`,
passing it the provided `PrivilegedExceptionAction`,
as well as the newly constructed `AccessControlContext`.

<br />

##### Parameters

| subject | the `Subject` that the specified `action` will run as. This parameter may be `null`. <br /> |
| action | the code to be run as the specified `Subject`. <br /> |
|---|---|

##### Returns

- the value returned by the PrivilegedExceptionAction's `run` method.

##### Throws

| [PrivilegedActionException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedActionException.html) | if the `PrivilegedExceptionAction.run` method throws a checked exception. <br /> |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `PrivilegedExceptionAction` is `null`. <br /> |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to invoke this method. |
|---|---|

#### public static T
**doAs**
([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedAction.html)\<T\> action)

Perform work as a particular `Subject`.

This method first retrieves the current Thread's
`AccessControlContext` via
`AccessController.getContext`,
and then instantiates a new `AccessControlContext`
using the retrieved context along with a new
`SubjectDomainCombiner` (constructed using
the provided `Subject`).
Finally, this method invokes `AccessController.doPrivileged`,
passing it the provided `PrivilegedAction`,
as well as the newly constructed `AccessControlContext`.

<br />

##### Parameters

| subject | the `Subject` that the specified `action` will run as. This parameter may be `null`. <br /> |
| action | the code to be run as the specified `Subject`. <br /> |
|---|---|

##### Returns

- the value returned by the PrivilegedAction's `run` method.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the `PrivilegedAction` is `null`. <br /> |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to invoke this method. |
|---|---|

#### public static T
**doAsPrivileged**
([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedExceptionAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedExceptionAction.html)\<T\> action, [AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc)

Perform privileged work as a particular `Subject`.

This method behaves exactly as `Subject.doAs`,
except that instead of retrieving the current Thread's
`AccessControlContext`, it uses the provided
`AccessControlContext`. If the provided
`AccessControlContext` is `null`,
this method instantiates a new `AccessControlContext`
with an empty collection of ProtectionDomains.

<br />

##### Parameters

| subject | the `Subject` that the specified `action` will run as. This parameter may be `null`. <br /> |
| action | the code to be run as the specified `Subject`. <br /> |
| acc | the `AccessControlContext` to be tied to the specified *subject* and *action*. <br /> |
|---|---|

##### Returns

- the value returned by the PrivilegedExceptionAction's `run` method.

##### Throws

| [PrivilegedActionException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedActionException.html) | if the `PrivilegedExceptionAction.run` method throws a checked exception. <br /> |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `PrivilegedExceptionAction` is `null`. <br /> |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to invoke this method. |
|---|---|

#### public static T
**doAsPrivileged**
([Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html) subject, [PrivilegedAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivilegedAction.html)\<T\> action, [AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc)

Perform privileged work as a particular `Subject`.

This method behaves exactly as `Subject.doAs`,
except that instead of retrieving the current Thread's
`AccessControlContext`, it uses the provided
`AccessControlContext`. If the provided
`AccessControlContext` is `null`,
this method instantiates a new `AccessControlContext`
with an empty collection of ProtectionDomains.

<br />

##### Parameters

| subject | the `Subject` that the specified `action` will run as. This parameter may be `null`. <br /> |
| action | the code to be run as the specified `Subject`. <br /> |
| acc | the `AccessControlContext` to be tied to the specified *subject* and *action*. <br /> |
|---|---|

##### Returns

- the value returned by the PrivilegedAction's `run` method.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the `PrivilegedAction` is `null`. <br /> |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to invoke this method. |
|---|---|

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o)

Compares the specified Object with this `Subject`
for equality. Returns true if the given object is also a Subject
and the two `Subject` instances are equivalent.
More formally, two `Subject` instances are
equal if their `Principal` and `Credential`
Sets are equal.

<br />

##### Parameters

| o | Object to be compared for equality with this `Subject`. |
|---|---|

##### Returns

- true if the specified Object is equal to this `Subject`.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to access the private credentials for this `Subject`, or if the caller does not have permission to access the private credentials for the provided `Subject`. |
|---|---|

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)\>
**getPrincipals**
()

Return the `Set` of Principals associated with this
`Subject`. Each `Principal` represents
an identity for this `Subject`.

The returned `Set` is backed by this Subject's
internal `Principal` `Set`. Any modification
to the returned `Set` affects the internal
`Principal` `Set` as well.

<br />

##### Returns

- The `Set` of Principals associated with this `Subject`.

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\>
**getPrincipals**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c)

Return a `Set` of Principals associated with this
`Subject` that are instances or subclasses of the specified
`Class`.

The returned `Set` is not backed by this Subject's
internal `Principal` `Set`. A new
`Set` is created and returned for each method invocation.
Modifications to the returned `Set`
will not affect the internal `Principal` `Set`.

<br />

##### Parameters

| c | the returned `Set` of Principals will all be instances of this class. |
|---|---|

##### Returns

- a `Set` of Principals that are instances of the specified `Class`.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `Class` is `null`. |
|---|---|

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\>
**getPrivateCredentials**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c)

Return a `Set` of private credentials associated with this
`Subject` that are instances or subclasses of the specified
`Class`.

The caller must have permission to access all of the
requested Credentials, or a `SecurityException`
will be thrown.

The returned `Set` is not backed by this Subject's
internal private Credential `Set`. A new
`Set` is created and returned for each method invocation.
Modifications to the returned `Set`
will not affect the internal private Credential `Set`.

<br />

##### Parameters

| c | the returned `Set` of private credentials will all be instances of this class. |
|---|---|

##### Returns

- a `Set` of private credentials that are instances of the specified `Class`.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `Class` is `null`. |
|---|---|

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)\>
**getPrivateCredentials**
()

Return the `Set` of private credentials held by this
`Subject`.

The returned `Set` is backed by this Subject's
internal private Credential `Set`. Any modification
to the returned `Set` affects the internal private
Credential `Set` as well.

A caller requires permissions to access the Credentials
in the returned `Set`, or to modify the
`Set` itself. A `SecurityException`
is thrown if the caller does not have the proper permissions.

While iterating through the `Set`,
a `SecurityException` is thrown
if the caller does not have permission to access a
particular Credential. The `Iterator`
is nevertheless advanced to next element in the `Set`.

<br />

##### Returns

- A `Set` of private credentials held by this `Subject`.

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)\>
**getPublicCredentials**
()

Return the `Set` of public credentials held by this
`Subject`.

The returned `Set` is backed by this Subject's
internal public Credential `Set`. Any modification
to the returned `Set` affects the internal public
Credential `Set` as well.

<br />

##### Returns

- A `Set` of public credentials held by this `Subject`.

#### public [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<T\>
**getPublicCredentials**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> c)

Return a `Set` of public credentials associated with this
`Subject` that are instances or subclasses of the specified
`Class`.

The returned `Set` is not backed by this Subject's
internal public Credential `Set`. A new
`Set` is created and returned for each method invocation.
Modifications to the returned `Set`
will not affect the internal public Credential `Set`.

<br />

##### Parameters

| c | the returned `Set` of public credentials will all be instances of this class. |
|---|---|

##### Returns

- a `Set` of public credentials that are instances of the specified `Class`.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified `Class` is `null`. |
|---|---|

#### public static [Subject](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/auth/Subject.html)
**getSubject**
([AccessControlContext](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html) acc)

Get the `Subject` associated with the provided
`AccessControlContext`.

The `AccessControlContext` may contain many
Subjects (from nested `doAs` calls).
In this situation, the most recent `Subject` associated
with the `AccessControlContext` is returned.

<br />

##### Parameters

| acc | the `AccessControlContext` from which to retrieve the `Subject`. |
|---|---|

##### Returns

- the `Subject` associated with the provided `AccessControlContext`, or `null` if no `Subject` is associated with the provided `AccessControlContext`.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to get the `Subject`. <br /> |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the provided `AccessControlContext` is `null`. |
|---|---|

#### public int
**hashCode**
()

Returns a hashcode for this `Subject`.

<br />

##### Returns

- a hashcode for this `Subject`.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to access this Subject's private credentials. |
|---|---|

#### public boolean
**isReadOnly**
()

Query whether this `Subject` is read-only.

<br />

##### Returns

- true if this `Subject` is read-only, false otherwise.

#### public void
**setReadOnly**
()

Set this `Subject` to be read-only.

Modifications (additions and removals) to this Subject's
`Principal` `Set` and
credential Sets will be disallowed.
The `destroy` operation on this Subject's credentials will
still be permitted.

Subsequent attempts to modify the Subject's `Principal`
and credential Sets will result in an
`IllegalStateException` being thrown.
Also, once a `Subject` is read-only,
it can not be reset to being writable again.

<br />

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the caller does not have permission to set this `Subject` to be read-only. |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Return the String representation of this `Subject`.

<br />

##### Returns

- the String representation of this `Subject`.