Search in sources :

Example 1 with OrgReferral

use of com.sun.identity.policy.plugins.OrgReferral in project OpenAM by OpenRock.

the class Referrals method getPolicyDecision.

/** 
     * Returns policy deicision 
     * @param token sso token identifying the user for who the Referrals has to 
     *        be evaluated.
     * @param resourceType resourceType 
     * @param resourceName resourceName
     * @param actionNames a set of action names for which policy results
     *        are to be evaluated. Each element of the set should be a
     *        String
     * @param envParameters a map of environment parameters
     *        Each key of the map is a String valued parameter name
     *        Each value of the map is a set of String values
     * @return policy decision
     * @throws NameNotFoundException if the action name or resource name
     *         is not found
     * @throws SSOException if token is invalid
     * @throws PolicyException for any other exception condition
     */
PolicyDecision getPolicyDecision(SSOToken token, String resourceType, String resourceName, Set actionNames, Map envParameters) throws SSOException, NameNotFoundException, PolicyException {
    PolicyDecision mergedPolicyDecision = null;
    ServiceType serviceType = ServiceTypeManager.getServiceTypeManager().getServiceType(resourceType);
    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;
        }
        PolicyDecision policyDecision = referral.getPolicyDecision(token, resourceType, resourceName, actionNames, envParameters);
        if (mergedPolicyDecision == null) {
            mergedPolicyDecision = policyDecision;
        } else {
            PolicyEvaluator.mergePolicyDecisions(serviceType, policyDecision, mergedPolicyDecision);
        }
        actionNames.removeAll(PolicyEvaluator.getFinalizedActions(serviceType, mergedPolicyDecision));
        if (actionNames.isEmpty()) {
            break;
        }
    }
    return (mergedPolicyDecision);
}
Also used : Referral(com.sun.identity.policy.interfaces.Referral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral)

Example 2 with OrgReferral

use of com.sun.identity.policy.plugins.OrgReferral in project OpenAM by OpenRock.

the class ResourceManager method removePolicyFromResourceTree.

/**
     * Removes the resource names of the policy from the resource tree.
     *
     * @param policy the policy to be removed
     *
     * @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 removePolicyFromResourceTree(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);
        removeRuleFromResourceTree(policy.getName(), rule.getResourceName(), rule.getServiceTypeName(), rule.getServiceType());
    }
    //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();
                            Iterator ruleIter = policy.getRuleNames().iterator();
                            while (ruleIter.hasNext()) {
                                String ruleName1 = (String) ruleIter.next();
                                Rule rule1 = policy.getRule(ruleName);
                                String resourceName = rule1.getResourceName();
                                if (resourceName != null) {
                                    String serviceTypeName = rule1.getServiceTypeName();
                                    Set resourceNames = new HashSet();
                                    resourceNames.add(resourceName);
                                    rm.removeResourcePrefixes(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 3 with OrgReferral

use of com.sun.identity.policy.plugins.OrgReferral in project OpenAM by OpenRock.

the class ResourceIndexManager method removePolicyFromResourceTree.

/**
     *  Removes a policy's relevant content from the resource tree.
     *
     *  @param svtm service type manager
     *  @param token sso token
     *  @param policy the policy to be removed
     *
     *  @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 removePolicyFromResourceTree(ServiceTypeManager svtm, SSOToken token, Policy policy) throws PolicyException, SSOException {
    Set ruleNames = policy.getRuleNames();
    Iterator iter = ruleNames.iterator();
    // iterating through each rule
    String ruleName = null;
    Rule rule = null;
    Set serviceNames = new HashSet();
    while (iter.hasNext()) {
        ruleName = (String) iter.next();
        rule = policy.getRule(ruleName);
        String serviceName = rule.getServiceTypeName();
        serviceNames.add(serviceName);
        ServiceType resourceType = svtm.getServiceType(serviceName);
        removeIndexEntry(resourceType, rule.getResourceName(), policy.getName());
    }
    iter = serviceNames.iterator();
    while (iter.hasNext()) {
        String serviceName = (String) iter.next();
        saveResourceIndex(serviceName);
    }
    //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()) {
                            Map servicePrefixMap = new HashMap();
                            String value = (String) valueIter.next();
                            try {
                                PolicyManager pm = new PolicyManager(token, value);
                                ResourceManager rm = pm.getResourceManager();
                                Iterator ruleIter = policy.getRuleNames().iterator();
                                while (ruleIter.hasNext()) {
                                    String ruleName1 = (String) ruleIter.next();
                                    Rule rule1 = policy.getRule(ruleName1);
                                    String resourceName = rule1.getResourceName();
                                    if (resourceName != null) {
                                        String service = rule1.getServiceTypeName();
                                        Set resourceNames = (Set) servicePrefixMap.get(service);
                                        if (resourceNames == null) {
                                            resourceNames = new HashSet();
                                            servicePrefixMap.put(service, resourceNames);
                                        }
                                        resourceNames.add(resourceName);
                                    }
                                }
                                Iterator serviceIter = servicePrefixMap.keySet().iterator();
                                while (serviceIter.hasNext()) {
                                    String service = (String) serviceIter.next();
                                    Set resourceNames = (Set) servicePrefixMap.get(service);
                                    rm.removeResourcePrefixes(service, resourceNames);
                                }
                            } catch (PolicyException e) {
                                if (DEBUG.warningEnabled()) {
                                    DEBUG.warning("Could not clean up resource " + " prefixes in referrred to org :" + value + "-" + e.getMessage());
                                }
                            }
                        }
                    // processed referral value
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with OrgReferral

use of com.sun.identity.policy.plugins.OrgReferral in project OpenAM by OpenRock.

the class Policy method getReferredToOrganizations.

//    public String getServiceTypeName() {
/* com.iplanet.am.admin.cli uses this method. 
         * Need to clean up cli not to use this 
         * method. Without this method build breaks - 03/05/02 */
