XPath xpath = factory.newXPath();
final NamespaceContext nsContext = this.getNamespaceContext();
xpath.setNamespaceContext(nsContext);
// Find the SecurityTokenReference for the assertion
final XPathExpression strExpr = xpath.compile(
"/s:Envelope/s:Header/wsse:Security/wsse:SecurityTokenReference/wsse:KeyIdentifier");
final NodeList strKeyIdNodes =
(NodeList) strExpr.evaluate(signedDoc, XPathConstants.NODESET);
String strId = null;
for (int i = 0; i < strKeyIdNodes.getLength(); i++) {
Node keyIdNode = (Node) strKeyIdNodes.item(i);
String strKey = keyIdNode.getTextContent();
if (strKey.equals(assertionId)) {
Node strNode = (Node) keyIdNode.getParentNode();
strId = strNode.getAttributes().
getNamedItemNS(nsContext.getNamespaceURI("wsu"), "Id").getNodeValue();
break;
}
}
assertNotNull("SecurityTokenReference for " + assertionId + " not found in security header.", strId);
// Verify STR is included in the signature references
final XPathExpression sigRefExpr = xpath.compile(
"/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo/ds:Reference");
final NodeList sigReferenceNodes =
(NodeList) sigRefExpr.evaluate(signedDoc, XPathConstants.NODESET);
boolean foundStrReference = false;
for (int i = 0; i < sigReferenceNodes.getLength(); i++) {
Node sigRefNode = (Node) sigReferenceNodes.item(i);
String sigRefURI = sigRefNode.getAttributes().getNamedItem("URI").getNodeValue();