APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.security.auth

public final Class Subject

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, java.security.*, java.text.MessageFormat, java.util.*, java.util.concurrent.Callable, .CompletionException, sun.security.util.ResourcesMgr

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.

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.

Deprecated Methods and Replacements

The following methods in this class for user-based authorization that are dependent on Security Manager APIs are deprecated for removal:

Methods current() and callAs(Subject, Callable) are replacements for these methods, where current is equivalent to getSubject(AccessController.getContext()) (as originally specified) and callAs is similar to doAs except that the input type and exceptions thrown are slightly different.

A doAs or callAs call binds a Subject object to the period of execution of an action, and the subject can be retrieved using the current method inside the action. This subject can be inherited by child threads if they are started and terminate within the execution of its parent thread using structured concurrency.

Since
1.4
See Also
java.security.Principal, java.security.DomainCombiner

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
Subject.ClassSet<T>

This class implements a Set which returns only members that are an instance of a specified Class.

private static class
Subject.SecureSet<E>

Prevent modifications unless caller has permission.

Field Summary

Modifier and TypeField and Description
private static final ProtectionDomain[]
private static final int
pack-priv Set<Principal>
principals

A Set that provides a view of all of this Subject's Principals

private static final int
pack-priv transient Set<Object>
private static final int
pack-priv transient Set<Object>
pubCredentials

Sets that provide a view of all of this Subject's Credentials

private volatile boolean
readOnly

Whether this Subject is read-only

private static final ScopedValue<Subject>
private static final long

Constructor Summary

AccessConstructor and Description
public
Subject()

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

public
Subject(boolean
true if the Subject is to be read-only, and false otherwise.
readOnly
,
Set<? extends Principal>
the Set of Principals to be associated with this Subject.
principals
,
Set<?>
the Set of public credentials to be associated with this Subject.
pubCredentials
,
Set<?>
the Set of private credentials to be associated with this Subject.
privCredentials
)

Create an instance of a Subject with Principals and credentials.

Method Summary

Modifier and TypeMethod and Description
public static <
the type of value returned by the call method of action
T
>
T

Returns:

the value returned by the call method of action
callAs
(final Subject
the Subject that the specified action will run as. This parameter may be null.
subject
,
final Callable<T>
the code to be run with subject as its current subject. Must not be null.
action
)

Executes a Callable with subject as the current subject.

private static <E> LinkedList<E>
collectionNullClean(Collection<? extends E>
A Collection to be tested for null references
coll
)

Tests for null-clean collections (both non-null reference and no null elements)

public static Subject

Returns:

the current subject, or null if a current subject is not installed or the current subject is set to null.
current
()

Returns the current subject.

public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the PrivilegedAction's run method.
doAs
(final Subject
the Subject that the specified action will run as. This parameter may be null.
subject
,
final PrivilegedAction<T>
the code to be run as the specified Subject.
action
)
Deprecated for removal since 18. This method originally performed the specified PrivilegedAction with privileges enabled.

Perform work as a particular Subject.

public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the PrivilegedExceptionAction's run method.
doAs
(final Subject
the Subject that the specified action will run as. This parameter may be null.
subject
,
final PrivilegedExceptionAction<T>
the code to be run as the specified Subject.
action
)
Deprecated for removal since 18. This method originally performed the specified PrivilegedExceptionAction with privileges enabled.

Perform work as a particular Subject.

public static <
the type of the value returned by the PrivilegedAction's run method.
T
>
T

Returns:

the value returned by the PrivilegedAction's run method.
doAsPrivileged
(final Subject
the Subject that the specified action will run as. This parameter may be null.
subject
,
final PrivilegedAction<T>
the code to be run as the specified Subject.
action
,
final AccessControlContext
ignored
acc
)
Deprecated for removal since 17. This method originally performed the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext.

Perform work as a particular Subject.

public static <
the type of the value returned by the PrivilegedExceptionAction's run method.
T
>
T

Returns:

the value returned by the PrivilegedExceptionAction's run method.
doAsPrivileged
(final Subject
the Subject that the specified action will run as. This parameter may be null.
subject
,
final PrivilegedExceptionAction<T>
the code to be run as the specified Subject.
action
,
final AccessControlContext
ignored
acc
)
Deprecated for removal since 17. This method originally performed the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext.

Perform work as a particular Subject.

public boolean

Returns:

true if the specified Object is equal to this Subject.
equals
(Object
Object to be compared for equality with this Subject.
o
)

Overrides java.lang.Object.equals.

Compares the specified Object with this Subject for equality.

private int
getCredHashCode(Object o)

