Search in sources :

Example 21 with Referral

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);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Referral(com.sun.identity.policy.interfaces.Referral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) Iterator(java.util.Iterator) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) HashSet(java.util.HashSet)

Example 22 with Referral

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);
}
Also used : Referral(com.sun.identity.policy.interfaces.Referral) SSOException(com.iplanet.sso.SSOException)

Example 23 with Referral

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;
}
Also used : Referral(com.sun.identity.policy.interfaces.Referral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral)

Aggregations

Referral (com.sun.identity.policy.interfaces.Referral)23 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)10 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)10 Set (java.util.Set)10 OrgReferral (com.sun.identity.policy.plugins.OrgReferral)8 HashSet (java.util.HashSet)8 Iterator (java.util.Iterator)8 PolicyManager (com.sun.identity.policy.PolicyManager)7 ReferralTypeManager (com.sun.identity.policy.ReferralTypeManager)7 Policy (com.sun.identity.policy.Policy)6 PolicyException (com.sun.identity.policy.PolicyException)6 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 SSOException (com.iplanet.sso.SSOException)4 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)3 InvalidNameException (com.sun.identity.policy.InvalidNameException)2 NameAlreadyExistsException (com.sun.identity.policy.NameAlreadyExistsException)2 Syntax (com.sun.identity.policy.Syntax)2 SSOToken (com.iplanet.sso.SSOToken)1