- 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: Construct 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>- See Also:
ObjectContainer,Manifest
-
-
Field Summary
Fields Modifier and Type Field Description static StringMANIFEST_URIField MANIFEST_URIstatic intMAXIMUM_TRANSFORM_COUNTThe maximum number of transforms per reference, if secure validation is enabled.static StringOBJECT_URIField OBJECT_URI-
Fields inherited from class org.apache.xml.security.utils.ElementProxy
baseURI
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedReference(Document doc, String baseURI, String referenceURI, Manifest manifest, Transforms transforms, String messageDigestAlgorithm)Constructor ReferenceprotectedReference(Element element, String baseURI, Manifest manifest)protectedReference(Element element, String baseURI, Manifest manifest, boolean secureValidation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected XMLSignatureInputdereferenceURIandPerformTransforms(OutputStream os)This method returns theXMLSignatureInputwhich is referenced by theURIAttribute.voidgenerateDigestValue()Method generateDigestValueStringgetBaseLocalName()Method getBaseLocalName Returns the localname of the Elements of the sub-class.XMLSignatureInputgetContentsAfterTransformation()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.StringgetHTMLRepresentation()Method getHTMLRepresentationStringgetId()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.org.apache.xml.security.signature.reference.ReferenceDatagetReferenceData()Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation.byte[]getReferencedBytes()Method getReferencedBytesTransformsgetTransforms()Method getTransformsXMLSignatureInputgetTransformsOutput()This method only works after a call to verify.StringgetType()Return thetypeattribute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:ManifestelementStringgetURI()Returns theURIof thisReferenceelementvoidsetId(String id)Sets theIdattribute of thisReferenceelementvoidsetType(String type)Sets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement.voidsetURI(String uri)Sets theURIof thisReferenceelementbooleantypeIsReferenceToManifest()Method isReferenceToManifest This returns true if theTypeattribute of theReferenceelement points to a#ManifestelementbooleantypeIsReferenceToObject()Method isReferenceToObject This returns true if theTypeattribute of theReferenceelement points to a#Objectelementbooleanverify()Tests reference validation 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, addReturnToSelf, addText, addTextElement, appendOther, appendSelf, appendSelf, createElementForFamily, createElementForFamilyLocal, createText, getBaseURI, getBigIntegerFromChildElement, getBytesFromTextChild, getDefaultPrefix, getDocument, getElement, getElementPlusReturns, getFirstChild, getLocalAttribute, getTextFromChildElement, getTextFromTextChild, length, registerDefaultPrefixes, setDefaultPrefix, setDocument, setElement, setElement, setLocalAttribute, setLocalIdAttribute, setXPathNamespaceContext
-
-
-
-
Field Detail
-
OBJECT_URI
public static final String OBJECT_URI
Field OBJECT_URI- See Also:
- Constant Field Values
-
MANIFEST_URI
public static final String MANIFEST_URI
Field MANIFEST_URI- See Also:
- Constant Field Values
-
MAXIMUM_TRANSFORM_COUNT
public static final int MAXIMUM_TRANSFORM_COUNT
The maximum number of transforms per reference, if secure validation is enabled.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Reference
protected Reference(Document doc, String baseURI, String referenceURI, Manifest manifest, Transforms transforms, String messageDigestAlgorithm) throws XMLSignatureException
Constructor 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(Element element, String baseURI, Manifest manifest) throws XMLSecurityException
- 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 which have been set by the user- Throws:
XMLSecurityException
-
Reference
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation) throws XMLSecurityException
- Parameters:
element-ReferenceelementbaseURI- the URI of the resource where the XML instance was storedmanifest- is theManifestofSignedInfoin which the Reference occurs.secureValidation- whether secure validation is enabled or not We need this because the Manifest has the individualResourceResolvers which 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(String uri)
Sets theURIof thisReferenceelement- Parameters:
uri- theURIof thisReferenceelement
-
getURI
public String getURI()
Returns theURIof thisReferenceelement- Returns:
- URI the
URIof thisReferenceelement
-
setId
public void setId(String id)
Sets theIdattribute of thisReferenceelement- Parameters:
id- theIdattribute of thisReferenceelement
-
getId
public String getId()
Returns theIdattribute of thisReferenceelement- Returns:
- Id the
Idattribute of thisReferenceelement
-
setType
public void setType(String type)
Sets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement.- Parameters:
type- thetypeattribute of the Reference
-
getType
public String getType()
Return thetypeattribute 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 theReferenceelement 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 theReferenceelement 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
-
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 String getHTMLRepresentation() throws XMLSignatureException
Method getHTMLRepresentation- Returns:
- The HTML of the transformation
- Throws:
XMLSignatureException
-
getTransformsOutput
public XMLSignatureInput getTransformsOutput()
This method only works after a call to verify.- Returns:
- the transformed output(i.e. what is going to be digested).
-
getReferenceData
public org.apache.xml.security.signature.reference.ReferenceData getReferenceData()
Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation.
-
dereferenceURIandPerformTransforms
protected XMLSignatureInput dereferenceURIandPerformTransforms(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 XMLSecurityExceptionReturns the digest value.- Returns:
- the digest value.
- Throws:
XMLSecurityException- if the Reference does not contain a DigestValue element
-
verify
public boolean verify() throws ReferenceNotInitializedException, XMLSecurityExceptionTests reference validation is success or false- Returns:
- true if reference validation is success, otherwise false
- Throws:
ReferenceNotInitializedExceptionXMLSecurityException
-
getBaseLocalName
public String getBaseLocalName()
Method getBaseLocalName Returns the localname of the Elements of the sub-class.- Specified by:
getBaseLocalNamein classElementProxy- Returns:
- the localname of the Elements of the sub-class.
-
-