if (signedElement.hasAttributeNS(null, "Id")) {
signedElement.setIdAttributeNS(null, "Id", true);
}
// See also WSS4J SAMLUtil.getCredentialFromKeyInfo
KeyInfo keyInfo = signature.getKeyInfo();
X509Certificate cert = keyInfo.getX509Certificate();
if (cert != null) {
valid = signature.checkSignatureValue(cert);
} else {
PublicKey pk = keyInfo.getPublicKey();
if (pk != null) {
valid = signature.checkSignatureValue(pk);
}
}
// validate trust
new TrustValidator().validateTrust(crypto, cert, keyInfo.getPublicKey());
if (valid && persistSignature) {
message.setContent(XMLSignature.class, signature);
message.setContent(Element.class, signedElement);
}