Package com.sun.identity.policy
Class Subjects
- java.lang.Object
-
- com.sun.identity.policy.Subjects
-
public class Subjects extends Object
The classSubjectsprovides methods to maintain a collection ofSubjectobjects that can be applied to a policy. This class provides methods to add, replace and removeSubjectobjects from this users collection. ThePolicyobject provides methods to setSubjects, which identifies users to whom the the policy applies.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSubjects()Constructor used by thePolicyobject to get a default instance of theSubjectsprotectedSubjects(PolicyManager pm, Node usersNode)Constructor used byPolicyto obtain an instance ofSubjectsfrom the XML documentSubjects(String name, String description)Constructor to obtain an instance ofSubjectsto hold collection of users represented asSubject
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSubject(Subject subject)Adds aSubjectobject to the this instance of user collection.voidaddSubject(String subjectName, Subject subject)Adds aSubjectobject to the this instance of user collection.voidaddSubject(String subjectName, Subject subject, boolean exclusive)Adds aSubjectobject to the this instance of user collection.Objectclone()Returns a new copy of this object with the identical set of user collections (subjects).booleanequals(Object o)Checks if twoSubjectsare identical.StringgetDescription()Returns the description for the collection of users represented asSubjectStringgetName()Returns the name for the collection of users represented asSubjectSubjectgetSubject(String subjectName)Returns theSubjectobject associated with the given subject name.StringgetSubjectName(Subject subject)Returns the name associated with the given subject object.SetgetSubjectNames()Returns the names ofSubjectobjects contained in this object.booleanisMember(SSOToken token)Checks if the given user (usingSSOToken) belongs to any of the subjects contained in this user collection (subjects).booleanisRealmSubject(String subjectName)Checks if the subject is a reference to aSubjectdefined at the realm.booleanisSubjectExclusive(String subjectName)Checks if the subject is exclusive.SubjectremoveSubject(Subject subject)Removes theSubjectobject identified by object'sequalsmethod.SubjectremoveSubject(String subjectName)Removes theSubjectobject identified by the subject name.voidreplaceSubject(String subjectName, Subject subject)Replaces an existing subject object having the same name with the new one.voidreplaceSubject(String subjectName, Subject subject, boolean exclusive)Replaces an existing subject object having the same name with the new one.voidsetDescription(String description)Sets the description for this instance of theSubjectswhich contains a collection of users respresented asSubject.voidsetName(String name)Sets the name for this instance of theSubjectswhich contains a collection of users respresented asSubject.StringtoString()Returns XML string representation of the subject (user collection) object.protected StringtoXML()Returns XML string representation of the subject (user collection) object.
-
-
-
Constructor Detail
-
Subjects
protected Subjects()
Constructor used by thePolicyobject to get a default instance of theSubjects
-
Subjects
protected Subjects(PolicyManager pm, Node usersNode) throws InvalidFormatException, InvalidNameException, NameNotFoundException, PolicyException
Constructor used byPolicyto obtain an instance ofSubjectsfrom the XML document- Parameters:
usersNode- node that repersents the Subjects- Throws:
InvalidFormatException- if the node passed in does not conform to expected formatInvalidNameExceptionNameNotFoundExceptionPolicyException- if can not constructSubjects
-
-
Method Detail
-
getName
public String getName()
Returns the name for the collection of users represented asSubject- Returns:
- name of the collection of subjects
-
getDescription
public String getDescription()
Returns the description for the collection of users represented asSubject- Returns:
- description for the collection of subjects
-
setName
public void setName(String name)
Sets the name for this instance of theSubjectswhich contains a collection of users respresented asSubject.- Parameters:
name- for the collection of subjects
-
setDescription
public void setDescription(String description)
Sets the description for this instance of theSubjectswhich contains a collection of users respresented asSubject.- Parameters:
description- description for the collection subjects
-
getSubjectNames
public Set getSubjectNames()
Returns the names ofSubjectobjects contained in this object.- Returns:
- names of
Subjectcontained in this object
-
getSubject
public Subject getSubject(String subjectName) throws NameNotFoundException
Returns theSubjectobject associated with the given subject name.- Parameters:
subjectName- name of the subject object- Returns:
- subject object corresponding to subject name
- Throws:
NameNotFoundException- if a subject with the given name is not present
-
addSubject
public void addSubject(Subject subject) throws NameAlreadyExistsException
Adds aSubjectobject to the this instance of user collection. Since the name is not provided it will be dynamically assigned such that it is unique within this instance of the user collection. However if a subject entry with the same name already exists in the user collectionNameAlreadyExistsExceptionwill be thrown. The subject is added as a normal (non exclusive) subject. So, policy will apply to members of the subject.- Parameters:
subject- instance of the subject object added to this collection- Throws:
NameAlreadyExistsException- throw if a subject object is present with the same name
-
addSubject
public void addSubject(String subjectName, Subject subject) throws NameAlreadyExistsException
Adds aSubjectobject to the this instance of user collection. If another subject with the same name already exists in the user collectionNameAlreadyExistsExceptionwill be thrown. The subject is added as a normal (non exclusive) subject. So, policy will apply to members of the subject.- Parameters:
subjectName- name for the subject instancesubject- instance of the subject object added to this collection- Throws:
NameAlreadyExistsException- if a subject object is present with the same name
-
addSubject
public void addSubject(String subjectName, Subject subject, boolean exclusive) throws NameAlreadyExistsException
Adds aSubjectobject to the this instance of user collection. If another subject with the same name already exists in the user collectionNameAlreadyExistsExceptionwill be thrown.- Parameters:
subjectName- name for the subject instancesubject- instance of the subject object added to this collectionexclusive- boolean flag indicating whether the subject is to be exclusive subject. If subject is exclusive, policy applies to users who are not members of the subject. Otherwise, policy applies to members of the subject.- Throws:
NameAlreadyExistsException- if a subject object is present with the same name
-
replaceSubject
public void replaceSubject(String subjectName, Subject subject) throws NameNotFoundException
Replaces an existing subject object having the same name with the new one. If aSubjectwith the given name does not exist,NameNotFoundExceptionwill be thrown. The subject is replaced as a normal (non exclusive) subject. So, policy will apply to members of the subject.- Parameters:
subjectName- name for the subject instancesubject- instance of the subject object that will replace another subject object having the given name- Throws:
NameNotFoundException- if a subject instance with the given name is not present
-
replaceSubject
public void replaceSubject(String subjectName, Subject subject, boolean exclusive) throws NameNotFoundException
Replaces an existing subject object having the same name with the new one. If aSubjectwith the given name does not exist,NameNotFoundExceptionwill be thrown.- Parameters:
subjectName- name for the subject instancesubject- instance of the subject object that will replace another subject object having the given nameexclusive- boolean flag indicating whether the subject is to be exclusive subject. If subject is exclusive, policy applies to users who are not members of the subject. Otherwise, policy applies to members of the subject.- Throws:
NameNotFoundException- if a subject instance with the given name is not present
-
removeSubject
public Subject removeSubject(String subjectName)
Removes theSubjectobject identified by the subject name. If a subject instance with the given name does not exist, the method will return silently.- Parameters:
subjectName- name of the subject instance that will be removed from the user collection- Returns:
- the subject that was just removed
-
removeSubject
public Subject removeSubject(Subject subject)
Removes theSubjectobject identified by object'sequalsmethod. If a subject instance does not exist, the method will return silently.- Parameters:
subject- subject object that will be removed from the user collection- Returns:
- the subject that was just removed
-
isSubjectExclusive
public boolean isSubjectExclusive(String subjectName) throws NameNotFoundException
Checks if the subject is exclusive. If subject is exclusive, policy applies to users who are not members of the subject. Otherwise, policy applies to members of the subject.- Parameters:
subjectName- name of the subject- Returns:
trueif the subject is exclusive,falseotherwise- Throws:
NameNotFoundException- if the subject with the given subjectName does not exist in the policy
-
isRealmSubject
public boolean isRealmSubject(String subjectName) throws NameNotFoundException
Checks if the subject is a reference to aSubjectdefined at the realm.- Parameters:
subjectName- name of the subject- Returns:
trueif the subject is a reference to aSubjectdefinet at the realm,falseotherwise- Throws:
NameNotFoundException- if the subject with the given subjectName does not exist in the policy
-
getSubjectName
public String getSubjectName(Subject subject)
Returns the name associated with the given subject object. It uses theequalsmethod on the subject to determine equality. If a subject instance that matches the given subject object is not present, the method returnsnull.- Parameters:
subject- subject object for which this method will return its associated name- Returns:
- user friendly name given to the subject object;
nullif not present
-
equals
public boolean equals(Object o)
Checks if twoSubjectsare identical. Two subjects (or user collections) are identical only if both have the same set ofSubjectobjects.
-
clone
public Object clone()
Returns a new copy of this object with the identical set of user collections (subjects).
-
isMember
public boolean isMember(SSOToken token) throws SSOException, PolicyException
Checks if the given user (usingSSOToken) belongs to any of the subjects contained in this user collection (subjects). In the current implementation it is sufficient if the user belongs to one of the subject objects, however in the future it can be extended to have complex logical operations.- Parameters:
token- single-sign-on token of the user- Returns:
trueif the user is memeber of one of the subjects;falseotherwise.- Throws:
SSOException- if SSO token is not validPolicyException- if an error occured while checking if the user is a member of one of subjects
-
toString
public String toString()
Returns XML string representation of the subject (user collection) object.
-
toXML
protected String toXML()
Returns XML string representation of the subject (user collection) object.- Returns:
- xml string representation of this object
-
-