【发布时间】:2016-12-12 14:03:32
【问题描述】:
您好,我收到此错误消息:
net.shibboleth.utilities.java.support.logic.ConstraintViolationException: Signature was null
关于验证来自 Azure AD 的 SAML 响应。
出于测试目的,我将响应文件保存为 xml 并找到了一个标签:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod
Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_97031c65-0139-4047-a416-9495df5d6ed7">
<ds:Transforms>
<ds:Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>
KMaFHRt8inqVYsMGKnAryKUTQUbYGPUDPxdvj6T08OQ=
</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
.....
</ds:SignatureValue>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
<X509Certificate>
....
</X509Certificate>
</X509Data>
</KeyInfo>
</ds:Signature>
我解组 XML 响应:
InitializationService.initialize();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
String content = new String(Files.readAllBytes(Paths.get("saml_response_azure.xml")));
Document document = docBuilder.parse(new ByteArrayInputStream(content.trim().getBytes()));
Element element = document.getDocumentElement();
Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(element);
Response response = (Response) unmarshaller.unmarshall(element);
并且错误被丢弃在:
Signature signature = response.getAssertions().get(0).getSignature() // returns null
SAMLSignatureProfileValidator profValidator = new SAMLSignatureProfileValidator();
profValidator.validate(signature);
【问题讨论】:
-
你能在某处提供整个回复吗?要点例如
-
gist.github.com/Gobliins/26d8f760f120430eaeb29c223f2e436f 我已经用一些随机信息替换了凭据
-
顺便说一句。在 opensaml 2.6.x 中我没有这个问题
-
我试过这个gist.github.com/anonymous/035c2cb57780a6810909cc1b0dcdee96,我从你的xml中得到了一个签名对象。
-
是签名对象是空的还是你在那一行得到一个空指针?你能检查你的响应对象是非空的吗?
标签: java azure saml unmarshalling opensaml