get a credential's hashcode

public Set<Principal>

Returns:

the Set of Principals associated with this Subject.
getPrincipals
()

Return the Set of Principals associated with this Subject.

public <
the type of the class modeled by c
T extends Principal
>
Set<T>

Returns:

a Set of Principals that are instances of the specified Class.
getPrincipals
(Class<T>
the returned Set of Principals will all be instances of this class.
c
)

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

public Set<Object>

Returns:

a Set of private credentials held by this Subject.
getPrivateCredentials
()

Return the Set of private credentials held by this Subject.

public <
the type of the class modeled by c
T
>
Set<T>

Returns:

a Set of private credentials that are instances of the specified Class.
getPrivateCredentials
(Class<T>
the returned Set of private credentials will all be instances of this class.
c
)

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

public Set<Object>

Returns:

a Set of public credentials held by this Subject.
getPublicCredentials
()

Return the Set of public credentials held by this Subject.

public <
the type of the class modeled by c
T
>
Set<T>

Returns:

a Set of public credentials that are instances of the specified Class.
getPublicCredentials
(Class<T>
the returned Set of public credentials will all be instances of this class.
c
)

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

public static Subject

Returns:

n/a
getSubject
(final AccessControlContext
ignored
acc
)
Deprecated for removal since 17. This method used to get the subject associated with the provided AccessControlContext, which was only useful in conjunction with the Security Manager, which is no longer supported.

Throws UnsupportedOperationException.

public int

Returns:

a hashcode for this Subject
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hashcode for this Subject.

public boolean

Returns:

true if this Subject is read-only, false otherwise.
isReadOnly
()

Query whether this Subject is read-only.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
s
)

Reads this object from a stream (i.e., deserializes it)

public void
setReadOnly()

Set this Subject to be read-only.

public String

Returns:

the String representation of this Subject.
toString
()

Overrides java.lang.Object.toString.

Return the String representation of this Subject.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Writes this object out to a stream (i.e., serializes it).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

NULL_PD_ARRAYback to summary
private static final ProtectionDomain[] NULL_PD_ARRAY
PRINCIPAL_SETback to summary
private static final int PRINCIPAL_SET
principalsback to summary
pack-priv Set<Principal> principals

A Set that provides a view of all of this Subject's Principals

Annotations
@SuppressWarnings:serial
PRIV_CREDENTIAL_SETback to summary
private static final int PRIV_CREDENTIAL_SET
privCredentialsback to summary
pack-priv transient Set<Object> privCredentials
PUB_CREDENTIAL_SETback to summary
private static final int PUB_CREDENTIAL_SET
pubCredentialsback to summary
pack-priv transient Set<Object> pubCredentials

Sets that provide a view of all of this Subject's Credentials

readOnlyback to summary
private volatile boolean readOnly

Whether this Subject is read-only

SCOPED_SUBJECTback to summary
private static final ScopedValue<Subject> SCOPED_SUBJECT
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

Subjectback to summary
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. These Sets also prohibit null elements, and attempts to add, query, or remove a null element will result in a NullPointerException.

