Movatterモバイル変換


[0]ホーム

URL:


         


Class Subject

java.lang.Object  |  +--javax.security.auth.Subject
All Implemented Interfaces:
java.io.Serializable

public final classSubject
extends java.lang.Object
implements java.io.Serializable

ASubject 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 aPrincipal within theSubject. Principals simply bind names to aSubject. For example, aSubject that happens to be a person, Alice, might have two Principals: one which binds "Alice Bar", the name on her driver license, to theSubject, and another which binds, "999-99-9999", the number on her student identification card, to theSubject. Both Principals refer to the sameSubject even though each has a different name.

ASubject 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 credentialSet. Credentials intended to be shared, such as public key certificates or Kerberos server tickets are stored within a public credentialSet. Different permissions are required to access and modify the different credential Sets.

To retrieve all the Principals associated with aSubject, invoke thegetPrincipals method. To retrieve all the public or private credentials belonging to aSubject, invoke thegetPublicCredentials method orgetPrivateCredentials method, respectively. To modify the returnedSet of Principals and credentials, use the methods defined in theSet class. For example:

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

ThisSubject class implementsSerializable. While the Principals associated with theSubject are serialized, the credentials associated with theSubject are not. Note that thejava.security.Principal class does not implementSerializable. Therefore all concretePrincipal implementations associated with Subjects must implementSerializable.

See Also:
Principal,DomainCombiner,Serialized Form

Subject()
          Create an instance of aSubject with an emptySet of Principals and empty Sets of public and private credentials.
Subject(boolean readOnly, java.util.Set principals, java.util.Set pubCredentials, java.util.Set privCredentials)
          Create an instance of aSubject with the specified Sets of Principals and credentials.
 
doAs(Subject subject, java.security.PrivilegedAction action)
          Perform work as a particularSubject.
doAs(Subject subject, java.security.PrivilegedExceptionAction action)
          Perform work as a particularSubject.
doAsPrivileged(Subject subject, java.security.PrivilegedAction action, java.security.AccessControlContext acc)
          Perform privileged work as a particularSubject.
doAsPrivileged(Subject subject, java.security.PrivilegedExceptionAction action, java.security.AccessControlContext acc)
          Perform privileged work as a particularSubject.
equals(java.lang.Object o)
          Compares the specified Object with thisSubject for equality.
getPrincipals()
          Return theSet of Principals associated with thisSubject.
getPrincipals(java.lang.Class c)
          Return aSet of Principals associated with thisSubject that are instances or subclasses of the specifiedClass.
getPrivateCredentials()
          Return theSet of private credentials held by thisSubject.
getPrivateCredentials(java.lang.Class c)
          Return aSet of private credentials associated with thisSubject that are instances or subclasses of the specifiedClass.
getPublicCredentials()
          Return theSet of public credentials held by thisSubject.
getPublicCredentials(java.lang.Class c)
          Return aSet of public credentials associated with thisSubject that are instances or subclasses of the specifiedClass.
getSubject(java.security.AccessControlContext acc)
          Get theSubject associated with the providedAccessControlContext.
hashCode()
          Returns a hashcode for thisSubject.
isReadOnly()
          Query whether thisSubject is read-only.
setReadOnly()
          Set thisSubject to be read-only.
toString()
          Return the String representation of thisSubject.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Subject

publicSubject()
Create an instance of aSubject with an emptySet of Principals and empty Sets of public and private credentials.

The newly constructed Sets check whether thisSubject 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 haveAuthPermission("modifyPrincipals"), for example).


Subject

publicSubject(boolean readOnly,               java.util.Set principals,               java.util.Set pubCredentials,               java.util.Set privCredentials)
Create an instance of aSubject with the specified Sets of Principals and credentials.

The specified Sets must check whether thisSubject has been set read-only before permitting subsequent modifications. The specified Sets must also prevent illegal modifications by ensuring that callers have sufficient permissions.

Parameters:
readOnly - true if theSubject is to be read-only,and false otherwise.

principals - theSet of Principalsto be associated with thisSubject.

pubCredentials - theSet of public credentialsto be associated with thisSubject.

privCredentials - theSet of private credentialsto be associated with thisSubject.
Throws:
java.lang.NullPointerException - if the specifiedprincipals,pubCredentials,orprivCredentials arenull.

setReadOnly

public voidsetReadOnly()
Set thisSubject to be read-only.

Modifications (additions and removals) to this Subject'sPrincipalSet and credential Sets will be disallowed. Thedestroy operation on this Subject's credentials will still be permitted.

