Search in sources :

Example 16 with Attribute

use of com.sun.identity.xacml.context.Attribute 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 17 with Attribute

use of com.sun.identity.xacml.context.Attribute 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

Attribute (com.sun.identity.xacml.context.Attribute)17 URI (java.net.URI)9 ArrayList (java.util.ArrayList)9 XACMLException (com.sun.identity.xacml.common.XACMLException)7 List (java.util.List)6 ContextFactory (com.sun.identity.xacml.context.ContextFactory)5 Subject (com.sun.identity.xacml.context.Subject)5 Element (org.w3c.dom.Element)5 Request (com.sun.identity.xacml.context.Request)4 Resource (com.sun.identity.xacml.context.Resource)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 SSOException (com.iplanet.sso.SSOException)3 SSOToken (com.iplanet.sso.SSOToken)3 Action (com.sun.identity.xacml.context.Action)3 Environment (com.sun.identity.xacml.context.Environment)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 Decision (com.sun.identity.xacml.context.Decision)2 Response (com.sun.identity.xacml.context.Response)2 Result (com.sun.identity.xacml.context.Result)2