in src/main/java/org/apache/xml/security/signature/XMLSignature.java [540:632]
public XMLSignature(Element element, String baseURI, boolean secureValidation, Provider provider)
throws XMLSignatureException, XMLSecurityException {
super(element, baseURI);
if (!(Constants.SignatureSpecNS.equals(element.getNamespaceURI())
&& Constants._TAG_SIGNATURE.equals(element.getLocalName()))) {
Object[] exArgs = { element.getLocalName() };
throw new XMLSignatureException("signature.Verification.InvalidElement", exArgs);
}
// check out SignedInfo child
Element signedInfoElem = XMLUtils.getNextElement(element.getFirstChild());
// check to see if it is there
if (signedInfoElem == null ||
!(Constants.SignatureSpecNS.equals(signedInfoElem.getNamespaceURI())
&& Constants._TAG_SIGNEDINFO.equals(signedInfoElem.getLocalName()))) {
Object[] exArgs = { Constants._TAG_SIGNEDINFO, Constants._TAG_SIGNATURE };
throw new XMLSignatureException("xml.WrongContent", exArgs);
}
// create a SignedInfo object from that element
this.signedInfo = new SignedInfo(signedInfoElem, baseURI, secureValidation, provider);
// get signedInfoElem again in case it has changed
signedInfoElem = XMLUtils.getNextElement(element.getFirstChild());
// check out SignatureValue child
this.signatureValueElement =
XMLUtils.getNextElement(signedInfoElem.getNextSibling());
// check to see if it exists
if (signatureValueElement == null ||
!(Constants.SignatureSpecNS.equals(signatureValueElement.getNamespaceURI())
&& Constants._TAG_SIGNATUREVALUE.equals(signatureValueElement.getLocalName()))) {
Object[] exArgs = { Constants._TAG_SIGNATUREVALUE, Constants._TAG_SIGNATURE };
throw new XMLSignatureException("xml.WrongContent", exArgs);
}
Attr signatureValueAttr = signatureValueElement.getAttributeNodeNS(null, "Id");
if (signatureValueAttr != null) {
signatureValueElement.setIdAttributeNode(signatureValueAttr, true);
}
// <element ref="ds:KeyInfo" minOccurs="0"/>
Element keyInfoElem =
XMLUtils.getNextElement(signatureValueElement.getNextSibling());
// If it exists use it, but it's not mandatory
Element objectElem = null;
if (keyInfoElem != null
&& Constants.SignatureSpecNS.equals(keyInfoElem.getNamespaceURI())
&& Constants._TAG_KEYINFO.equals(keyInfoElem.getLocalName())) {
this.keyInfo = new KeyInfo(keyInfoElem, baseURI);
this.keyInfo.setSecureValidation(secureValidation);
objectElem = XMLUtils.getNextElement(keyInfoElem.getNextSibling());
} else {
// If we have no KeyInfo
objectElem = keyInfoElem;
}
// <element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/>
while (objectElem != null) {
// Make sure it actually is an Object
if (!(Constants.SignatureSpecNS.equals(objectElem.getNamespaceURI())
&& Constants._TAG_OBJECT.equals(objectElem.getLocalName()))) {
Object[] exArgs = { objectElem.getLocalName() };
throw new XMLSignatureException("signature.Verification.InvalidElement", exArgs);
}
Attr objectAttr = objectElem.getAttributeNodeNS(null, "Id");
if (objectAttr != null) {
objectElem.setIdAttributeNode(objectAttr, true);
}
Node firstChild = objectElem.getFirstChild();
// Register Ids of the Object child elements
while (firstChild != null) {
if (firstChild.getNodeType() == Node.ELEMENT_NODE) {
Element childElem = (Element)firstChild;
String tag = childElem.getLocalName();
if ("Manifest".equals(tag)) {
new Manifest(childElem, baseURI);
} else if ("SignatureProperties".equals(tag)) {
new SignatureProperties(childElem, baseURI);
}
}
firstChild = firstChild.getNextSibling();
}
objectElem = XMLUtils.getNextElement(objectElem.getNextSibling());
}
this.state = MODE_VERIFY;
}