Package com.sun.xacml.cond

Examples of com.sun.xacml.cond.EvaluationResult


    }

    public EvaluationResult evaluate(List<? extends Expression> inputs, EvaluationCtx context) {

        AttributeValue[] argValues = new AttributeValue[inputs.size()];
        EvaluationResult result = evalArgs(inputs, context, argValues);
        if (result != null)
            return result;

        GeometryAttribute geomAttr = (GeometryAttribute) (argValues[0]);

        double length = 0;

        try {
            length = geomAttr.getGeometry().getLength();
        } catch (Throwable t) {
            return exceptionError(t);
        }

        return new EvaluationResult(new DoubleAttribute(length));
    }
View Full Code Here


            // see if the module supports this type
            Set<Integer> types = module.getSupportedDesignatorTypes();
            if ((types == null) || (types.contains(new Integer(designatorType)))) {
                // see if the module can find an attribute value
                EvaluationResult result = module.findAttribute(attributeType, attributeId, issuer,
                        subjectCategory, context, designatorType);

                // if there was an error, we stop right away
                if (result.indeterminate()) {
                    if (logger.isLoggable(Level.INFO))
                        logger.info("Error while trying to resolve values: "
                                + result.getStatus().getMessage());
                    return result;
                }

                // if the result wasn't empty, then return the result
                BagAttribute bag = (BagAttribute) (result.getAttributeValue());
                if (!bag.isEmpty())
                    return result;
            }
        }

        // if we got here then there were no errors but there were also no
        // matches, so we have to return an empty bag
        if (logger.isLoggable(Level.FINE))
            logger.fine("Failed to resolve any values for " + attributeId.toString());

        return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
    }
View Full Code Here

    public EvaluationResult findAttribute(String contextPath, Node namespaceNode,
            URI attributeType, EvaluationCtx context, String xpathVersion) {

        for (AttributeFinderModule module : selectorModules) {
            // see if the module can find an attribute value
            EvaluationResult result = module.findAttribute(contextPath, namespaceNode,
                    attributeType, context, xpathVersion);

            // if there was an error, we stop right away
            if (result.indeterminate()) {
                if (logger.isLoggable(Level.INFO))
                    logger.info("Error while trying to resolve values: "
                            + result.getStatus().getMessage());
                return result;
            }

            // if the result wasn't empty, then return the result
            BagAttribute bag = (BagAttribute) (result.getAttributeValue());
            if (!bag.isEmpty())
                return result;
        }

        // if we got here then there were no errors but there were also no
        // matches, so we have to return an empty bag
        if (logger.isLoggable(Level.FINE))
            logger.fine("Failed to resolve any values for " + contextPath);

        return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
    }
View Full Code Here

    }

    public EvaluationResult evaluate(List<? extends Expression> inputs, EvaluationCtx context) {

        AttributeValue[] argValues = new AttributeValue[inputs.size()];
        EvaluationResult result = evalArgs(inputs, context, argValues);
        if (result != null)
            return result;

        GeometryAttribute geomAttr = (GeometryAttribute) (argValues[0]);
View Full Code Here

    }

    public EvaluationResult evaluate(List<? extends Expression> inputs, EvaluationCtx context) {

        AttributeValue[] argValues = new AttributeValue[inputs.size()];
        EvaluationResult result = evalArgs(inputs, context, argValues);
        if (result != null)
            return result;

        DoubleAttribute value = (DoubleAttribute) (argValues[0]);
        StringAttribute unit = (StringAttribute) (argValues[1]);

        Double multiplyBy = UnitToSquareMetre.get(unit.getValue());
        if (multiplyBy == null) {
            exceptionError(new Exception("Unit" + unit + " not supported"));
        }
        double resultValue = value.getValue() * multiplyBy;

        return new EvaluationResult(new DoubleAttribute(resultValue));
    }
View Full Code Here

    }

    public EvaluationResult evaluate(List<? extends Expression> inputs, EvaluationCtx context) {

        AttributeValue[] argValues = new AttributeValue[inputs.size()];
        EvaluationResult result = evalArgs(inputs, context, argValues);
        if (result != null)
            return result;

        GeometryAttribute geomAttr = (GeometryAttribute) (argValues[0]);

        Geometry resultGeom = null;

        try {
            resultGeom = geomAttr.getGeometry().getCentroid();
        } catch (Throwable t) {
            return exceptionError(t);
        }

        GeometryAttribute resultAttr = null;

        try {
            resultAttr = new GeometryAttribute(resultGeom, geomAttr.getSrsName(), null, null, null);
        } catch (URISyntaxException e) {
            // should not happend
        }
        return new EvaluationResult(resultAttr);

    }
View Full Code Here

     */
    public EvaluationResult findAttribute(URI attributeType, URI attributeId, URI issuer,
            URI subjectCategory, EvaluationCtx context, int designatorType) {
        // make sure this is the identifier we support
        if (!attributeId.toString().equals(ROLE_IDENTIFIER))
            return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));

        // make sure we've been asked for a string
        if (!attributeType.toString().equals(StringAttribute.identifier))
            return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));

        // retrieve the subject identifer from the context
        EvaluationResult result = context.getSubjectAttribute(attributeType, subjectIdentifier,
                issuer, subjectCategory);
        if (result.indeterminate())
            return result;

        // check that we succeeded in getting the subject identifier
        BagAttribute bag = (BagAttribute) (result.getAttributeValue());
        if (bag.isEmpty()) {
            ArrayList<String> code = new ArrayList<String>();
            code.add(Status.STATUS_MISSING_ATTRIBUTE);
            Status status = new Status(code, "missing subject-id");
            return new EvaluationResult(status);
        }

        // finally, look for the subject who has the role-mapping defined,
        // and if they're the identified subject, add their role
        BagAttribute returnBag = null;
        Iterator<AttributeValue> it = bag.iterator();
        while (it.hasNext()) {
            StringAttribute attr = (StringAttribute) (it.next());
            if (attr.getValue().equals("Julius Hibbert")) {
                Set<AttributeValue> set = new HashSet<AttributeValue>();
                set.add(new StringAttribute("Physician"));
                returnBag = new BagAttribute(attributeType, set);
                break;
            }
        }

        return new EvaluationResult(returnBag);
    }