//       return null;
//  }
/**
     *  Gets organizations referred to in this policy by OrgReferral(s)
     *  defined in this policy.
     *  
     *  @return names of organization (DNs) of organizations referred
     *          to in this policy via <code>OrgReferral</code>(s) defined in 
     *          this policy.
     *          Please note that <code>PeerOrgReferral</code> and 
     *          <code>SubOrgReferral</code> extend <code>OrgReferral</code> 
     *          and hence qualify as OrgReferral.
     *  @exception PolicyException
     */
Set getReferredToOrganizations() throws PolicyException {
    Set referredToOrgs = new HashSet();
    Iterator referralNames = referrals.getReferralNames().iterator();
    while (referralNames.hasNext()) {
        String referralName = (String) referralNames.next();
        Referral referral = (Referral) referrals.getReferral(referralName);
        if (referral instanceof OrgReferral) {
            Set values = referral.getValues();
            if ((values != null) && (!values.isEmpty())) {
                String orgName = (String) values.iterator().next();
                referredToOrgs.add(orgName.toLowerCase());
            }
        }
    }
    return referredToOrgs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) 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 5 with OrgReferral

use of com.sun.identity.policy.plugins.OrgReferral in project OpenAM by OpenRock.

the class ResourceIndexManager method addPolicyToResourceTree.

/**
     *  Adds a policy's relevant content to the resource tree.
     *
     *  @param svtm service type manager
     *  @param token sso token
     *  @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(ServiceTypeManager svtm, SSOToken token, Policy policy) throws PolicyException, SSOException {
    Set ruleNames = policy.getRuleNames();
    Iterator iter = ruleNames.iterator();
    Set serviceNames = new HashSet();
    while (iter.hasNext()) {
        String ruleName = (String) iter.next();
        Rule rule = policy.getRule(ruleName);
        String serviceName = rule.getServiceTypeName();
        serviceNames.add(serviceName);
        ServiceType resourceType = svtm.getServiceType(serviceName);
        addIndexEntry(resourceType, rule.getResourceName(), policy.getName());
    }
    iter = serviceNames.iterator();
    while (iter.hasNext()) {
        String serviceName = (String) iter.next();
        saveResourceIndex(serviceName);
    }
    //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()) {
                            Map servicePrefixMap = new HashMap();
                            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 service = rule1.getServiceTypeName();
                                    Set resourceNames = (Set) servicePrefixMap.get(service);
                                    if (resourceNames == null) {
                                        resourceNames = new HashSet();
                                        servicePrefixMap.put(service, resourceNames);
                                    }
                                    resourceNames.add(resourceName);
                                }
                            }
                            Iterator serviceIter = servicePrefixMap.keySet().iterator();
                            while (serviceIter.hasNext()) {
                                String service = (String) serviceIter.next();
                                Set resourceNames = (Set) servicePrefixMap.get(service);
                                rm.addResourcePrefixes(service, resourceNames);
                            }
                        }
                    //processed a referral value
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Referral (com.sun.identity.policy.interfaces.Referral)7 OrgReferral (com.sun.identity.policy.plugins.OrgReferral)7 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2