Subjectback to summary
public Subject(boolean readOnly, Set<? extends Principal> principals, Set<?> pubCredentials, Set<?> 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. These Sets also prohibit null elements, and attempts to add, query, or remove a null element will result in a NullPointerException.

Parameters
readOnly:boolean

true if the Subject is to be read-only, and false otherwise.

principals:Set<? extends Principal>

the Set of Principals to be associated with this Subject.

pubCredentials:Set<?>

the Set of public credentials to be associated with this Subject.

privCredentials:Set<?>

the Set of private credentials to be associated with this Subject.

Exceptions
NullPointerException:
if the specified principals, pubCredentials, or privCredentials are null, or a null value exists within any of these three Sets.

Method Detail

callAsback to summary
public static <T> T callAs(final Subject subject, final Callable<T> action) throws CompletionException

Executes a Callable with subject as the current subject.

This method launches action and binds subject to the period of its execution.

Parameters
<T>
the type of value returned by the call method of action
subject:Subject

the Subject that the specified action will run as. This parameter may be null.

action:Callable<T>

the code to be run with subject as its current subject. Must not be null.

Returns:T

the value returned by the call method of action

Exceptions
CompletionException:
if action.call() throws an exception. The cause of the CompletionException is set to the exception thrown by action.call().
NullPointerException:
if action is null
Since
18
See Also
current()
collectionNullCleanback to summary
private static <E> LinkedList<E> collectionNullClean(Collection<? extends E> coll)

Tests for null-clean collections (both non-null reference and no null elements)

Parameters
coll:Collection<? extends E>

A Collection to be tested for null references

Exceptions
NullPointerException:
if the specified collection is either null or contains a null element
currentback to summary
public static Subject current()

Returns the current subject.

The current subject is installed by the callAs method. When callAs(subject, action) is called, action is executed with subject as its current subject which can be retrieved by this method. After action is finished, the current subject is reset to its previous value. The current subject is null before the first call of callAs().

This method returns the Subject bound to the period of the execution of the current thread.

Returns:Subject

the current subject, or null if a current subject is not installed or the current subject is set to null.

Since
18
See Also
callAs(Subject, Callable)
doAsback to summary
public static <T> T doAs(final Subject subject, final PrivilegedAction<T> action)

Deprecated

for removal since 18.

This method originally performed the specified PrivilegedAction with privileges enabled. Running the action with privileges enabled was only useful in conjunction with the Security Manager, which is no longer supported. This method has been changed to launch the action as is and bind the subject to the period of its execution. A replacement API named callAs has been added which can be used to perform the same work. There is no replacement for the Security Manager.

Perform work as a particular Subject.

This method launches action and binds subject to the period of its execution.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
subject:Subject

the Subject that the specified action will run as. This parameter may be null.

action:PrivilegedAction<T>

the code to be run as the specified Subject.

Returns:T

the value returned by the PrivilegedAction's run method.

Annotations
@Deprecated
since:18
forRemoval:true
Exceptions
NullPointerException:
if the PrivilegedAction is null.
See Also
callAs(Subject, Callable)
doAsback to summary
public static <T> T doAs(final Subject subject, final PrivilegedExceptionAction<T> action) throws PrivilegedActionException

Deprecated

for removal since 18.

This method originally performed the specified PrivilegedExceptionAction with privileges enabled. Running the action with privileges enabled was only useful in conjunction with the Security Manager, which is no longer supported. This method has been changed to launch the action as is and bind the subject to the period of its execution. A replacement API named callAs has been added which can be used to perform the same work. There is no replacement for the Security Manager.

Perform work as a particular Subject.

This method launches action and binds subject to the period of its execution.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
subject:Subject

the Subject that the specified action will run as. This parameter may be null.

action:PrivilegedExceptionAction<T>

the code to be run as the specified Subject.

Returns:T

the value returned by the PrivilegedExceptionAction's run method.

Annotations
@Deprecated
since:18
forRemoval:true
Exceptions
PrivilegedActionException:
if the PrivilegedExceptionAction.run method throws a checked exception.
NullPointerException:
if the specified PrivilegedExceptionAction is null.
See Also
callAs(Subject, Callable)
doAsPrivilegedback to summary
public static <T> T doAsPrivileged(final Subject subject, final PrivilegedAction<T> action, final AccessControlContext acc)

Deprecated

for removal since 17.

This method originally performed the specified PrivilegedAction with privileges enabled and restricted by the specified AccessControlContext. Running the action with privileges enabled was only useful in conjunction with the Security Manager, which is no longer supported. This method has been changed to ignore the AccessControlContext and launch the action as is and bind the subject to the period of its execution. A replacement API named callAs has been added which can be used to perform the same work. There is no replacement for the Security Manager.

Perform work as a particular Subject.

This method launches action and binds subject to the period of its execution.

Parameters
<T>
the type of the value returned by the PrivilegedAction's run method.
subject:Subject

the Subject that the specified action will run as. This parameter may be null.

action:PrivilegedAction<T>

the code to be run as the specified Subject.

acc:AccessControlContext

ignored

Returns:T

the value returned by the PrivilegedAction's run method.

Annotations
@SuppressWarnings:removal
@Deprecated
since:17
forRemoval:true
Exceptions
NullPointerException:
if the PrivilegedAction is null.
See Also
callAs(Subject, Callable)
doAsPrivilegedback to summary
public static <T> T doAsPrivileged(final Subject subject, final PrivilegedExceptionAction<T> action, final AccessControlContext acc) throws PrivilegedActionException

Deprecated

for removal since 17.

This method originally performed the specified PrivilegedExceptionAction with privileges enabled and restricted by the specified AccessControlContext. Running the action with privileges enabled was only useful in conjunction with the Security Manager, which is no longer supported. This method has been changed to ignore the AccessControlContext and launch the action as is and bind the subject to the period of its execution. A replacement API named callAs has been added which can be used to perform the same work. There is no replacement for the Security Manager.

Perform work as a particular Subject.

This method launches action and binds subject to the period of its execution.

Parameters
<T>
the type of the value returned by the PrivilegedExceptionAction's run method.
subject:Subject

the Subject that the specified action will run as. This parameter may be null.

action:PrivilegedExceptionAction<T>

the code to be run as the specified Subject.

acc:AccessControlContext

ignored

Returns:T

the value returned by the PrivilegedExceptionAction's run method.

Annotations
@SuppressWarnings:removal
@Deprecated
since:17
forRemoval:true
Exceptions
PrivilegedActionException:
if the PrivilegedExceptionAction.run method throws a checked exception.
NullPointerException:
if the specified PrivilegedExceptionAction is null.
See Also
callAs(Subject, Callable)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

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.

Parameters
o:Object

Object to be compared for equality with this Subject.

Returns:boolean

true if the specified Object is equal to this Subject.

Annotations
@Override
getCredHashCodeback to summary
private int getCredHashCode(Object o)

get a credential's hashcode

getPrincipalsback to summary
public Set<Principal> 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.

Returns:Set<Principal>

the Set of Principals associated with this Subject.

getPrincipalsback to summary
public <T extends Principal> Set<T> getPrincipals(Class<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.

Parameters
<T>
the type of the class modeled by c
c:Class<T>

the returned Set of Principals will all be instances of this class.

Returns:Set<T>

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

Exceptions
NullPointerException:
if the specified Class is null.
getPrivateCredentialsback to summary
public Set<Object> 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.

Returns:Set<Object>

a Set of private credentials held by this Subject.

getPrivateCredentialsback to summary
public <T> Set<T> getPrivateCredentials(Class<T> c)

Return a Set of private 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 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.

Parameters
<T>
the type of the class modeled by c
c:Class<T>

the returned Set of private credentials will all be instances of this class.

Returns:Set<T>

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

Exceptions
NullPointerException:
if the specified Class is null.
getPublicCredentialsback to summary
public Set<Object> 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.

Returns:Set<Object>

a Set of public credentials held by this Subject.

getPublicCredentialsback to summary
public <T> Set<T> getPublicCredentials(Class<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.

Parameters
<T>
the type of the class modeled by c
c:Class<T>

the returned Set of public credentials will all be instances of this class.

Returns:Set<T>

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

Exceptions
NullPointerException:
if the specified Class is null.
getSubjectback to summary
public static Subject getSubject(final AccessControlContext acc)

Deprecated

for removal since 17.

This method used to get the subject associated with the provided AccessControlContext, which was only useful in conjunction with the Security Manager, which is no longer supported. This method has been changed to always throw UnsupportedOperationException. A replacement API named current() has been added which can be used to obtain the current subject. There is no replacement for the Security Manager.

Throws UnsupportedOperationException. A replacement API named current() has been added which can be used to obtain the current subject.

Parameters
acc:AccessControlContext

ignored

Returns:Subject

n/a

Annotations
@SuppressWarnings:removal
@Deprecated
since:17
forRemoval:true
Exceptions
UnsupportedOperationException:
always
See Also
current()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hashcode for this Subject.

Returns:int

a hashcode for this Subject

Annotations
@Override
isReadOnlyback to summary
public boolean isReadOnly()

Query whether this Subject is read-only.

Returns:boolean

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

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Reads this object from a stream (i.e., deserializes it)

Parameters
s:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@SuppressWarnings:unchecked
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
setReadOnlyback to summary
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.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the String representation of this Subject.

Returns:String

the String representation of this Subject.

Annotations
@Override
writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Writes this object out to a stream (i.e., serializes it).

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
javax.security.auth back to summary

private Class Subject.ClassSet<T>

extends AbstractSet<T>
Class Inheritance

This class implements a Set which returns only members that are an instance of a specified Class.

Field Summary

Modifier and TypeField and Description
private final Class<T>
c

private final Set<T>
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
ClassSet(int which, Class<T> c)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(T o)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).

public Iterator<T>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

private void
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Field Detail

cback to summary
private final Class<T> c
setback to summary
private final Set<T> set
whichback to summary
private final int which

Constructor Detail

ClassSetback to summary
pack-priv ClassSet(int which, Class<T> c)

Method Detail

addback to summary
public boolean add(T o)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

Annotations
@Override
iteratorback to summary
public Iterator<T> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Annotations
@Override
populateSetback to summary
private void populateSet()
Annotations
@SuppressWarnings:unchecked
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
javax.security.auth back to summary

private Class Subject.SecureSet<E>

extends Object
implements Set<E>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Set, java.util.Collection, java.lang.Iterable

Prevent modifications unless caller has permission.

Field Summary

Modifier and TypeField and Description
pack-priv LinkedList<E>
private static final ObjectStreamField[]
private static final long
pack-priv Subject
private int

Constructor Summary

AccessConstructor and Description
pack-priv
SecureSet(Subject subject, int which)

pack-priv
SecureSet(Subject subject, int which, LinkedList<E> list)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E o)

Implements java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation).

