Search in sources :

Example 11 with XACMLException

use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.

the class RequestImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.REQUEST)) {
        XACMLSDKUtils.debug.error("RequestImpl.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) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): request has no subelements");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
    ContextFactory factory = ContextFactory.getInstance();
    List children = new ArrayList();
    int i = 0;
    Node child;
    while (i < numOfNodes) {
        child = (Node) nodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            children.add(child);
        }
        i++;
    }
    if (children.isEmpty()) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " request has no subelements");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
    child = (Node) children.get(0);
    // The first subelement should be <Subject>
    String childName = child.getLocalName();
    if ((childName == null) || (!childName.equals(XACMLConstants.SUBJECT))) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " the first element is not <Subject>");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelement_subject"));
    }
    Subject subject = factory.getInstance().createSubject((Element) child);
    if (!supportedSubjectCategory.contains(subject.getSubjectCategory().toString())) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():subject " + "category in subject not supported");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("unsupported_subject_category"));
    }
    subjects.add(subject);
    boolean resourceFound = false;
    boolean actionFound = false;
    boolean envFound = false;
    for (int j = 1; j < children.size(); j++) {
        child = (Node) children.get(j);
        // so far <Resource> is not encountered
        // Go through next sub elements for <Subject> and <Resource>
        // The next subelement may be <Resource> or <Subject>
        childName = child.getLocalName();
        if ((childName != null) && (childName.equals(XACMLConstants.RESOURCE) || childName.equals(XACMLConstants.SUBJECT))) {
            if (resourceFound) {
                if (childName.equals(XACMLConstants.SUBJECT)) {
                    // all <Subject> should be before <Resource>
                    XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Subject> should be " + "before <Resource>");
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
                } else {
                    // found another resource
                    Resource resource = factory.getInstance().createResource((Element) child);
                    resources.add(resource);
                }
            } else if (childName.equals(XACMLConstants.SUBJECT)) {
                subject = factory.getInstance().createSubject((Element) child);
                subjects.add(subject);
            } else {
                // childname is resource
                resourceFound = true;
                Resource resource = factory.getInstance().createResource((Element) child);
                resources.add(resource);
            }
        } else if ((childName != null) && (childName.equals(XACMLConstants.ACTION))) {
            if (!resourceFound) {
                XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> should be " + "before <Action>");
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
            } else {
                actionFound = true;
                action = factory.createAction((Element) child);
            }
        } else if ((childName != null) && (childName.equals(XACMLConstants.ENVIRONMENT))) {
            if (!resourceFound || !actionFound) {
                XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> and " + "Action should be before <Environment>");
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
            } else {
                envFound = true;
                env = factory.createEnvironment((Element) child);
            }
        }
    }
    if (XACMLSDKUtils.debug.messageEnabled()) {
        XACMLSDKUtils.debug.message("resourceFound:" + resourceFound);
        XACMLSDKUtils.debug.message("actionFound:" + actionFound);
        XACMLSDKUtils.debug.message("envFound:" + envFound);
    }
    if (!resourceFound || !actionFound || !envFound) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): Some" + "of required elements are missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Resource(com.sun.identity.xacml.context.Resource) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Subject(com.sun.identity.xacml.context.Subject) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 12 with XACMLException

use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.

the class ResponseImpl method processElement.

/** 
     * Initializes a <code>Response</code> object from an XML DOM element
     *
     * @param element XML DOM element representing a <code>Response</code> 
     * object
     *
     * @throws SAMLException if the DOM element could not be processed
     */
private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("ResponseImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("ResponseImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.RESPONSE)) {
        XACMLSDKUtils.debug.error("ResponseImpl.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();
    int nextElem = 0;
    while (nextElem < numOfNodes) {
        Node child = (Node) nodes.item(nextElem);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String childName = child.getLocalName();
            if (childName != null) {
                if (childName.equals(XACMLConstants.RESULT)) {
                    results.add(ContextFactory.getInstance().createResult((Element) child));
                //XMLUtils.getElementValue((Element)child));
                } else {
                    XACMLSDKUtils.debug.error("ResponseImpl.processElement(): " + " invalid child element: " + elemName);
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
                    "invalid_child_name"));
                }
            }
        }
        nextElem++;
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 13 with XACMLException

use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.

