Search in sources :

Example 21 with XACMLException

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

the class AttributeImpl method processElement.

private void processElement(Element element) throws XACMLException {
    String value = null;
    if (element == null) {
        XACMLSDKUtils.debug.error("AttributeImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    // First check that we're really parsing an Attribute
    if (!element.getLocalName().equals(XACMLConstants.ATTRIBUTE)) {
        XACMLSDKUtils.debug.error("AttributeImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    NamedNodeMap attrs = element.getAttributes();
    try {
        id = new URI(attrs.getNamedItem(XACMLConstants.ATTRIBUTE_ID).getNodeValue());
    } catch (Exception e) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
    }
    if (id == null) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
    }
    try {
        type = new URI(attrs.getNamedItem(XACMLConstants.DATATYPE).getNodeValue());
    } catch (Exception e) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
    }
    if (type == null) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
    }
    try {
        Node issuerNode = attrs.getNamedItem(XACMLConstants.ISSUER);
        if (issuerNode != null)
            issuer = issuerNode.getNodeValue();
    } catch (Exception e) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_parsing_error"));
    }
    // now we get the attribute value
    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if ((node.getNodeType() == Node.ELEMENT_NODE) || (node.getNodeType() == Node.ATTRIBUTE_NODE)) {
            if (node.getLocalName().equals(XACMLConstants.ATTRIBUTE_VALUE)) {
                if (values == null) {
                    values = new ArrayList();
                }
                values.add(node);
            }
        }
    }
    // make sure we got a value
    if (values == null || values.isEmpty()) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute_value"));
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) URI(java.net.URI) XACMLException(com.sun.identity.xacml.common.XACMLException) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 22 with XACMLException

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

the class AttributeImpl method setAttributeStringValues.

/**
     * Sets the attribute values for this object
     *
     * @param stringValues a <code>List</code> containing
     *        <code>String<code> values of this object.
     * @throws XACMLException if the object is immutable
     *         An object is considered <code>immutable</code> if <code>
     *         makeImmutable()</code> has been invoked on it. It can
     *         be determined by calling <code>isMutable</code> on the object.
     */
public void setAttributeStringValues(List stringValues) throws XACMLException {
    if (!isMutable) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("objectImmutable"));
    }
    if (this.values == null) {
        this.values = new ArrayList();
    }
    if (stringValues == null || stringValues.isEmpty()) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("null_not_valid"));
    }
    for (int i = 0; i < stringValues.size(); i++) {
        String value = (String) (stringValues.get(i));
        StringBuffer sb = new StringBuffer(200);
        sb.append("<").append(XACMLConstants.ATTRIBUTE_VALUE).append(">").append(value).append("</").append(XACMLConstants.ATTRIBUTE_VALUE).append(">\n");
        Document document = XMLUtils.toDOMDocument(sb.toString(), XACMLSDKUtils.debug);
        Element element = null;
        if (document != null) {
            element = document.getDocumentElement();
        }
        if (element != null) {
            this.values.add(element);
        }
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) 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