Java Code Examples for org.wso2.balana.finder.PolicyFinderResult#indeterminate()

The following examples show how to use org.wso2.balana.finder.PolicyFinderResult#indeterminate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolicyReference.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Private helper method that tried to resolve the policy
 */
private AbstractPolicy resolvePolicy() {
    // see if this reference was setup with a finder
    if (finder == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("PolicyReference with id " + reference.toString()
                    + " was queried but was " + "not configured with a PolicyFinder");
        }

        throw new ProcessingException("couldn't find the policy with " + "a null finder");
    }

    PolicyFinderResult pfr = finder.findPolicy(reference, policyType, constraints,
            parentMetaData);

    if (pfr.notApplicable())
        throw new ProcessingException("couldn't resolve the policy");

    if (pfr.indeterminate())
        throw new ProcessingException("error resolving the policy");

    return pfr.getPolicy();
}
 
Example 2
Source File: PolicyReference.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
     * Tries to evaluate the policy by calling the combining algorithm on the given policies or
     * rules. The <code>match</code> method must always be called first, and must always return
     * MATCH, before this method is called.
     * 
     * @param context the representation of the request
     * 
     * @return the result of evaluation
     */
    public AbstractResult evaluate(EvaluationCtx context) {
        // if there is no finder, then we return NotApplicable
        if (finder == null){
            //return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_NOT_APPLICABLE, context);
        }

        PolicyFinderResult pfr = finder.findPolicy(reference, policyType, constraints,
                parentMetaData);

        // if we found nothing, then we return NotApplicable
        if (pfr.notApplicable()){
            //return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_NOT_APPLICABLE, context);
        }
        // if there was an error, we return that status data
        if (pfr.indeterminate()){
//            return new Result(Result.DECISION_INDETERMINATE, pfr.getStatus(), context
//                    .getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_INDETERMINATE, pfr.getStatus(), context);
        }
        // we must have found a policy
        return pfr.getPolicy().evaluate(context);
    }
 
Example 3
Source File: PDP.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * A private helper routine that resolves a policy for the given context, and then tries to
 * evaluate based on the policy
 *
 * @param context context
 * @return a response
 */
private AbstractResult evaluateContext(EvaluationCtx context) {
    // first off, try to find a policy
    PolicyFinderResult finderResult = policyFinder.findPolicy(context);

    // see if there weren't any applicable policies
    if (finderResult.notApplicable()) {
        return ResultFactory.getFactory().getResult(AbstractResult.DECISION_NOT_APPLICABLE, context);
    }
    // see if there were any errors in trying to get a policy
    if (finderResult.indeterminate()) {
        return ResultFactory.getFactory().getResult(AbstractResult.DECISION_INDETERMINATE,
                finderResult.getStatus(), context);
    }

    // we found a valid policy,

    // list all found policies if XACML 3.0
    if (context instanceof XACML3EvaluationCtx && ((RequestCtx) context.getRequestCtx()).
            isReturnPolicyIdList()) {
        Set<PolicyReference> references = new HashSet<PolicyReference>();
        processPolicyReferences(finderResult.getPolicy(), references);
        ((XACML3EvaluationCtx) context).setPolicyReferences(references);
    }

    // so we can do the evaluation
    return finderResult.getPolicy().evaluate(context);
}