5

我正在使用spring-saml实现。在 WebSSOProfileConsumerImpl 类中,我可以找到以下代码行,它们在SAML 响应的断言中检查 nameId 。

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 可能是subject/attribute的一部分。似乎有一些实现在主题中接受 nameId ,就像SimpleSAMLPHP一样。

我收到的主题如下,没有附上 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作为其属性值。为什么不能用这个代替主题中的那个。

<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是spring-saml实现中唯一主题的一部分的原因。

@vschafer 有没有一种方法可以自定义securityContext.xml以选择nameId,它是特定属性的一部分而不是来自subject

4

2 回答 2

3

我们在 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"/>
于 2016-04-11T15:01:14.087 回答
2

Spring SAML 当前需要NameID存在。更改这将需要更改代码,并且目前不能仅通过配置来完成。请随时在Spring SAML Jira中打开功能请求以更改此设置。

于 2014-10-13T21:06:38.207 回答