Java Code Examples for org.wso2.balana.finder.ResourceFinderResult#getResources()

The following examples show how to use org.wso2.balana.finder.ResourceFinderResult#getResources() . 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: 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 2
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);

}