Subsequent attempts to modify the Subject'sPrincipal and credential Sets will result in anIllegalStateException being thrown. Also, once aSubject is read-only, it can not be reset to being writable again.

Throws:
java.lang.SecurityException - if the caller does not have permissionto set thisSubject to be read-only.

isReadOnly

public booleanisReadOnly()
Query whether thisSubject is read-only.

Returns:
true if thisSubject is read-only, false otherwise.

getSubject

public staticSubjectgetSubject(java.security.AccessControlContext acc)
Get theSubject associated with the providedAccessControlContext.

TheAccessControlContext may contain many Subjects (from nesteddoAs calls). In this situation, the most recentSubject associated with theAccessControlContext is returned.

Parameters:
acc - theAccessControlContext from which to retrievetheSubject.
Returns:
theSubject associated with the providedAccessControlContext, ornullif noSubject is associatedwith the providedAccessControlContext.
Throws:
java.lang.SecurityException - if the caller does not have permissionto get theSubject.

java.lang.NullPointerException - if the providedAccessControlContext isnull.

doAs

public static java.lang.ObjectdoAs(Subject subject,                                    java.security.PrivilegedAction action)
Perform work as a particularSubject.

This method first retrieves the current Thread'sAccessControlContext viaAccessController.getContext, and then instantiates a newAccessControlContext using the retrieved context along with a newSubjectDomainCombiner (constructed using the providedSubject). Finally, this method invokesAccessController.doPrivileged, passing it the providedPrivilegedAction, as well as the newly constructedAccessControlContext.

Parameters:
subject - theSubject that the specifiedaction will run as. This parametermay benull.

action - the code to be run as the specifiedSubject.

Returns:
theObject returned by the PrivilegedAction'srun method.
Throws:
java.lang.NullPointerException - if thePrivilegedActionisnull.

java.lang.SecurityException - if the caller does not have permissionto invoke this method.

doAs

public static java.lang.ObjectdoAs(Subject subject,                                    java.security.PrivilegedExceptionAction action)                             throws java.security.PrivilegedActionException
Perform work as a particularSubject.

This method first retrieves the current Thread'sAccessControlContext viaAccessController.getContext, and then instantiates a newAccessControlContext using the retrieved context along with a newSubjectDomainCombiner (constructed using the providedSubject). Finally, this method invokesAccessController.doPrivileged, passing it the providedPrivilegedExceptionAction, as well as the newly constructedAccessControlContext.

Parameters:
subject - theSubject that the specifiedaction will run as. This parametermay benull.

action - the code to be run as the specifiedSubject.

Returns:
theObject returned by thePrivilegedExceptionAction'srun method.
Throws:
java.security.PrivilegedActionException - if thePrivilegedExceptionAction.runmethod throws a checked exception.

java.lang.NullPointerException - if the specifiedPrivilegedExceptionAction isnull.

java.lang.SecurityException - if the caller does not have permissionto invoke this method.

doAsPrivileged

public static java.lang.ObjectdoAsPrivileged(Subject subject,                                              java.security.PrivilegedAction action,                                              java.security.AccessControlContext acc)
Perform privileged work as a particularSubject.

This method behaves exactly asSubject.doAs, except that instead of retrieving the current Thread'sAccessControlContext, it uses the providedAccessControlContext. If the providedAccessControlContext isnull, this method instantiates a newAccessControlContext with an empty collection of ProtectionDomains.

Parameters:
subject - theSubject that the specifiedaction will run as. This parametermay benull.

action - the code to be run as the specifiedSubject.

acc - theAccessControlContext to be tied to thespecifiedsubject andaction.

Returns:
theObject returned by the PrivilegedAction'srun method.
Throws:
java.lang.NullPointerException - if thePrivilegedActionisnull.

java.lang.SecurityException - if the caller does not have permissionto invoke this method.

doAsPrivileged

public static java.lang.ObjectdoAsPrivileged(Subject subject,                                              java.security.PrivilegedExceptionAction action,                                              java.security.AccessControlContext acc)                                       throws java.security.PrivilegedActionException
Perform privileged work as a particularSubject.

This method behaves exactly asSubject.doAs, except that instead of retrieving the current Thread'sAccessControlContext, it uses the providedAccessControlContext. If the providedAccessControlContext isnull, this method instantiates a newAccessControlContext with an empty collection of ProtectionDomains.

Parameters:
subject - theSubject that the specifiedaction will run as. This parametermay benull.