View Full Code Here

     * Private helper to create a new processing error status result
     */
    private EvaluationResult createProcessingError(String msg) {
        ArrayList<String> code = new ArrayList<String>();
        code.add(Status.STATUS_PROCESSING_ERROR);
        return new EvaluationResult(new Status(code, msg));
    }
View Full Code Here

     */
    public EvaluationResult findAttribute(String path, Node namespaceNode, URI type,
            EvaluationCtx context, String xpathVersion) {
        // we only support 1.0
        if (!xpathVersion.equals(PolicyMetaData.XPATH_1_0_IDENTIFIER))
            return new EvaluationResult(BagAttribute.createEmptyBag(type));

        // get the DOM root of the request document
        Node root = context.getRequestRoot();

        // if we were provided with a non-null namespace node, then use it
        // to resolve namespaces, otherwise use the context root node
        Node nsNode = (namespaceNode != null) ? namespaceNode : root;

        // setup the root path (pre-pended to the context path), which...
        String rootPath = "";

        // ...only has content if the context path is relative
        if (path.charAt(0) != '/') {
            String rootName = root.getLocalName();

            // see if the request root is in a namespace
            String namespace = root.getNamespaceURI();

            if (namespace == null) {
                // no namespacing, so we're done
                rootPath = "/" + rootName + "/";
            } else {
                // namespaces are used, so we need to lookup the correct
                // prefix to use in the search string
                NamedNodeMap nmap = namespaceNode.getAttributes();
                rootPath = null;

                for (int i = 0; i < nmap.getLength(); i++) {
                    Node n = nmap.item(i);
                    if (n.getNodeValue().equals(namespace)) {
                        // we found the matching namespace, so get the prefix
                        // and then break out
                        String name = n.getNodeName();
                        int pos = name.indexOf(':');

                        if (pos == -1) {
                            // the namespace was the default namespace
                            rootPath = "/";
                        } else {
                            // we found a prefixed namespace
                            rootPath = "/" + name.substring(pos + 1);
                        }

                        // finish off the string
                        rootPath += ":" + rootName + "/";

                        break;
                    }
                }

                // if the rootPath is still null, then we don't have any
                // definitions for the namespace
                if (rootPath == null)
                    return createProcessingError("Failed to map a namespace"
                            + " in an XPath expression");
            }
        }

        // now do the query, pre-pending the root path to the context path
        NodeList matches = null;
        try {
            // NOTE: see comments in XALAN docs about why this is slow
            matches = XPathAPI.selectNodeList(root, rootPath + path, nsNode);
        } catch (Exception e) {
            // in the case of any exception, we need to return an error
            return createProcessingError("error in XPath: " + e.getMessage());
        }

        if (matches.getLength() == 0) {
            // we didn't find anything, so we return an empty bag
            return new EvaluationResult(BagAttribute.createEmptyBag(type));
        }

        // there was at least one match, so try to generate the values
        try {
            ArrayList<AttributeValue> list = new ArrayList<AttributeValue>();
            AttributeFactory attrFactory = AttributeFactory.getInstance();

            for (int i = 0; i < matches.getLength(); i++) {
                String text = null;
                Node node = matches.item(i);
                short nodeType = node.getNodeType();

                // see if this is straight text, or a node with data under
                // it and then get the values accordingly
                if ((nodeType == Node.CDATA_SECTION_NODE) || (nodeType == Node.COMMENT_NODE)
                        || (nodeType == Node.TEXT_NODE) || (nodeType == Node.ATTRIBUTE_NODE)) {
                    // there is no child to this node
                    text = node.getNodeValue();
                } else {
                    // the data is in a child node
                    text = node.getFirstChild().getNodeValue();
                }

                list.add(attrFactory.createValue(type, text));
            }

            return new EvaluationResult(new BagAttribute(type, list));
        } catch (ParsingException pe) {
            return createProcessingError(pe.getMessage());
        } catch (UnknownIdentifierException uie) {
            return createProcessingError("unknown attribute type: " + type);
        }
View Full Code Here

     */
    public EvaluationResult findAttribute(URI attributeType, URI attributeId, URI issuer,
            URI subjectCategory, EvaluationCtx context, int designatorType) {
        // we only know about environment attributes
        if (designatorType != AttributeDesignator.ENVIRONMENT_TARGET)
            return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));

        // figure out which attribute we're looking for
        String attrName = attributeId.toString();

        if (attrName.equals(ENVIRONMENT_CURRENT_TIME)) {
            return handleTime(attributeType, issuer, context);
        } else if (attrName.equals(ENVIRONMENT_CURRENT_DATE)) {
            return handleDate(attributeType, issuer, context);
        } else if (attrName.equals(ENVIRONMENT_CURRENT_DATETIME)) {
            return handleDateTime(attributeType, issuer, context);
        }

        // if we got here, then it's an attribute that we don't know
        return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
    }
View Full Code Here

TOP

Related Classes of com.sun.xacml.cond.EvaluationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.