use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PolicyModelImpl method createSubject.
/**
* Returns a subject object.
*
* @param realmName Name of Realm.
* @param subjectType Name of subject type.
* @param values Values of the subject.
* @return subject object.
* @throws AMConsoleException if subject cannot be created.
*/
public Subject createSubject(String realmName, String subjectType, Set values) throws AMConsoleException {
Subject subject = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
subject = subjectTypeMgr.getSubject(subjectType);
subject.setValues(values);
}
} catch (NameNotFoundException e) {
throw new AMConsoleException(getErrorString(e));
} catch (PolicyException e) {
throw new AMConsoleException(getErrorString(e));
}
return subject;
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PolicyModelImpl method getActiveSubjectTypes.
/**
* Returns a map of active subject types for a realm to its display name.
*
* @param realmName Name of Realm.
* @return a map of active subject types for a realm to its display name.
*/
public QueryResults getActiveSubjectTypes(String realmName) {
Map subjectTypes = Collections.EMPTY_MAP;
String strError = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
if (subjectTypeMgr != null) {
Set types = subjectTypeMgr.getSelectedSubjectTypeNames();
subjectTypes = new HashMap(types.size() * 2);
for (Iterator iter = types.iterator(); iter.hasNext(); ) {
String rName = (String) iter.next();
try {
Subject subject = subjectTypeMgr.getSubject(rName);
if (subject != null) {
Syntax syntax = subject.getValueSyntax(getUserSSOToken());
if (!syntax.equals(Syntax.NONE)) {
subjectTypes.put(rName, subjectTypeMgr.getDisplayName(rName));
}
}
} catch (SSOException e) {
strError = getErrorString(e);
} catch (NameNotFoundException e) {
strError = getErrorString(e);
} catch (PolicyException e) {
strError = getErrorString(e);
}
}
}
}
} catch (AMConsoleException e) {
debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
} catch (SSOException e) {
debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
} catch (NameNotFoundException e) {
debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
} catch (PolicyException e) {
debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
}
return new QueryResults(subjectTypes, strError);
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PolicyModelImpl method getSubjectViewBeanURL.
/**
* Returns properties view bean URL of a subject.
*
* @param realmName Name of realm.
* @param subjectTypeName Name of Subject Type.
* @return properties view bean URL of a subject.
*/
public String getSubjectViewBeanURL(String realmName, String subjectTypeName) {
String url = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
Subject subject = subjectTypeMgr.getSubject(subjectTypeName);
url = subjectTypeMgr.getViewBeanURL(subject);
}
} catch (AMConsoleException e) {
debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
} catch (NameNotFoundException e) {
debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
} catch (PolicyException e) {
debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
}
return url;
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class SharedSubject method isMember.
/**
* Determines if the user identified by <code>SSOToken</cdoe>
* is a member of this <code>Subject</code>.
*
* @param token single-sign-on token of the user
*
* @return <code>true</code> if the user is member of the
* given subject, <code>false</code> otherwise.
*
* @exception SSOException if SSO token is not valid
* @exception PolicyException if an error occurred while
* checking if the user is a member of this subject
*/
public boolean isMember(SSOToken token) throws SSOException, PolicyException {
boolean member = false;
if (mstm == null) {
String realmName = stm.getPolicyManager().getOrganizationDN();
mstm = PolicyCache.getInstance().getPolicyManager(realmName).getSubjectTypeManager();
}
Subject subject = mstm.getCachedSubjectByName(subjectName);
if (subject != null) {
member = subject.isMember(token);
} else {
if (debug.warningEnabled()) {
debug.warning("Realm subject: " + subjectName + " not found");
}
}
return member;
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class SubjectTypeManager method removeSubject.
/**
* Removes the subject with the given name from the realm.
* This method would throw PolicyException if the subject
* is being used by any policy unless <code>forcedRemove</code>
* argument is set to <code>true</code>.
* If the <code>forcedRemove</code> argument is set to
* <code>true</code> policies that are using the subject would
* be modified to remove the references to the subject
*
* @param subjectName name of the Subject
* @param forcedRemove if set to <code>true</code>, policies that
* use the subject would be modifed to remove the references
* to the subject. Otherwise, <code>ObjectInUseException</code>
* would be thrown if there is any policy using the subject
*
* @return returns the Subject object being removed,
* returns <code>null</code> if Subject with
* the given subjectName is not present
*
* @throws PolicyException if can not remove the Subject
*/
public Subject removeSubject(String subjectName, boolean forcedRemove) throws ObjectInUseException, PolicyException, SSOException {
if (debug.messageEnabled()) {
debug.message("Removing realm subject : " + subjectName + ", in realm:" + pmRealmName);
}
if (realmSubjects == null) {
initRealmSubjects();
}
if (forcedRemove) {
Set userPolicies = pm.getPoliciesUsingRealmSubject(subjectName);
for (Iterator policyIter = userPolicies.iterator(); policyIter.hasNext(); ) {
Policy policy = (Policy) policyIter.next();
policy.removeSubject(subjectName);
}
} else {
Policy p = pm.getPolicyUsingRealmSubject(subjectName);
if (p != null) {
//Object[] args, String name, Object user)
throw new ObjectInUseException(null, null, null, null, null);
}
}
Subject subject = realmSubjects.removeSubject(subjectName);
saveSubjects();
if (debug.messageEnabled()) {
debug.message("Removed realm subject : " + subjectName + ", in realm:" + pmRealmName);
}
return subject;
}
Aggregations