the class ResourceImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.RESOURCE)) {
        XACMLSDKUtils.debug.error("ResourceImpl.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 > 0) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int i = 0; i < numOfNodes; i++) {
            Node child = (Node) nodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                String childName = child.getLocalName();
                // <ResourceContent>
                if (childName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (attributes == null) {
                        attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else if (childName.equals(XACMLConstants.RESOURCE_CONTENT)) {
                    resourceContent = (Element) child;
                }
            }
        }
    } else {
    /* not a schema violation
             XACMLSDKUtils.debug.error(
                "ResourceImpl.processElement(): no attributes or resource "
                +"content");
            throw new XACMLException( 
                XACMLSDKUtils.xacmlResourceBundle.getString(
                "missing_subelements"));
            */
    }
}
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) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 14 with XACMLException

use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.

the class StatusCodeImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.STATUS_CODE)) {
        XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    String attrValue = element.getAttribute(XACMLConstants.VALUE);
    if ((attrValue == null) || (attrValue.length() == 0)) {
        XACMLSDKUtils.debug.error("StatusCodeImpl.processElement(): statuscode missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//i18n
        "missing_status_code"));
    }
    if (!XACMLSDKUtils.isValidStatusMessage(attrValue.trim())) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_value"));
    } else {
        this.value = attrValue;
    }
    //process child StatusCode element
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    List childElements = new ArrayList();
    int i = 0;
    while (i < numOfNodes) {
        Node child = (Node) nodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            childElements.add(child);
        }
        i++;
    }
    int childCount = childElements.size();
    if (childCount > 1) {
        XACMLSDKUtils.debug.error("ResultImpl.processElement(): invalid child element count: " + childCount);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_child_count"));
    }
    if (childCount == 1) {
        Element childElement = (Element) childElements.get(0);
        elemName = childElement.getLocalName();
        if (elemName == null) {
            XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): local name missing");
            throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
        }
        if (!elemName.equals(XACMLConstants.STATUS_CODE)) {
            XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid local name " + elemName);
            throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
        }
        attrValue = childElement.getAttribute(XACMLConstants.VALUE);
        if ((attrValue == null) || (attrValue.length() == 0)) {
            XACMLSDKUtils.debug.error("StatusCodeImpl.processElement(): minor statuscode missing");
            throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_minor_status_code"));
        }
        if (!XACMLSDKUtils.isValidStatusMessage(attrValue.trim())) {
            throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_value"));
        } else {
            this.minorCodeValue = attrValue;
        }
    } else {
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 15 with XACMLException

use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.

the class ObligationsImpl method setObligations.

/**
     * Sets the <code>Obligation</code> objects of this
     * <code>Obligations</code>
     *
     * @param obligations the <code>Obligation</code> objects to set in this
     * <code>Obligations</code>
     * @throws XACMLException if the object is immutable.
     */
public void setObligations(List obligations) throws XACMLException {
    if (!mutable) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("objectImmutable"));
    }
    if (obligations != null) {
        Iterator iter = obligations.iterator();
        this.obligations = new ArrayList();
        while (iter.hasNext()) {
            Obligation obligation = (Obligation) iter.next();
            this.obligations.add(obligation);
        }
    } else {
        obligations = null;
    }
}
Also used : Obligation(com.sun.identity.xacml.policy.Obligation) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Aggregations

XACMLException (com.sun.identity.xacml.common.XACMLException)22 ArrayList (java.util.ArrayList)18 Element (org.w3c.dom.Element)14 Node (org.w3c.dom.Node)14 NodeList (org.w3c.dom.NodeList)14 Attribute (com.sun.identity.xacml.context.Attribute)7 List (java.util.List)7 ContextFactory (com.sun.identity.xacml.context.ContextFactory)6 URI (java.net.URI)6 Resource (com.sun.identity.xacml.context.Resource)3 Result (com.sun.identity.xacml.context.Result)3 Subject (com.sun.identity.xacml.context.Subject)3 Iterator (java.util.Iterator)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 SSOException (com.iplanet.sso.SSOException)2 SSOToken (com.iplanet.sso.SSOToken)2 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 Decision (com.sun.identity.xacml.context.Decision)2 Request (com.sun.identity.xacml.context.Request)2 Response (com.sun.identity.xacml.context.Response)2