Iam使用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应该是主题的一部分。但是大多数的subject/attribute.,包括我正在使用的一个,提到nameId可能是nameId的一部分似乎有一些实现像SimpleSAMLPHP.一样在主题中接受nameId。
我所收到的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作为其属性值。为什么不能用它代替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是spring实现中唯一的subject的一部分。
@vschafer是一种定制securityContext.xml以选择nameId的方法,它是特定属性的一部分,而不是来自subject
发布于 2014-10-13 21:06:38
Spring目前要求出现NameID。更改此操作将需要更改代码,目前无法仅用配置完成。请随时打开一个在春季SAML Jira中更改此功能的请求。
发布于 2016-04-11 15:01:14
我们在ADFS3.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"/>https://stackoverflow.com/questions/26297938
复制相似问题