All,

I'm trying to parse n SAML response which, among other things, has arbitrary name/value pairs which look like this:

     <saml2:Attribute Name="attribute-name">
        <saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:type="xs:string">attriute-value</saml2:AttributeValue>
      </saml2:Attribute>

I'm using Digester 3.2 and In the past I've been doing something like this:

digester.addCallMethod("..../Attribute", "setAttribute", 2, THREE_STRINGS);
digester.addCallParam("..../Attribute/AttributeValue", 0, "xsi:type");
digester.addCallParam("..../Attribute", 1, "Name");
digester.addCallParam("..../Attribute/AttributeValue", 2);

This will call my bean's setAttribute method with 3 parameters:

1. The value of the "xsi:type" attribute
2. The value of the "Name" attribute
3. The value of the CDATA child of the AttributeValue element

This worked great until someone presented me with a SAML message where the namespaces are different:

<saml:Attribute Name="attribute-name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:type="xsd:string">attribute-value</saml:AttributeValue>
      </saml:Attribute>

Note that I was expecting xsi: as the namespace prefix for the "type" attribute (which is the same), but this vendor has used "xsd:" as the namespace prefix for the XMLSchema namespace instead of "xs:" which is also common.

I couldn't determine any way to interact with direct methods on the Digester class to specify certain namespaces for things, so I decided to write my own Rule and see what I could do. I have bound this rule to "..../AttributeValue" and it currently just dumps out information:

System.out.println("Got element " + getNamespaceURI() + ":" + name + " with attrs " + attributes);
    System.out.println("attribute ns: " + namespace);
    System.out.println("Attribute count: " + attributes.getLength());

System.out.println("http://www.w3.org/2001/XMLSchema-instance:type="; + attributes.getValue("http://www.w3.org/2001/XMLSchema-instance";, "type"));

This prints:

Got element null:AttributeValue with attrs com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$AttributesProxy@55a561cf
attribute ns: urn:oasis:names:tc:SAML:2.0:assertion
Attribute count: 1
http://www.w3.org/2001/XMLSchema-instance:type=xsd:string

So it looks like I can fetch the value of the "type" parameter by using the actual namespace definition, which is great. But the value is a string which is either "xs:string" or "xsd:string" depending on who sent the SAML response.

Now the simple thing to do would be to accept either, but I'd like to do this "properly". The namespace declarations are present on the <AttributeValue> element, but the attribute "count" is only 1 for the AttributeValue element.

Is there a way to get the namespace prefix for the namespace "http://www.w3.org/2001/XMLSchema"; so I can (a) validate and (b) remove it from the "type" attribute's value? I'm hoping to end up with "string" and know that "string" is defined by the "http://www.w3.org/2001/XMLSchema"; namespace.

Thanks,
-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to