Skip to main content

Extending JSR 105 to support more URI reference types

Posted by mullan on June 28, 2006 at 10:24 AM PDT

In XML Signatures, Reference elements use URIs to describe the data that is to be digested and signed. Adding support for your own URI dereferencing implementation is pretty straightforward in JSR 105. First you need to create a concrete implementation of the javax.xml.crypto.URIDereferencer interface, ex:

public class MyURIDereferencer implements URIDereferencer {

There is only one method in URIDereferencer that you need to provide an implementation for: the dereference method:

Data dereference(URIReference uriReference,
XMLCryptoContext context)
throws URIReferenceException

This method takes a URIReference object describing the URI to be dereferenced and an XMLCryptoContext object that may contain additional information (such as the base URI) that is helpful in dereferencing the URI. The method returns a Data object containing the dereferenced data. The API defines two subclasses of Data: OctetStreamData for holding byte streams, and NodeSetData for holding node-sets.

Once you have implemented your URIDereferencer, it can be set as the default URIDereferencer by invoking the XMLCryptoContext.setURIDereferencer method (which takes a URIDereferencer argument), ex:

context.setURIDereferencer(new MyURIDereferencer());

Does this mean MyURIDereferencer is responsible for dereferencing all URI types? Yes. But what if I want to continue to use the built-in support and only add support for new types? Well you can do that too. In your URIDereferencer implementation, you should add some code to fallback to the built-in URIDereferencer for URI types that you do not support. You can do this by calling the XMLSignatureFactory.getURIDereferencer method which returns a reference to the XMLSignatureFactory's built-in implementation of URIDereferencer.

You can get the reference implementation of JSR 105 from the Java Web Service Developer's Pack v2.0, the beta 2 release or latest snapshot of JDK 6 (Mustang), or GlassFish.

Related Topics >>