action - the code to be run as the specifiedSubject.

acc - theAccessControlContext to be tied to thespecifiedsubject andaction.

Returns:
theObject returned by thePrivilegedExceptionAction'srun method.
Throws:
java.security.PrivilegedActionException - if thePrivilegedExceptionAction.runmethod throws a checked exception.

java.lang.NullPointerException - if the specifiedPrivilegedExceptionAction isnull.

java.lang.SecurityException - if the caller does not have permissionto invoke this method.

getPrincipals

public java.util.SetgetPrincipals()
Return theSet of Principals associated with thisSubject. EachPrincipal represents an identity for thisSubject.

The returnedSet is backed by this Subject's internalPrincipalSet. Any modification to the returnedSet affects the internalPrincipalSet as well.

Returns:
TheSet of Principals associated with thisSubject.

getPrincipals

public java.util.SetgetPrincipals(java.lang.Class c)
Return aSet of Principals associated with thisSubject that are instances or subclasses of the specifiedClass.

The returnedSet is not backed by this Subject's internalPrincipalSet. A newSet is created and returned for each method invocation. Modifications to the returnedSet will not affect the internalPrincipalSet.

Parameters:
c - the returnedSet of Principals will all beinstances of this class.
Returns:
aSet of Principals that are instances of thespecifiedClass.
Throws:
java.lang.NullPointerException - if the specifiedClassisnull.

getPublicCredentials

public java.util.SetgetPublicCredentials()
Return theSet of public credentials held by thisSubject.

The returnedSet is backed by this Subject's internal public CredentialSet. Any modification to the returnedSet affects the internal public CredentialSet as well.

Returns:
ASet of public credentials held by thisSubject.

getPrivateCredentials

public java.util.SetgetPrivateCredentials()
Return theSet of private credentials held by thisSubject.

The returnedSet is backed by this Subject's internal private CredentialSet. Any modification to the returnedSet affects the internal private CredentialSet as well.

Returns:
ASet of private credentials held by thisSubject.

getPublicCredentials

public java.util.SetgetPublicCredentials(java.lang.Class c)
Return aSet of public credentials associated with thisSubject that are instances or subclasses of the specifiedClass.

The returnedSet is not backed by this Subject's internal public CredentialSet. A newSet is created and returned for each method invocation. Modifications to the returnedSet will not affect the internal public CredentialSet.

Parameters:
c - the returnedSet of public credentials will all beinstances of this class.
Returns:
aSet of public credentials that are instancesof thespecifiedClass.
Throws:
java.lang.NullPointerException - if the specifiedClassisnull.

getPrivateCredentials

public java.util.SetgetPrivateCredentials(java.lang.Class c)
Return aSet of private credentials associated with thisSubject that are instances or subclasses of the specifiedClass.

The returnedSet is not backed by this Subject's internal private CredentialSet. A newSet is created and returned for each method invocation. Modifications to the returnedSet will not affect the internal private CredentialSet.

Parameters:
c - the returnedSet of private credentials will all beinstances of this class.
Returns:
aSet of private credentials that are instancesof thespecifiedClass.
Throws:
java.lang.NullPointerException - if the specifiedClassisnull.

equals

public booleanequals(java.lang.Object o)
Compares the specified Object with thisSubject for equality. Returns true if the given object is also a Subject and the twoSubject instances are equivalent. More formally, twoSubject instances are equal if theirPrincipal andCredential Sets are equal.

Overrides:
equals in classjava.lang.Object
Parameters:
o - Object to be compared for equality with thisSubject.
Returns:
true if the specified Object is equal to thisSubject.
Throws:
java.lang.SecurityException - if the caller does not have permissionto access the private credentials for thisSubject,or if the caller does not have permission to access theprivate credentials for the providedSubject.

toString

public java.lang.StringtoString()
Return the String representation of thisSubject.

Overrides:
toString in classjava.lang.Object
Returns:
the String representation of thisSubject.

hashCode

public inthashCode()
Returns a hashcode for thisSubject.

The hashcode is derived exclusive or-ing the hashcodes of this Subject's Principals and credentials.

If a particular credential was destroyed (credential.hashCode() throws anIllegalStateException), the hashcode for that credential is derived via:credential.getClass().toString().hashCode().

Overrides:
hashCode in classjava.lang.Object
Returns:
a hashcode for thisSubject.
Throws:
java.lang.SecurityException - if the caller does not have permissionto access this Subject's private credentials.

         


[8]ページ先頭

©2009-2025 Movatter.jp