Search in sources :

Example 1 with ResourceMatch

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

the class ResourceResultCache method mergePolicyDecisions.

/**
     * Merges policy decisions applicable to a resource 
     * from a <code>ResourceResult</code> object.
     *
     * @param pd a collector for merged policy decision
     * @param resourceResult <code>ResourceResult</code> from which
     * to find applicable policy decisions
     * @param resourceName resource name for which to get policy decision
     * @param resourceComparator <code>ResourceName</code>, resource
     * comparison algorithm used to compare resources
     *
     * @param serviceName service name
     *
     * @return a flag indicating whether more <code>ResourceResult</code>
     * objects need to be visited to to compute the policy decision.
     * <code>true</code> is returned if no more <code>ResourceResult</code>
     * objects need to be visited
     * 
     *
     * a <code>ResourceResult</code> object.
     *
     * @throws PolicyException if can not get policy decision
     */
private boolean mergePolicyDecisions(PolicyDecision pd, ResourceResult resourceResult, String resourceName, ResourceName resourceComparator, String serviceName) throws PolicyException {
    boolean processed = false;
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.mergePolicyDecisions():" + "resourceName=" + resourceName + ":resourceResultResourceName=" + resourceResult.getResourceName());
    }
    ResourceMatch result = resourceComparator.compare(resourceName, resourceResult.getResourceName(), //wild card compare
    true);
    if (result.equals(ResourceMatch.EXACT_MATCH)) {
        resetPolicyDecision(resourceResult.getPolicyDecision(), pd, serviceName);
        processed = true;
    } else if (result.equals(ResourceMatch.WILDCARD_MATCH)) {
        mergePolicyDecisions(resourceResult.getPolicyDecision(), pd, serviceName);
        if (pd.getTimeToLive() < System.currentTimeMillis()) {
            processed = true;
        }
        if (!processed) {
            Set resourceResults = resourceResult.getResourceResults();
            Iterator resultsIter = resourceResults.iterator();
            while (!processed && resultsIter.hasNext()) {
                ResourceResult subResult = (ResourceResult) resultsIter.next();
                processed = mergePolicyDecisions(pd, subResult, resourceName, resourceComparator, serviceName);
            }
        }
    } else if (result.equals(ResourceMatch.SUPER_RESOURCE_MATCH)) {
        Set resourceResults = resourceResult.getResourceResults();
        Iterator resultsIter = resourceResults.iterator();
        while (!processed && resultsIter.hasNext()) {
            ResourceResult subResult = (ResourceResult) resultsIter.next();
            processed = mergePolicyDecisions(pd, subResult, resourceName, resourceComparator, serviceName);
        }
    }
    // else NO_MATCH or SUBRESOURCE_MATCH nothing to do
    return processed;
}
Also used : ResourceResult(com.sun.identity.policy.ResourceResult) Set(java.util.Set) HashSet(java.util.HashSet) RequestSet(com.iplanet.services.comm.share.RequestSet) Iterator(java.util.Iterator) ResourceMatch(com.sun.identity.policy.ResourceMatch)

Example 2 with ResourceMatch

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

the class ResourceResultCache method clearCacheForResourceNames.

/**
     * Clears cached decisions for a set of resources
     * @param serviceName service name
     * @param affectedResourceNames affected resource names
     */
private static void clearCacheForResourceNames(String serviceName, Set affectedResourceNames) {
    if ((affectedResourceNames == null) || affectedResourceNames.isEmpty()) {
        return;
    }
    Map resourceTokenIDsMap = (Map) (resourceResultCache.resultCache).get(serviceName);
    if ((resourceTokenIDsMap == null) || resourceTokenIDsMap.isEmpty()) {
        return;
    }
    ResourceName resourceComparator = resourceResultCache.policyProperties.getResourceComparator(serviceName);
    Iterator arIter = affectedResourceNames.iterator();
    while (arIter.hasNext()) {
        String affectedRN = (String) arIter.next();
        if (debug.messageEnabled()) {
            debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "affectedResourceName=" + affectedRN);
        }
        synchronized (resourceTokenIDsMap) {
            Set cachedResourceNames = resourceTokenIDsMap.keySet();
            Iterator crIter = cachedResourceNames.iterator();
            while (crIter.hasNext()) {
                String cachedRN = (String) crIter.next();
                if (debug.messageEnabled()) {
                    debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "affectedResourceName=" + affectedRN + ":cachedResourceName=" + cachedRN);
                }
                if (affectedRN.equals(cachedRN)) {
                    crIter.remove();
                    if (debug.messageEnabled()) {
                        debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "cleared cached results for " + "resourceName=" + cachedRN + ":affectedResourceName=" + affectedRN + ":match=SAME RESOURCE NAME");
                    }
                } else {
                    ResourceMatch rm = resourceComparator.compare(cachedRN, affectedRN, //wildcard compare
                    true);
                    if (rm.equals(ResourceMatch.EXACT_MATCH)) {
                        crIter.remove();
                        if (debug.messageEnabled()) {
                            debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "cleared cached results for " + "resourceName=" + cachedRN + ":affectedResourceName=" + affectedRN + ":match=EXACT_MATCH");
                        }
                    } else if (rm.equals(ResourceMatch.WILDCARD_MATCH)) {
                        crIter.remove();
                        if (debug.messageEnabled()) {
                            debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "cleared cached results for " + "resourceName=" + cachedRN + ":affectedResourceName=" + affectedRN + ":match=WILD_CARD_MATCH");
                        }
                    } else if (rm.equals(ResourceMatch.SUB_RESOURCE_MATCH)) {
                        crIter.remove();
                        if (debug.messageEnabled()) {
                            debug.message("ResourceResultCache." + "clearCacheForResourceNames():" + "cleared cached results for " + "resourceName=" + cachedRN + ":affectedResourceName=" + affectedRN + ":match=SUB_RESOURCE_MACTH");
                        }
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RequestSet(com.iplanet.services.comm.share.RequestSet) ResourceName(com.sun.identity.policy.interfaces.ResourceName) Iterator(java.util.Iterator) ResourceMatch(com.sun.identity.policy.ResourceMatch) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

RequestSet (com.iplanet.services.comm.share.RequestSet)2 ResourceMatch (com.sun.identity.policy.ResourceMatch)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 ResourceResult (com.sun.identity.policy.ResourceResult)1 ResourceName (com.sun.identity.policy.interfaces.ResourceName)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1