Search in sources :

Example 6 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class SubjectImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("SubjectImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("SubjectImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.SUBJECT)) {
        XACMLSDKUtils.debug.error("SubjectImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes >= 1) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int nextElem = 0; nextElem < numOfNodes; nextElem++) {
            Node child = (Node) nodes.item(nextElem);
            if ((child.getNodeType() == Node.ELEMENT_NODE) || (child.getNodeType() == Node.ATTRIBUTE_NODE)) {
                // The child nodes should be <Attribute> 
                // or <SubjectCategory>
                String attrChildName = child.getLocalName();
                if (attrChildName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (this.attributes == null) {
                        this.attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else if (attrChildName.equals(XACMLConstants.SUBJECT_CATEGORY)) {
                    try {
                        subjectCategory = new URI(child.getNodeValue());
                    } catch (Exception e) {
                        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
                    }
                } else {
                    XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): Invalid element :" + attrChildName);
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
                }
            }
        }
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) URI(java.net.URI) XACMLException(com.sun.identity.xacml.common.XACMLException) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 7 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class ActionImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("ActionImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("ActionImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.ACTION)) {
        XACMLSDKUtils.debug.error("ActionImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes >= 1) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int nextElem = 0; nextElem < numOfNodes; nextElem++) {
            Node child = (Node) nodes.item(nextElem);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                // The child nodes should be <Attribute>
                String attrChildName = child.getLocalName();
                if (attrChildName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (this.attributes == null) {
                        this.attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else {
                    XACMLSDKUtils.debug.error("ActionImpl." + "processElement(): Invalid element :" + attrChildName);
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
                }
            }
        }
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Aggregations

ContextFactory (com.sun.identity.xacml.context.ContextFactory)7 XACMLException (com.sun.identity.xacml.common.XACMLException)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Attribute (com.sun.identity.xacml.context.Attribute)5 ArrayList (java.util.ArrayList)5 Element (org.w3c.dom.Element)3 Resource (com.sun.identity.xacml.context.Resource)1 Subject (com.sun.identity.xacml.context.Subject)1 URI (java.net.URI)1 ParseException (java.text.ParseException)1 List (java.util.List)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1