use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class ResourceManager method addPolicyToResourceTree.
/**
* Adds the resource names of the policy to the resource tree.
*
* @param policy the policy to be added
*
* @exception PolicyException if unable to get the policy services,
* and will contain the exception thrown by SMS.
* @exception SSOException single-sign-on token invalid or expired
*/
void addPolicyToResourceTree(Policy policy) throws PolicyException, SSOException {
Set ruleNames = policy.getRuleNames();
Iterator i = ruleNames.iterator();
// iterating through each rule
String ruleName = null;
Rule rule = null;
while (i.hasNext()) {
ruleName = (String) i.next();
rule = policy.getRule(ruleName);
addRuleToResourceTree(policy.getName(), rule);
}
//Process Referrals
Referrals referrals = policy.getReferrals();
if (referrals != null) {
Set referralNames = referrals.getReferralNames();
if ((referralNames != null) && (!referralNames.isEmpty())) {
Iterator referralIter = referralNames.iterator();
while (referralIter.hasNext()) {
String referralName = (String) referralIter.next();
Referral referral = referrals.getReferral(referralName);
if (referral instanceof OrgReferral) {
Set values = referral.getValues();
if ((values != null) && (!values.isEmpty())) {
Iterator valueIter = values.iterator();
while (valueIter.hasNext()) {
String value = (String) valueIter.next();
PolicyManager pm = new PolicyManager(token, value);
ResourceManager rm = pm.getResourceManager();
Set ruleNames1 = policy.getRuleNames();
Iterator ruleIter = ruleNames1.iterator();
while (ruleIter.hasNext()) {
String ruleName1 = (String) ruleIter.next();
Rule rule1 = policy.getRule(ruleName1);
String resourceName = rule1.getResourceName();
if (resourceName != null) {
String serviceTypeName = rule1.getServiceTypeName();
Set resourceNames = new HashSet();
resourceNames.add(resourceName);
rm.addResourcePrefixes(serviceTypeName, resourceNames);
}
}
}
}
}
}
}
}
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class ReferralTypeManager method getReferral.
/**
* Returns an instance of the <code>Referral</code>
* given the referral type name.
*
* @param referralType type of referral.
* @return an instance of the <code>Referral</code> given the referral type
* name.
* @throws NameNotFoundException if the <code>Referral</code> for the
* <code>referralType</code> name is not found
* @throws PolicyException for any other abnormal condition
*/
public Referral getReferral(String referralType) throws NameNotFoundException, PolicyException {
PluginSchema ps = PolicyManager.getPluginSchema(REFERRAL, referralType);
if (ps == null) {
throw (new NameNotFoundException(ResBundleUtils.rbName, "invalid_referral", null, referralType, PolicyException.USER_COLLECTION));
}
// Construct the object
Referral answer = null;
try {
String className = ps.getClassName();
answer = (Referral) Class.forName(className).newInstance();
} catch (Exception e) {
throw (new PolicyException(e));
}
// Construct the Referral and return
Map policyConfig = pm.getPolicyConfig();
answer.initialize(policyConfig);
return (answer);
}
use of com.sun.identity.policy.interfaces.Referral in project OpenAM by OpenRock.
the class Referrals method getResourceNames.
/**
* Returns resource names rooted at the given resource name for the given
* serviceType that could be governed by this referral set
* @param token sso token
* @param serviceTypeName service type name
* @param resourceName resource name
* @return names of sub resources for the given resourceName.
* The return value also includes the resourceName.
*
* @throws PolicyException
* @throws SSOException
*/
Set getResourceNames(SSOToken token, String serviceTypeName, String resourceName) throws PolicyException, SSOException {
Set resourceNames = new HashSet();
Set referralNames = getReferralNames();
Iterator referralIter = referralNames.iterator();
while (referralIter.hasNext()) {
String referralName = (String) referralIter.next();
Referral referral = getReferral(referralName);
if (referral instanceof OrgReferral) {
//specially evaluated by PolicyEvaluator
continue;
}
Set rResourceNames = referral.getResourceNames(token, serviceTypeName, resourceName);
resourceNames.addAll(rResourceNames);
}
return resourceNames;
}
Aggregations