Search in sources :

Example 21 with PolicyDecision

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

the class ResourceResultCache method getPolicyDecisionFromResourceResults.

/**
     * Returns policy decision computed from a set of
     * <code>ResourceResult</code> objects
     *
     * @param resourceResults resource results used to compute policy decision
     * @param resourceName resource name for which to get policy decision
     * @param resourceComparator <code>ResourceName</code>, resource
     * comparison algorithm used to compare resources
     *
     * @return computed policy decision
     *
     * @throws PolicyException if can not get policy decision
     */
private PolicyDecision getPolicyDecisionFromResourceResults(Set resourceResults, String resourceName, ResourceName resourceComparator, String serviceName) throws PolicyException {
    PolicyDecision pd = new PolicyDecision();
    Iterator resultsIter = resourceResults.iterator();
    boolean processed = false;
    while (!processed && resultsIter.hasNext()) {
        ResourceResult resourceResult = (ResourceResult) resultsIter.next();
        processed = mergePolicyDecisions(pd, resourceResult, resourceName, resourceComparator, serviceName);
    }
    return pd;
}
Also used : PolicyDecision(com.sun.identity.policy.PolicyDecision) ResourceResult(com.sun.identity.policy.ResourceResult) Iterator(java.util.Iterator)

Example 22 with PolicyDecision

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

the class ResourceResultCache method getPolicyDecision.

/**
     * Returns policy decision
     * @param appToken application sso token to identify the client to policy
     * service
     *
     * @param serviceName name of service for which to get policy decision
     * @param token session token of user for whom to get policy decision
     * @param resourceName resource name for which to get policy decision
     * @param actionNames action names for which to get policy decision
     * @param env environment map to use to get policy decision
     *
     * @param useCache flag indicating whether to return a locally cached 
     * policy decision.  Locally cached decision is returned only if the 
     * value is <code>true</code>. Otherwise, policy decision is fetched 
     * from policy service and returned.
     *
     * @return policy decision
     * @throws PolicyException if can not get policy decision
     * @throws SSOException if session token is not valid
     */
private PolicyDecision getPolicyDecision(SSOToken appToken, String serviceName, SSOToken token, String resourceName, Set actionNames, Map env, boolean useCache) throws InvalidAppSSOTokenException, PolicyException, SSOException {
    String cacheMode = policyProperties.getCacheMode();
    String rootResourceName = resourceName;
    if (PolicyProperties.SUBTREE.equals(cacheMode)) {
        rootResourceName = getRootResourceName(resourceName, serviceName);
        if (debug.messageEnabled()) {
            debug.message("ResourceResultCache.getPolicyDecision():" + "resourceName=" + resourceName + ":cacheMode=" + cacheMode + ":would get resource results for root resource=" + rootResourceName);
        }
    }
    Set resourceResults = getResourceResults(appToken, serviceName, token, rootResourceName, actionNames, env, cacheMode, useCache);
    ResourceName resourceComparator = (ResourceName) policyProperties.getResourceComparator(serviceName);
    PolicyDecision pd = getPolicyDecisionFromResourceResults(resourceResults, resourceName, resourceComparator, serviceName);
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.getPolicyDecision():" + ":serviceName=" + serviceName + ":token=" + token.getPrincipal().getName() + ":resourceName=" + resourceName + ":actionNames=" + actionNames + ":env" + ":cacehMode=" + cacheMode + ":useCache=" + useCache + ":returning policyDecision:" + pd);
    }
    return pd;
}
Also used : PolicyDecision(com.sun.identity.policy.PolicyDecision) Set(java.util.Set) HashSet(java.util.HashSet) RequestSet(com.iplanet.services.comm.share.RequestSet) ResourceName(com.sun.identity.policy.interfaces.ResourceName)

Aggregations

PolicyDecision (com.sun.identity.policy.PolicyDecision)22 HashSet (java.util.HashSet)14 Set (java.util.Set)13 Map (java.util.Map)12 HashMap (java.util.HashMap)11 SSOToken (com.iplanet.sso.SSOToken)8 ActionDecision (com.sun.identity.policy.ActionDecision)8 ResourceResult (com.sun.identity.policy.ResourceResult)6 PolicyEvaluator (com.sun.identity.policy.client.PolicyEvaluator)6 PolicyEvaluator (com.sun.identity.policy.PolicyEvaluator)5 Test (org.testng.annotations.Test)5 Parameters (org.testng.annotations.Parameters)4 PolicyException (com.sun.identity.policy.PolicyException)3 ResourceName (com.sun.identity.policy.interfaces.ResourceName)3 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3 ServletException (javax.servlet.ServletException)3 RequestSet (com.iplanet.services.comm.share.RequestSet)2 SSOException (com.iplanet.sso.SSOException)2 AuthContext (com.sun.identity.authentication.AuthContext)2