mace-opensaml-users - Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace
Subject: OpenSAML user discussion
List archive
- From: Brent Putman <>
- To:
- Subject: Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace
- Date: Wed, 03 Dec 2008 20:00:47 -0500
I'm not sure I 100% understand what you want to do. But if the
fundamental question is how to use AttributeValues which are
non-namespace-qualified XML: I don't think this is really going to work
at all.
The reason is more fundamental than OpenSAML. We rely under the covers
on the DOM API. In the DOM, as far as I know, trying to mix
namespace-qualified and non-namespace-qualified XML is a non-starter.
You just can't do it, especially if you going to anything non-trivial
like XML signature and the like.
SAML is of course namespace-qualified. So trying to use SAML data
structures via the DOM API is mutually exclusive with
non-namespace-qualified content. If someone else knows otherwise,
please correct me.
Namespace-qualified XML values for AttributeValues are supported just
fine, however. So my suggestion would be to just use
namespace-qualified data, declare the default namespace on the root
element of each subtree and use that default namespace on those elements
to eliminate the namespace prefix. Then, the non-namespace-aware code
that is apparently consuming the AttributeValue data can just ignore the
xmlns attribute on the element. That's probably the closest you can get
to what you want.
--Brent
Stepan Hrbacek wrote:
> Hi,
>
> I use OpenSAML 2.2.2 for creating SAML 1.1/2.0 assertions with attribute
> statements containing complex attribute values (XML elements). Recently I
> have experienced issue marshalling attribute values containing XML elements
> without namespace (but valid XML data).
>
> Following test shows it:
> =================
> public void testMarshallWithoutNamespaceUseXSAnyUnmarshallerSaml1()
> throws ParsingException, SAXException, IOException,
> ParserConfigurationException, MarshallingException, ConfigurationException,
> UnmarshallingException {
> org.opensaml.DefaultBootstrap.bootstrap();
>
> javax.xml.parsers.DocumentBuilderFactory docBldrFact =
> javax.xml.parsers.DocumentBuilderFactory.newInstance();
> docBldrFact.setNamespaceAware(true);
> org.w3c.dom.Element valueElem =
> docBldrFact.newDocumentBuilder().parse(new org.xml.sax.InputSource(new
> java.io.StringReader("<value/>"))).getDocumentElement();
>
> org.opensaml.xml.io.Unmarshaller unmarshaller = new
> org.opensaml.xml.schema.impl.XSAnyUnmarshaller();
> org.opensaml.xml.XMLObject valueXmlObj =
> unmarshaller.unmarshall(valueElem);
>
> org.opensaml.xml.XMLObjectBuilder xmlObjectBilder = new
> org.opensaml.xml.schema.impl.XSAnyBuilder();
> org.opensaml.xml.ElementExtensibleXMLObject attrValueXmlObj =
> (org.opensaml.xml.ElementExtensibleXMLObject)
> xmlObjectBilder.buildObject(org.opensaml.saml1.core.AttributeValue.DEFAULT_ELEMENT_NAME);
>
> attrValueXmlObj.getUnknownXMLObjects().add(valueXmlObj);
>
> org.opensaml.saml1.core.Attribute attrXmlObj =
> ((org.opensaml.saml1.core.impl.AttributeBuilder)
> org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(
>
> org.opensaml.saml1.core.Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
>
> attrXmlObj.setAttributeName("aaa");
> attrXmlObj.setAttributeNamespace("bbb");
> attrXmlObj.getAttributeValues().add(attrValueXmlObj);
>
> org.opensaml.xml.io.Marshaller marshaller =
> org.opensaml.xml.Configuration.getMarshallerFactory().getMarshaller(attrXmlObj.getElementQName());
>
> org.w3c.dom.Element domObj = marshaller.marshall(attrXmlObj);
> }
>
> During an execution of this test I get following exception:
> =========================================
> org.opensaml.xml.io.MarshallingException: Unable to root namespaces of
> cached DOM element, value
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.prepareForAdoption(AbstractXMLObjectMarshaller.java:446)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshall(AbstractXMLObjectMarshaller.java:157)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshallChildElements(AbstractXMLObjectMarshaller.java:316)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshallInto(AbstractXMLObjectMarshaller.java:224)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshall(AbstractXMLObjectMarshaller.java:175)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshallChildElements(AbstractXMLObjectMarshaller.java:316)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshallInto(AbstractXMLObjectMarshaller.java:224)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshall(AbstractXMLObjectMarshaller.java:130)
>
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshall(AbstractXMLObjectMarshaller.java:86)
>
> at A.testMarshallWithoutNamespaceUseXSAnyUnmarshallerSaml1(A.java:134)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
>
> Caused by: org.opensaml.xml.parse.XMLParserException: Unable to resolve
> namespace prefix null found on element value
> at org.opensaml.xml.util.XMLHelper.rootNamespaces(XMLHelper.java:897)
> at org.opensaml.xml.util.XMLHelper.rootNamespaces(XMLHelper.java:870)
> at
> org.opensaml.xml.io.AbstractXMLObjectMarshaller.prepareForAdoption(AbstractXMLObjectMarshaller.java:441)
>
> ... 27 more
>
> First I have reported this as a bug
> https://bugs.internet2.edu/jira/browse/JXT-42, but this was closed as
> invalid because the way I use to create the complex attribute value is not
> supported by OpenSAML / XmlTooling.
>
> Could you please give me a hint how to perform the above stated use case in
> a supported way and without marshalling issues?
>
> Thank you
> Stepan
>
>
- Issues marshalling XmlObject with DOM without namespace, Stepan Hrbacek, 12/01/2008
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Brent Putman, 12/03/2008
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Stepan Hrbacek, 12/04/2008
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Chad La Joie, 12/04/2008
- RE: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Scott Cantor, 12/04/2008
- Message not available
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Stepan Hrbacek, 12/04/2008
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Stepan Hrbacek, 12/04/2008
- Re: [OpenSAML] Issues marshalling XmlObject with DOM without namespace, Brent Putman, 12/03/2008
Archive powered by MHonArc 2.6.16.