java - 来自 saml 响应的 opensaml 3 签名为空

标签 java azure saml unmarshalling opensaml

您好,我收到此错误消息:

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);

最佳答案

好吧,我想我找到了,看来您没有向 POM 添加任何实现依赖项。当我使用您的 POM 并包含此依赖项时,我会得到签名对象。

  <dependency>
     <groupId>org.opensaml</groupId>
     <artifactId>opensaml-saml-impl</artifactId>
     <version>3.2.0</version>
 </dependency>

依赖项的模块化结构与 OpenSAML 版本 2 有很大不同。

关于java - 来自 saml 响应的 opensaml 3 签名为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41102613/

相关文章:

java - 在我的服务器中,出现异常 "javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake"

java - 如果我们使用@OneToMany注释,我们是否必须在数据库中本地定义一对多关系

amazon-web-services - 从 Azure Devops Pipeline 上传到 AWS s3 存储桶

saml - 为什么 SAML 服务提供商应该信任 SAML 响应?

SAML 1x 与 SAML 2.0

java - 在 Java servlet 中使用 x509 证书公钥

java - 在java中读取时跳过文本文件的某些部分

java - 在 Gradle 中获取 POM 父级

azure - Azure Functions 中的缩放 Controller 背后的逻辑是什么?

r - Azure Notebooks 中插入符号包安装失败且退出状态为非零