SAMLException:NameID 元素必须作为响应消息中主题的一部分出现,请在 IDP 配置中启用它

2024-01-02

我在用春天萨姆执行。在 WebSSOProfileConsumerImpl 类中,我可以找到以下代码行,用于检查 nameIdSAML 响应的断言.

NameID nameID;
if (subject.getEncryptedID() != null) {
    Assert.notNull(context.getLocalDecrypter(), "Can't decrypt NameID, no decrypter is set in the context");
    nameID = (NameID) context.getLocalDecrypter().decrypt(subject.getEncryptedID());
} else {
    nameID = subject.getNameID();
}

根据代码,很明显 nameId 应该是主题的一部分。但大多数 IDP(包括我正在使用的 IDP)都提到 nameId 可能是主题/属性。似乎有一些实现接受主题中的 nameId 就像简单SAMLPHP.

The subject我收到的信息如下,并且没有包含 nameId

<saml2:Subject>
  <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">  
    <saml2:SubjectConfirmationData Address="91.X.X.X" InResponseTo="XXXX" NotOnOrAfter="2014-10-10T10:34:26.619Z" Recipient="http://localhost:8080/XXXX/saml/SSO"/>
  </saml2:SubjectConfirmation>
</saml2:Subject>

然而,有一个属性其中有一个nameId as its 属性值。为什么不能用这个来代替subject.

<saml2:Attribute FriendlyName="testID" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
  <saml2:AttributeValue>
      <saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" NameQualifier="https://XXXX/idp/shibboleth" SPNameQualifier="urn:XX:XX:XX">XXXXXXXXXXXXXXXXX=
      </saml2:NameID>
  </saml2:AttributeValue>
</saml2:Attribute>

谁能解释一下背后的原因nameId成为唯一的一部分subject in 春天萨姆执行。

@vschafer 有没有办法自定义安全上下文.xml选择nameId这是特定的一部分属性而不是来自subject?


ADFS 3.0 也有类似的情况。 ADFS 的这一特定配置根本不提供 NameId。我们通过向 ADFS 请求 UPN 声明,然后将其用作 NameId 来实现解决方法。不过,可插入的 NameIdResolver 会很好,@vschafer。

如果有人感兴趣的话,解决方法的代码:

public class ClaimConstants {

public static final String UPN = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn";
}

 

public class NameIdWebSSOProfileConsumer extends WebSSOProfileConsumerImpl {

@Override
protected void verifySubject(Subject subject, AuthnRequest request, SAMLMessageContext context) throws SAMLException, DecryptionException {
    super.verifySubject(subject, request, context);

    Response response = (Response) context.getInboundSAMLMessage();
    for (EncryptedAssertion ea : response.getEncryptedAssertions()) {
        Assertion assertion = context.getLocalDecrypter().decrypt(ea);

        for (Statement statement : assertion.getStatements()) {
            if (statement instanceof AttributeStatementImpl) {
                for (Attribute attribute : ((AttributeStatementImpl) statement).getAttributes()) {
                    if (ClaimConstants.UPN.equals(attribute.getName())) {
                        NameID nameId = new NameIDBuilder().buildObject();
                        XSAnyImpl xmlObject = (XSAnyImpl) attribute.getAttributeValues().get(0);
                        nameId.setValue(xmlObject.getTextContent());
                        //noinspection unchecked
                        context.setSubjectNameIdentifier(nameId);
                        return;
                    }
                }
            }
        }
    }
}

然后在 Spring 中正常使用:

<bean id="webSSOprofileConsumer" class="com.example.NameIdWebSSOProfileConsumer"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SAMLException:NameID 元素必须作为响应消息中主题的一部分出现,请在 IDP 配置中启用它 的相关文章

随机推荐