public boolean
addAll(Collection<? extends E> c)

Implements java.util.Set.addAll.

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

public void
clear()

Implements java.util.Set.clear.

Removes all of the elements from this set (optional operation).

public boolean
contains(Object o)

Implements java.util.Set.contains.

Returns true if this set contains the specified element.

public boolean
containsAll(Collection<?> c)

Implements java.util.Set.containsAll.

Returns true if this set contains all of the elements of the specified collection.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals.

Compares the specified object with this set for equality.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode.

Returns the hash code value for this set.

public boolean
isEmpty()

Implements java.util.Set.isEmpty.

Returns true if this set contains no elements.

public Iterator<E>
iterator()

Implements java.util.Set.iterator.

Returns an iterator over the elements in this set.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
ois
)

Restores the state of this object from the stream.

public boolean
remove(Object o)

Implements java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation).

public boolean
removeAll(Collection<?> c)

Implements java.util.Set.removeAll.

Removes from this set all of its elements that are contained in the specified collection (optional operation).

public boolean
retainAll(Collection<?> c)

Implements java.util.Set.retainAll.

Retains only the elements in this set that are contained in the specified collection (optional operation).

public int
size()

Implements java.util.Set.size.

Returns the number of elements in this set (its cardinality).

public Object[]
toArray()

