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 ads:Referencefrom anElement.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
Fields Modifier and Type Field Description static booleanCacheSignedNodesField CacheSignedNodesstatic java.lang.StringMANIFEST_URIField MANIFEST_URIstatic java.lang.StringOBJECT_URIField 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
Constructors Modifier Constructor Description protectedReference(org.w3c.dom.Document doc, java.lang.String BaseURI, java.lang.String ReferenceURI, Manifest manifest, Transforms transforms, java.lang.String messageDigestAlgorithm)Constructor ReferenceprotectedReference(org.w3c.dom.Element element, java.lang.String BaseURI, Manifest manifest)Build aReferencefrom anElement
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected XMLSignatureInputdereferenceURIandPerformTransforms(java.io.OutputStream os)This method returns theXMLSignatureInputwhich is referenced by theURIAttribute.voidgenerateDigestValue()Method generateDigestValuejava.lang.StringgetBaseLocalName()Method getBaseLocalNameXMLSignatureInputgetContentsAfterTransformation()Returns the XMLSignatureInput which is the result of the Transforms.XMLSignatureInputgetContentsBeforeTransformation()Returns the XMLSignatureInput which is created by de-referencing the URI attribute.byte[]getDigestValue()Returns the digest value.java.lang.StringgetHTMLRepresentation()Method getHTMLRepresentationjava.lang.StringgetId()Returns theIdattribute of thisReferenceelementMessageDigestAlgorithmgetMessageDigestAlgorithm()ReturnsMessageDigestAlgorithmXMLSignatureInputgetNodesetBeforeFirstCanonicalization()This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.byte[]getReferencedBytes()Method getReferencedBytesTransformsgetTransforms()Method getTransformsXMLSignatureInputgetTransformsInput()Deprecated.use getContentsBeforeTransformationXMLSignatureInputgetTransformsOutput()This method only works works after a call to verify.java.lang.StringgetType()Return thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelementjava.lang.StringgetURI()Returns theURIof thisReferenceelementvoidsetId(java.lang.String Id)Sets theIdattribute of thisReferenceelementvoidsetType(java.lang.String Type)Sets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:ManifestelementvoidsetURI(java.lang.String URI)Sets theURIof thisReferenceelementbooleantypeIsReferenceToManifest()Method isReferenceToManifest This returns true if theTypeattribute of theRefernceelement points to a#ManifestelementbooleantypeIsReferenceToObject()Method isReferenceToObject This returns true if theTypeattribute of theRefernceelement points to a#Objectelementbooleanverify()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, getDefaultPrefix, getDocument, getElement, getElementPlusReturns, getTextFromChildElement, getTextFromTextChild, guaranteeThatElementInCorrectSpace, length, setDefaultPrefix, setElement, setXPathNamespaceContext
-
-
-
-
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 XMLSignatureExceptionConstructor Reference- Parameters:
doc- theDocumentin whichXMLsignatureis placedBaseURI- the URI of the resource where the XML instance will be storedReferenceURI- URI indicate where is data which will digestedmanifest-transforms-Transformsapplied to datamessageDigestAlgorithm-Digest algorithmwhich is applied to the data TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?- Throws:
XMLSignatureException
-
Reference
protected Reference(org.w3c.dom.Element element, java.lang.String BaseURI, Manifest manifest) throws XMLSecurityExceptionBuild aReferencefrom anElement- Parameters:
element-ReferenceelementBaseURI- the URI of the resource where the XML instance was storedmanifest- is theManifestofSignedInfoin which the Reference occurs. We need this because the Manifest has the individualResourceResolvers whcih have been set by the user- Throws:
XMLSecurityException
-
-
Method Detail
-
getMessageDigestAlgorithm
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException
ReturnsMessageDigestAlgorithm- Returns:
MessageDigestAlgorithm- Throws:
XMLSignatureException
-
setURI
public void setURI(java.lang.String URI)
Sets theURIof thisReferenceelement- Parameters:
URI- theURIof thisReferenceelement
-
getURI
public java.lang.String getURI()
Returns theURIof thisReferenceelement- Returns:
- URI the
URIof thisReferenceelement
-
setId
public void setId(java.lang.String Id)
Sets theIdattribute of thisReferenceelement- Parameters:
Id- theIdattribute of thisReferenceelement
-
getId
public java.lang.String getId()
Returns theIdattribute of thisReferenceelement- Returns:
- Id the
Idattribute of thisReferenceelement
-
setType
public void setType(java.lang.String Type)
Sets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement- Parameters:
Type- thetypeattribute of the Reference
-
getType
public java.lang.String getType()
Return thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement- Returns:
- the
typeattribute of the Reference
-
typeIsReferenceToObject
public boolean typeIsReferenceToObject()
Method isReferenceToObject This returns true if theTypeattribute of theRefernceelement points to a#Objectelement- Returns:
- true if the Reference type indicates that this Reference points to an
Object
-
typeIsReferenceToManifest
public boolean typeIsReferenceToManifest()
Method isReferenceToManifest This returns true if theTypeattribute of theRefernceelement points to a#Manifestelement- Returns:
- true if the Reference type indicates that this Reference points to a
Manifest
-
generateDigestValue
public void generateDigestValue() throws XMLSignatureException, ReferenceNotInitializedExceptionMethod generateDigestValue
-
getContentsBeforeTransformation
public XMLSignatureInput getContentsBeforeTransformation() throws ReferenceNotInitializedException
Returns the XMLSignatureInput which is created by de-referencing the URI attribute.- Returns:
- the XMLSignatureInput of the source of this reference
- Throws:
ReferenceNotInitializedException- If the resolver found any problem resolving the reference
-
getTransformsInput
public XMLSignatureInput getTransformsInput() throws ReferenceNotInitializedException
Deprecated.use getContentsBeforeTransformationReturns the data which is referenced by the URI attribute. This method only works works after a call to verify.- Returns:
- a XMLSignature with a byte array.
- Throws:
ReferenceNotInitializedException
-
getContentsAfterTransformation
public XMLSignatureInput getContentsAfterTransformation() throws XMLSignatureException
Returns the XMLSignatureInput which is the result of the Transforms.- Returns:
- a XMLSignatureInput with all transformations applied.
- Throws:
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.- Returns:
- Gets a the node doing everything till the first c14n is needed
- Throws:
XMLSignatureException
-
getHTMLRepresentation
public java.lang.String getHTMLRepresentation() throws XMLSignatureExceptionMethod getHTMLRepresentation- Returns:
- The HTML of the transformation
- Throws:
XMLSignatureException
-
getTransformsOutput
public XMLSignatureInput getTransformsOutput()
This method only works works after a call to verify.- Returns:
- the transformed output(i.e. what is going to be digested).
-
dereferenceURIandPerformTransforms
protected XMLSignatureInput dereferenceURIandPerformTransforms(java.io.OutputStream os) throws XMLSignatureException
This method returns theXMLSignatureInputwhich is referenced by theURIAttribute.- Parameters:
os- where to write the transformation can be null.- Returns:
- the element to digest
- Throws:
XMLSignatureException- See Also:
Manifest.verifyReferences()
-
getTransforms
public Transforms getTransforms() throws XMLSignatureException, InvalidTransformException, TransformationException, XMLSecurityException
Method getTransforms- Returns:
- The transforms that applied this reference.
- Throws:
InvalidTransformExceptionTransformationExceptionXMLSecurityExceptionXMLSignatureException
-
getReferencedBytes
public byte[] getReferencedBytes() throws ReferenceNotInitializedException, XMLSignatureExceptionMethod getReferencedBytes- Returns:
- the bytes that will be used to generated digest.
- Throws:
ReferenceNotInitializedExceptionXMLSignatureException
-
getDigestValue
public byte[] getDigestValue() throws Base64DecodingException, XMLSecurityExceptionReturns the digest value.- Returns:
- the digest value.
- Throws:
Base64DecodingException- if Reference contains no proper base64 encoded data.XMLSecurityException- if the Reference does not contain a DigestValue element
-
verify
public boolean verify() throws ReferenceNotInitializedException, XMLSecurityExceptionTests reference valdiation is success or false- Returns:
- true if reference valdiation is success, otherwise false
- Throws:
ReferenceNotInitializedExceptionXMLSecurityException
-
getBaseLocalName
public java.lang.String getBaseLocalName()
Method getBaseLocalName- Specified by:
getBaseLocalNamein classElementProxy- Returns:
- the localname of the Elements of the sub-class.
-
-