You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Wolfgang Schmiesing <wo...@trustcenter.de> on 2011/05/11 13:37:11 UTC
Namespace definition in XMLObject
Hi,
I'm currently using the "javax.xml.crypto.dsig" API to create a
signature. Now, is there any way of assigning a namespace definition to
an <Object> element inside the signature? The output I need should look
similar to this:
<Signature>
...
<Object xmlns:test="http://www.example.org/ns" Id="someId">
<test:someElem />
<test:someElem />
</Object>
</Signature>
I'm currently creating the <Object> element using the following call:
> XMLSignatureFactory.newXMLObject( List content, String id, String
> mimeType, String encoding );
This returns a javax.xml.crypto.dsig.XMLObject. Unfortunately, I can't
find a way of assigning a namespace in "XMLObject".
I managed to create an <Object> element with a namespace using
"org.apache.xml.security.signature.ObjectContainer" but
am currently not able to switch to XMLSecurity APIs. Is this the only
way to do it or am I missing something?
Kind regards,
Wolfgang
Re: Namespace definition in XMLObject
Posted by Sean Mullan <se...@oracle.com>.
This issue has been fixed and will be released in the 1.5 version.
See: https://issues.apache.org/jira/browse/SANTUARIO-283 for more info.
--Sean
On 5/16/11 3:42 PM, Sean Mullan wrote:
> On 5/13/11 9:52 AM, Wolfgang Schmiesing wrote:
>> Thanks for the quick reply,
>>
>> I followed your advice and tried using an XML template and unmarshalling it using
>>
>>> XMLSignatureFactory.getInstance().unmarshalXMLSignature(domTemplate);
>>
>> My input is as follows:
>>
>> ...
>>> <Object Id="sample" xmlns:test="http://test.net/ns/xmldsig">
>>> <test:Simple ATT="1" />
>>> <test:Simple ATT="2" />
>>> </Object>
>> ...
>>
>> The output looks like this after signing:
>>
>> ...
>>> <Object Id="sample">
>>> <test:Simple ATT="1" xmlns:test="http://test.net/ns/xmldsig" />
>>> <test:Simple ATT="2" xmlns:test="http://test.net/ns/xmldsig" />
>>> </Object>
>> ...
>>
>> Any ideas why the namespace is pushed down into the child elements after signing?
>> In the output document I'd like to have the namespace declared only once.
>
> I looked at the code. It's a bug. It doesn't retain the xmlns attributes on the
> Object element when it unmarshals it, however the child elements do retain that
> so that is why they end up getting redeclared on the child elements.
> Unfortunately I can't think of any workaround.
>
> Please file a bug.
>
> Thanks,
> Sean
>
>
>>
>> Kind regards,
>>
>> Wolfgang
>>
>> On 11.05.2011 14:57, Sean Mullan wrote:
>>> On 5/11/11 7:37 AM, Wolfgang Schmiesing wrote:
>>>> Hi,
>>>>
>>>> I'm currently using the "javax.xml.crypto.dsig" API to create a signature. Now,
>>>> is there any way of assigning a namespace definition to
>>>> an<Object> element inside the signature? The output I need should look similar
>>>> to this:
>>>>
>>>> <Signature>
>>>> ...
>>>> <Object xmlns:test="http://www.example.org/ns" Id="someId">
>>>> <test:someElem />
>>>> <test:someElem />
>>>> </Object>
>>>> </Signature>
>>>>
>>>> I'm currently creating the<Object> element using the following call:
>>>>
>>>>> XMLSignatureFactory.newXMLObject( List content, String id, String mimeType,
>>>>> String encoding );
>>>> This returns a javax.xml.crypto.dsig.XMLObject. Unfortunately, I can't find a
>>>> way of assigning a namespace in "XMLObject".
>>>>
>>>> I managed to create an<Object> element with a namespace using
>>>> "org.apache.xml.security.signature.ObjectContainer" but
>>>> am currently not able to switch to XMLSecurity APIs. Is this the only way to do
>>>> it or am I missing something?
>>> No, I don't think so. It is a limitation in the API. You can add the namespace
>>> declarations to the test elements by creating Elements and wrapping them in
>>> DOMStructures. But in order to add them to the Object element you will need to
>>> access the underlying DOM and add them using DOM APIs.
>>>
>>> Another alternative is to use an XML template of an XML Signature where all of
>>> the namespace declarations are already in place. That is you unmarshal an
>>> XMLSignature object from XML (with empty or bogus DigestValue and SignatureValue
>>> elements) using XMLSignatureFactory.unmarshal and then sign it using
>>> XMLSignature.sign.
>>>
>>> --Sean
>>>
>>>
>>>>
>>>>
>>>> Kind regards,
>>>>
>>>> Wolfgang
>>>>
>>
>>
Re: Namespace definition in XMLObject
Posted by Sean Mullan <se...@oracle.com>.
On 5/13/11 9:52 AM, Wolfgang Schmiesing wrote:
> Thanks for the quick reply,
>
> I followed your advice and tried using an XML template and unmarshalling it using
>
>> XMLSignatureFactory.getInstance().unmarshalXMLSignature(domTemplate);
>
> My input is as follows:
>
> ...
>> <Object Id="sample" xmlns:test="http://test.net/ns/xmldsig">
>> <test:Simple ATT="1" />
>> <test:Simple ATT="2" />
>> </Object>
> ...
>
> The output looks like this after signing:
>
> ...
>> <Object Id="sample">
>> <test:Simple ATT="1" xmlns:test="http://test.net/ns/xmldsig" />
>> <test:Simple ATT="2" xmlns:test="http://test.net/ns/xmldsig" />
>> </Object>
> ...
>
> Any ideas why the namespace is pushed down into the child elements after signing?
> In the output document I'd like to have the namespace declared only once.
I looked at the code. It's a bug. It doesn't retain the xmlns attributes on the
Object element when it unmarshals it, however the child elements do retain that
so that is why they end up getting redeclared on the child elements.
Unfortunately I can't think of any workaround.
Please file a bug.
Thanks,
Sean
>
> Kind regards,
>
> Wolfgang
>
> On 11.05.2011 14:57, Sean Mullan wrote:
>> On 5/11/11 7:37 AM, Wolfgang Schmiesing wrote:
>>> Hi,
>>>
>>> I'm currently using the "javax.xml.crypto.dsig" API to create a signature. Now,
>>> is there any way of assigning a namespace definition to
>>> an<Object> element inside the signature? The output I need should look similar
>>> to this:
>>>
>>> <Signature>
>>> ...
>>> <Object xmlns:test="http://www.example.org/ns" Id="someId">
>>> <test:someElem />
>>> <test:someElem />
>>> </Object>
>>> </Signature>
>>>
>>> I'm currently creating the<Object> element using the following call:
>>>
>>>> XMLSignatureFactory.newXMLObject( List content, String id, String mimeType,
>>>> String encoding );
>>> This returns a javax.xml.crypto.dsig.XMLObject. Unfortunately, I can't find a
>>> way of assigning a namespace in "XMLObject".
>>>
>>> I managed to create an<Object> element with a namespace using
>>> "org.apache.xml.security.signature.ObjectContainer" but
>>> am currently not able to switch to XMLSecurity APIs. Is this the only way to do
>>> it or am I missing something?
>> No, I don't think so. It is a limitation in the API. You can add the namespace
>> declarations to the test elements by creating Elements and wrapping them in
>> DOMStructures. But in order to add them to the Object element you will need to
>> access the underlying DOM and add them using DOM APIs.
>>
>> Another alternative is to use an XML template of an XML Signature where all of
>> the namespace declarations are already in place. That is you unmarshal an
>> XMLSignature object from XML (with empty or bogus DigestValue and SignatureValue
>> elements) using XMLSignatureFactory.unmarshal and then sign it using
>> XMLSignature.sign.
>>
>> --Sean
>>
>>
>>>
>>>
>>> Kind regards,
>>>
>>> Wolfgang
>>>
>
>
Re: Namespace definition in XMLObject
Posted by Wolfgang Schmiesing <wo...@trustcenter.de>.
Thanks for the quick reply,
I followed your advice and tried using an XML template and unmarshalling
it using
> XMLSignatureFactory.getInstance().unmarshalXMLSignature(domTemplate);
My input is as follows:
...
> <Object Id="sample" xmlns:test="http://test.net/ns/xmldsig">
> <test:Simple ATT="1" />
> <test:Simple ATT="2" />
> </Object>
...
The output looks like this after signing:
...
> <Object Id="sample">
> <test:Simple ATT="1" xmlns:test="http://test.net/ns/xmldsig" />
> <test:Simple ATT="2" xmlns:test="http://test.net/ns/xmldsig" />
> </Object>
...
Any ideas why the namespace is pushed down into the child elements after
signing?
In the output document I'd like to have the namespace declared only once.
Kind regards,
Wolfgang
On 11.05.2011 14:57, Sean Mullan wrote:
> On 5/11/11 7:37 AM, Wolfgang Schmiesing wrote:
>> Hi,
>>
>> I'm currently using the "javax.xml.crypto.dsig" API to create a signature. Now,
>> is there any way of assigning a namespace definition to
>> an<Object> element inside the signature? The output I need should look similar
>> to this:
>>
>> <Signature>
>> ...
>> <Object xmlns:test="http://www.example.org/ns" Id="someId">
>> <test:someElem />
>> <test:someElem />
>> </Object>
>> </Signature>
>>
>> I'm currently creating the<Object> element using the following call:
>>
>>> XMLSignatureFactory.newXMLObject( List content, String id, String mimeType,
>>> String encoding );
>> This returns a javax.xml.crypto.dsig.XMLObject. Unfortunately, I can't find a
>> way of assigning a namespace in "XMLObject".
>>
>> I managed to create an<Object> element with a namespace using
>> "org.apache.xml.security.signature.ObjectContainer" but
>> am currently not able to switch to XMLSecurity APIs. Is this the only way to do
>> it or am I missing something?
> No, I don't think so. It is a limitation in the API. You can add the namespace
> declarations to the test elements by creating Elements and wrapping them in
> DOMStructures. But in order to add them to the Object element you will need to
> access the underlying DOM and add them using DOM APIs.
>
> Another alternative is to use an XML template of an XML Signature where all of
> the namespace declarations are already in place. That is you unmarshal an
> XMLSignature object from XML (with empty or bogus DigestValue and SignatureValue
> elements) using XMLSignatureFactory.unmarshal and then sign it using
> XMLSignature.sign.
>
> --Sean
>
>
>>
>>
>> Kind regards,
>>
>> Wolfgang
>>
--
--
Wolfgang Schmiesing
Software Development
TC TrustCenter GmbH – Now part of Symantec
Sonninstrasse 24 - 28
20097 Hamburg
Germany
Office: +49-(0)40-808026-353, Fax: -126
E-mail wolfgang.schmiesing@trustcenter.de
www.trustcenter.de
Geschaeftsfuehrung/Managing Directors:
Austin McCabe, Kristen Laubscher
AG Hamburg, HRB 96168
----------------
This email may contain confidential and privileged material for the sole use of the intended recipient.
Any review or distribution by others is strictly prohibited.
If you are not the intended recipient please contact the sender and delete all copies.
Re: Namespace definition in XMLObject
Posted by Sean Mullan <se...@oracle.com>.
On 5/11/11 7:37 AM, Wolfgang Schmiesing wrote:
> Hi,
>
> I'm currently using the "javax.xml.crypto.dsig" API to create a signature. Now,
> is there any way of assigning a namespace definition to
> an <Object> element inside the signature? The output I need should look similar
> to this:
>
> <Signature>
> ...
> <Object xmlns:test="http://www.example.org/ns" Id="someId">
> <test:someElem />
> <test:someElem />
> </Object>
> </Signature>
>
> I'm currently creating the <Object> element using the following call:
>
>> XMLSignatureFactory.newXMLObject( List content, String id, String mimeType,
>> String encoding );
>
> This returns a javax.xml.crypto.dsig.XMLObject. Unfortunately, I can't find a
> way of assigning a namespace in "XMLObject".
>
> I managed to create an <Object> element with a namespace using
> "org.apache.xml.security.signature.ObjectContainer" but
> am currently not able to switch to XMLSecurity APIs. Is this the only way to do
> it or am I missing something?
No, I don't think so. It is a limitation in the API. You can add the namespace
declarations to the test elements by creating Elements and wrapping them in
DOMStructures. But in order to add them to the Object element you will need to
access the underlying DOM and add them using DOM APIs.
Another alternative is to use an XML template of an XML Signature where all of
the namespace declarations are already in place. That is you unmarshal an
XMLSignature object from XML (with empty or bogus DigestValue and SignatureValue
elements) using XMLSignatureFactory.unmarshal and then sign it using
XMLSignature.sign.
--Sean
>
>
>
> Kind regards,
>
> Wolfgang
>