org.wso2.balana.finder.ResourceFinderResult Java Examples

The following examples show how to use org.wso2.balana.finder.ResourceFinderResult. 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: TestResourceFinderModule.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the children resources associated with the given root,
 * assuming the hierarchy is one that this module handles.
 *
 * @param root the root resource in the hierarchy
 * @param context the evaluation's context
 *
 * @return the resource hierarchy
 */
public ResourceFinderResult findChildResources(AttributeValue root,
                                               EvaluationCtx context) {
    // make sure we can handle this hierarchy
    if (! requestApplies(root))
        return new ResourceFinderResult();

    // add the root to the set of resolved resources
    HashSet set = new HashSet();
    set.add(root);

    // add the other resources, which are defined by the conformance tests
    try {
        set.add(new AnyURIAttribute(new URI("urn:root:child1")));
        set.add(new AnyURIAttribute(new URI("urn:root:child2")));
    } catch (URISyntaxException urise) {
        // this will never happen
    }

    return new ResourceFinderResult(set);
}
 
Example #2
Source File: XACML2EvaluationCtx.java    From balana with Apache License 2.0 5 votes vote down vote up
private MultipleCtxResult processHierarchicalAttributes(XACML2EvaluationCtx evaluationCtx) {

        ResourceFinderResult resourceResult = null;
        Set<EvaluationCtx> children = new HashSet<EvaluationCtx>();
        AttributeValue resourceId = evaluationCtx.getResourceId();
        int resourceScope = evaluationCtx.getResourceScope();

        if(resourceId != null){
            if(resourceScope == XACMLConstants.SCOPE_CHILDREN){
                resourceResult = evaluationCtx.getPdpConfig().getResourceFinder().
                                                findChildResources(resourceId, evaluationCtx);
            } else if(resourceScope == XACMLConstants.SCOPE_DESCENDANTS) {
                resourceResult = evaluationCtx.getPdpConfig().getResourceFinder().
                                                findDescendantResources(resourceId, evaluationCtx);
            } else {
                logger.error("Unknown scope type: " );
                //TODO
            }
        } else {
             logger.error("ResourceId Attribute is NULL: " );
            // TODO
        }

        if(resourceResult == null || resourceResult.isEmpty()){
            logger.error("Resource Finder result is NULL: " );
            // TODO
        } else {
            for (AttributeValue resource : resourceResult.getResources()) {
                evaluationCtx.setResourceId(resource, attributesSet);
                children.add(evaluationCtx);
            }
        }

        return new MultipleCtxResult(children, null, false);

    }
 
Example #3
Source File: TestResourceFinderModule.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the children resources associated with the given root,
 * assuming the hierarchy is one that this module handles.
 *
 * @param root the root resource in the hierarchy
 * @param context the evaluation's context
 *
 * @return the resource hierarchy
 */
public ResourceFinderResult findDescendantResources(AttributeValue root,
                                                    EvaluationCtx
                                                    context) {
    // make sure we can handle this hierarchy
    if (! requestApplies(root))
        return new ResourceFinderResult();

    // add the root to the set of resolved resources
    HashSet set = new HashSet();
    set.add(root);

    // add the other resources, which are defined by the conformance tests
    try {
        set.add(new AnyURIAttribute(new URI("urn:root:child1")));
        set.add(new AnyURIAttribute(new
                                    URI("urn:root:child1:descendant1")));
        set.add(new AnyURIAttribute(new
                                    URI("urn:root:child1:descendant2")));
        set.add(new AnyURIAttribute(new URI("urn:root:child2")));
        set.add(new AnyURIAttribute(new
                                    URI("urn:root:child2:descendant1")));
        set.add(new AnyURIAttribute(new
                                    URI("urn:root:child2:descendant2")));
    } catch (URISyntaxException urise) {
        // this will never happen
    }

    return new ResourceFinderResult(set);
}
 
Example #4
Source File: XACML3EvaluationCtx.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param evaluationCtx
 * @return
 */
private MultipleCtxResult processHierarchicalAttributes(XACML3EvaluationCtx evaluationCtx) {

    ResourceFinderResult resourceResult = null;
    Set<EvaluationCtx> children = new HashSet<EvaluationCtx>();

    Attribute resourceId = evaluationCtx.getResourceId();
    if(resourceId != null){

        if(evaluationCtx.getResourceScope() == XACMLConstants.SCOPE_CHILDREN){
            resourceResult = pdpConfig.getResourceFinder().
                                            findChildResources(resourceId.getValue(), evaluationCtx);
        } else if(evaluationCtx.getResourceScope()  == XACMLConstants.SCOPE_DESCENDANTS) {
            resourceResult = pdpConfig.getResourceFinder().
                                            findDescendantResources(resourceId.getValue(), evaluationCtx);
        } else {
            logger.error("Unknown scope type: " );
            //TODO
        }
    } else {
         logger.error("ResourceId Attribute is NULL: " );
        // TODO
    }

    if(resourceResult == null || resourceResult.isEmpty()){
        logger.error("Resource Finder result is NULL: " );
        // TODO
    } else {
        for (AttributeValue resource : resourceResult.getResources()) {
            Set<Attributes> newSet = new HashSet<Attributes>(evaluationCtx.getAttributesSet());
            Attributes resourceAttributes = null;
            for(Attributes attributes : newSet){
                if(XACMLConstants.RESOURCE_CATEGORY.equals(attributes.getCategory().toString())){
                    Set<Attribute> attributeSet = new HashSet<Attribute>(attributes.getAttributes());
                    attributeSet.remove(resourceScopeAttribute);
                    attributeSet.remove(resourceId);
                    try{
                        Attribute attribute = new Attribute(new URI(XACMLConstants.RESOURCE_ID),
                                resourceId.getIssuer(), null, resource, resourceId.isIncludeInResult(),
                                XACMLConstants.XACML_VERSION_3_0);
                        attributeSet.add(attribute);
                        Attributes newAttributes = new Attributes(new URI(XACMLConstants.RESOURCE_CATEGORY),
                                    (Node)attributes.getContent(), attributeSet, attributes.getId());
                        newSet.add(newAttributes);
                        resourceAttributes = attributes;
                    } catch (URISyntaxException e) {
                        //ignore
                    }
                    break;
                }
            }
            if(resourceAttributes != null){
                newSet.remove(resourceAttributes);
                children.add(new XACML3EvaluationCtx(new RequestCtx(newSet, null), pdpConfig));
            }
        }
    }

    return new MultipleCtxResult(children);

}