Implements java.util.Set.toArray.

Returns an array containing all of the elements in this set.

public <T> T[]
toArray(T[] a)

Implements java.util.Set.toArray.

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Writes this object out to a stream (i.e., serializes it).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

elementsback to summary
pack-priv LinkedList<E> elements
serialPersistentFieldsback to summary
private static final ObjectStreamField[] serialPersistentFields
Annotations
@Serial
Serial Fields:
this$0:Subject
The outer Subject instance.
elements:LinkedList
The elements in this set.
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
subjectback to summary
pack-priv Subject subject
whichback to summary
private int which

Constructor Detail

SecureSetback to summary
pack-priv SecureSet(Subject subject, int which)
SecureSetback to summary
pack-priv SecureSet(Subject subject, int which, LinkedList<E> list)

Method Detail

addback to summary
public boolean add(E o)

Implements java.util.Set.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

addAllback to summary
public boolean addAll(Collection<? extends E> c)

Implements java.util.Set.addAll.

Doc from java.util.Set.addAll.

Adds all of the elements in the specified collection to this set if they're not already present (optional operation). If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

clearback to summary
public void clear()

Implements java.util.Set.clear.

Doc from java.util.Set.clear.

Removes all of the elements from this set (optional operation). The set will be empty after this call returns.

containsback to summary
public boolean contains(Object o)

Implements java.util.Set.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

containsAllback to summary
public boolean containsAll(Collection<?> c)

Implements java.util.Set.containsAll.

Doc from java.util.Set.containsAll.

Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals.

Doc from java.util.Set.equals.

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode.

Doc from java.util.Set.hashCode.

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of Object#hashCode.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Set.isEmpty.

Doc from java.util.Set.isEmpty.

Returns true if this set contains no elements.

iteratorback to summary
public Iterator<E> iterator()

Implements java.util.Set.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException

Restores the state of this object from the stream.

Parameters
ois:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@SuppressWarnings:unchecked
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
removeback to summary
public boolean remove(Object o)

Implements java.util.Set.remove.

Doc from java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

removeAllback to summary
public boolean removeAll(Collection<?> c)

Implements java.util.Set.removeAll.

Doc from java.util.Set.removeAll.

Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

retainAllback to summary
public boolean retainAll(Collection<?> c)

Implements java.util.Set.retainAll.

Doc from java.util.Set.retainAll.

Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.

sizeback to summary
public int size()

Implements java.util.Set.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

toArrayback to summary
public Object[] toArray()

Implements java.util.Set.toArray.

Doc from java.util.Set.toArray.

Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

toArrayback to summary
public <T> T[] toArray(T[] a)

Implements java.util.Set.toArray.

Doc from java.util.Set.toArray.

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.

If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to null. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)

If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a set known to contain only strings. The following code can be used to dump the set into a newly allocated array of String:

    String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Writes this object out to a stream (i.e., serializes it).

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs