org.apache.xml.security.signature
Class Reference

java.lang.Object
  |
  +--org.apache.xml.security.utils.ElementProxy
        |
        +--org.apache.xml.security.utils.SignatureElementProxy
              |
              +--org.apache.xml.security.signature.Reference

public class Reference
extends SignatureElementProxy

Handles <ds:Reference> elements. This includes: Constuct a ds:Reference from an Element.

Create a new reference

 Document _doc;
 MessageDigestAlgorithm sha1 = MessageDigestAlgorithm.getInstance("http://#sha1");
 Reference ref = new Reference(new XMLSignatureInput(new FileInputStream("1.gif"),
                               "http://localhost/1.gif",
                               (Transforms) null, sha1);
 Element refElem = ref.toElement(_doc);
 

Verify a reference

 Element refElem = _doc.getElement("Reference"); // PSEUDO
 Reference ref = new Reference(refElem);
 String url = ref.getURI();
 ref.setData(new XMLSignatureInput(new FileInputStream(url)));
 if (ref.verify()) {
    System.out.println("verified");
 }
 
 <element name="Reference" type="ds:ReferenceType"/>
  <complexType name="ReferenceType">
    <sequence>
      <element ref="ds:Transforms" minOccurs="0"/>
      <element ref="ds:DigestMethod"/>
      <element ref="ds:DigestValue"/>
    </sequence>
    <attribute name="Id" type="ID" use="optional"/>
    <attribute name="URI" type="anyURI" use="optional"/>
    <attribute name="Type" type="anyURI" use="optional"/>
  </complexType>
 

Author:
Christian Geuer-Pollmann
See Also:
ObjectContainer, Manifest

Field Summary
static boolean CacheSignedNodes
          Field CacheSignedNodes
static java.lang.String MANIFEST_URI
          Field MANIFEST_URI
static java.lang.String OBJECT_URI
          Field OBJECT_URI
 
Fields inherited from class org.apache.xml.security.utils.ElementProxy
_baseURI, _constructionElement, _doc, _state, MODE_CREATE, MODE_DECRYPT, MODE_ENCRYPT, MODE_PROCESS, MODE_SIGN, MODE_UNKNOWN, MODE_VERIFY
 
Constructor Summary
protected Reference(org.w3c.dom.Document doc, java.lang.String BaseURI, java.lang.String ReferenceURI, Manifest manifest)
          Constructor Reference
protected Reference(org.w3c.dom.Document doc, java.lang.String BaseURI, java.lang.String ReferenceURI, Manifest manifest, java.lang.String messageDigestAlgorithm)
          Constructor Reference
protected Reference(org.w3c.dom.Document doc, java.lang.String BaseURI, java.lang.String ReferenceURI, Manifest manifest, Transforms transforms)
          Constructor Reference
protected Reference(org.w3c.dom.Document doc, java.lang.String BaseURI, java.lang.String ReferenceURI, Manifest manifest, Transforms transforms, java.lang.String messageDigestAlgorithm)
          Constructor Reference
protected Reference(org.w3c.dom.Element element, java.lang.String BaseURI, Manifest manifest)
          Build a Reference from an Element
 
Method Summary
protected  void dereferenceURIandPerformTransforms()
          This method returns the XMLSignatureInput which is referenced by the URI Attribute.
 void generateDigestValue()
          Method generateDigestValue
 java.lang.String getBaseLocalName()
          Method getBaseLocalName
 XMLSignatureInput getContentsAfterTransformation()
          Returns the XMLSignatureInput which is the result of the Transforms.
 XMLSignatureInput getContentsBeforeTransformation()
          Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
 java.lang.String getHTMLRepresentation()
          Method getHTMLRepresentation
 java.lang.String getId()
          Returns the Id attribute of this Reference element
 MessageDigestAlgorithm getMessageDigestAlgorithm()
          Returns MessageDigestAlgorithm
 XMLSignatureInput getNodesetBeforeFirstCanonicalization()
          This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.
 byte[] getReferencedBytes()
          Method getReferencedBytes
 Transforms getTransforms()
          Method getTransforms
 XMLSignatureInput getTransformsInput()
          Deprecated. use
 XMLSignatureInput getTransformsOutput()
          This method only works works after a call to verify.
 java.lang.String getType()
          Return the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element
 java.lang.String getURI()
          Returns the URI of this Reference element
 void setId(java.lang.String Id)
          Sets the Id attribute of this Reference element
 void setType(java.lang.String Type)
          Sets the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element
 void setURI(java.lang.String URI)
          Sets the URI of this Reference element
 boolean typeIsReferenceToManifest()
          Method isReferenceToManifest This returns true if the Type attribute of the Refernce element points to a #Manifest element
 boolean typeIsReferenceToObject()
          Method isReferenceToObject This returns true if the Type attribute of the Refernce element points to a #Object element
 boolean verify()
          Tests reference valdiation is success or false
 
Methods inherited from class org.apache.xml.security.utils.SignatureElementProxy
getBaseNamespace
 
Methods inherited from class org.apache.xml.security.utils.ElementProxy
addBase64Element, addBase64Text, addBigIntegerElement, addText, addTextElement, createElementForFamily, getBaseURI, getBigIntegerFromChildElement, getBytesFromChildElement, getBytesFromTextChild, getChildElementLocalName, getDefaultPrefix, getDocument, getElement, getElementPlusReturns, getTextFromChildElement, getTextFromTextChild, guaranteeThatElementInCorrectSpace, length, setDefaultPrefix, setElement, setXPathNamespaceContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CacheSignedNodes

public static boolean CacheSignedNodes
Field CacheSignedNodes


OBJECT_URI

public static final java.lang.String OBJECT_URI
Field OBJECT_URI

See Also:
Constant Field Values

MANIFEST_URI

public static final java.lang.String MANIFEST_URI
Field MANIFEST_URI

See Also:
Constant Field Values
Constructor Detail

Reference

protected Reference(org.w3c.dom.Document doc,
                    java.lang.String BaseURI,
                    java.lang.String ReferenceURI,
                    Manifest manifest,
                    Transforms transforms,
                    java.lang.String messageDigestAlgorithm)
             throws XMLSignatureException
Constructor Reference

Parameters:
doc - the Document in which XMLsignature is placed
BaseURI - the URI of the resource where the XML instance will be stored
ReferenceURI - URI indicate where is data which will digested
manifest -
transforms - Transforms applied to data
messageDigestAlgorithm - Digest algorithm which is applied to the data $todo$ should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?
Throws:
XMLSignatureException

Reference

protected Reference(org.w3c.dom.Document doc,
                    java.lang.String BaseURI,
                    java.lang.String ReferenceURI,
                    Manifest manifest,
                    java.lang.String messageDigestAlgorithm)
             throws XMLSignatureException
Constructor Reference

Parameters:
doc - this Document in which XMLsignature is placed
BaseURI - the URI of the resource where the XML instance will be stored
ReferenceURI - This referenceURI indicate where the data will for signature validation
manifest -
messageDigestAlgorithm - Digest algorithm which is applied to the data
Throws:
XMLSignatureException

Reference

protected Reference(org.w3c.dom.Document doc,
                    java.lang.String BaseURI,
                    java.lang.String ReferenceURI,
                    Manifest manifest,
                    Transforms transforms)
             throws XMLSignatureException
Constructor Reference

Parameters:
doc - this Document in which XMLsignature is placed
BaseURI - the URI of the resource where the XML instance will be stored
ReferenceURI - This referenceURI indicate where the data is for signature validation
manifest -
transforms - Transforms applied to data
Throws:
XMLSignatureException

Reference

protected Reference(org.w3c.dom.Document doc,
                    java.lang.String BaseURI,
                    java.lang.String ReferenceURI,
                    Manifest manifest)
             throws XMLSignatureException
Constructor Reference

Parameters:
doc - this Document in which XMLsignature is placed
BaseURI - the URI of the resource where the XML instance will be stored
ReferenceURI - This referenceURI indicate where the data is for signature validation
manifest -
Throws:
XMLSignatureException

Reference

protected Reference(org.w3c.dom.Element element,
                    java.lang.String BaseURI,
                    Manifest manifest)
             throws XMLSecurityException
Build a Reference from an Element

Parameters:
element - Reference element
BaseURI - the URI of the resource where the XML instance was stored
manifest - is the Manifest of SignedInfo in which the Reference occurs. We need this because the Manifest has the individual ResourceResolvers whcih have been set by the user
Throws:
XMLSecurityException
Method Detail

getMessageDigestAlgorithm

public MessageDigestAlgorithm getMessageDigestAlgorithm()
                                                 throws XMLSignatureException
Returns MessageDigestAlgorithm

Returns:
MessageDigestAlgorithm
Throws:
XMLSignatureException

setURI

public void setURI(java.lang.String URI)
Sets the URI of this Reference element

Parameters:
URI - the URI of this Reference element

getURI

public java.lang.String getURI()
Returns the URI of this Reference element

Returns:
URI the URI of this Reference element

setId

public void setId(java.lang.String Id)
Sets the Id attribute of this Reference element

Parameters:
Id - the Id attribute of this Reference element

getId

public java.lang.String getId()
Returns the Id attribute of this Reference element

Returns:
Id the Id attribute of this Reference element

setType

public void setType(java.lang.String Type)
Sets the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element

Parameters:
Type - the type attribute of the Reference

getType

public java.lang.String getType()
Return the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element

Returns:
the type attribute of the Reference

typeIsReferenceToObject

public boolean typeIsReferenceToObject()
Method isReferenceToObject This returns true if the Type attribute of the Refernce element points to a #Object element

Returns:
true if the Reference type indicates that this Reference points to an Object

typeIsReferenceToManifest

public boolean typeIsReferenceToManifest()
Method isReferenceToManifest This returns true if the Type attribute of the Refernce element points to a #Manifest element

Returns:
true if the Reference type indicates that this Reference points to a Manifest

generateDigestValue

public void generateDigestValue()
                         throws XMLSignatureException,
                                ReferenceNotInitializedException
Method generateDigestValue

Throws:
ReferenceNotInitializedException
XMLSignatureException

getContentsBeforeTransformation

public XMLSignatureInput getContentsBeforeTransformation()
                                                  throws ReferenceNotInitializedException
Returns the XMLSignatureInput which is created by de-referencing the URI attribute.

ReferenceNotInitializedException

getTransformsInput

public XMLSignatureInput getTransformsInput()
Deprecated. use

Returns the data which is referenced by the URI attribute. This method only works works after a call to verify.


getContentsAfterTransformation

public XMLSignatureInput getContentsAfterTransformation()
                                                 throws XMLSignatureException
Returns the XMLSignatureInput which is the result of the Transforms.

XMLSignatureException

getNodesetBeforeFirstCanonicalization

public XMLSignatureInput getNodesetBeforeFirstCanonicalization()
                                                        throws XMLSignatureException
This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.

Throws:
XMLSignatureException

getHTMLRepresentation

public java.lang.String getHTMLRepresentation()
                                       throws XMLSignatureException
Method getHTMLRepresentation

Throws:
XMLSignatureException

getTransformsOutput

public XMLSignatureInput getTransformsOutput()
This method only works works after a call to verify.


dereferenceURIandPerformTransforms

protected void dereferenceURIandPerformTransforms()
                                           throws XMLSignatureException
This method returns the XMLSignatureInput which is referenced by the URI Attribute.

Throws:
XMLSignatureException
See Also:
Manifest.verifyReferences()

getTransforms

public Transforms getTransforms()
                         throws XMLSignatureException,
                                InvalidTransformException,
                                TransformationException,
                                XMLSecurityException
Method getTransforms

Throws:
InvalidTransformException
TransformationException
XMLSecurityException
XMLSignatureException

getReferencedBytes

public byte[] getReferencedBytes()
                          throws ReferenceNotInitializedException,
                                 XMLSignatureException
Method getReferencedBytes

Throws:
ReferenceNotInitializedException
XMLSignatureException

verify

public boolean verify()
               throws ReferenceNotInitializedException,
                      XMLSecurityException
Tests reference valdiation is success or false

Returns:
true if reference valdiation is success, otherwise false
Throws:
ReferenceNotInitializedException
XMLSecurityException

getBaseLocalName

public java.lang.String getBaseLocalName()
Method getBaseLocalName

Specified by:
getBaseLocalName in class ElementProxy
Returns:
the localname of the Elements of the sub-class.