【发布时间】:2018-12-18 12:06:25
【问题描述】:
长期以来一直困扰着这个问题,感谢任何帮助。
我正在为我的应用程序实施 Spring SAML SSO 身份验证。 它实际上是一个巨大的安全配置文件,因此我只会附上我认为可能很重要的配置部分。
@Bean
public MetadataGenerator metadataGenerator() {
MetadataGenerator metadataGenerator = new MetadataGenerator();
metadataGenerator.setEntityId(env.getProperty("saml.entity.id"));
metadataGenerator.setExtendedMetadata(extendedMetadata());
metadataGenerator.setIncludeDiscoveryExtension(false);
metadataGenerator.setKeyManager(keyManager());
return metadataGenerator;
}
@Bean
@Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider() throws MetadataProviderException {
String idpSSOCircleMetadataURL = env.getProperty("saml.provider.url");
HTTPMetadataProvider httpMetadataProvider = new HTTPMetadataProvider(this.backgroundTaskTimer, httpClient(),
idpSSOCircleMetadataURL);
httpMetadataProvider.setParserPool(parserPool());
ExtendedMetadataDelegate extendedMetadataDelegate = new ExtendedMetadataDelegate(httpMetadataProvider,
extendedMetadata());
extendedMetadataDelegate.setMetadataTrustCheck(true);
extendedMetadataDelegate.setMetadataRequireSignature(false);
backgroundTaskTimer.purge();
return extendedMetadataDelegate;
}
我们在这个 bean 中使用的属性文件的值是 -
saml.entity.id=urn:saml2:test:s
saml.provider.url=https://fedsvc-stage.pwc.com/ofiss/FederationMetadata/2007-06/FederationMetadata.xml
我的 spring 应用程序托管在本地机器上,并且 IDP 是公开可用的。我在 hosts 文件中添加了条目,因此我的 ip 映射到 mysso.com
现在我正在尝试访问 SAML 身份验证背后的 url -
http://mysso.com:8080/sso-self/auth/login
用户 get 被重定向到他输入凭据的 IDP,并且在成功进行身份验证后,用户 get 被重定向回 - http://localhost:8080/sso-self/saml/SSO,带有 saml 响应,但我在浏览器上得到 404,并且在控制台上出现以下错误 -
org.opensaml.common.SAMLException: InResponseToField of the Response doesn't correspond to sent message a330ei589j3e99ee10d8a55bghc518i
我可以看到的问题是消息正在从 2 个不同的会话中存储和检索,因为第一个请求来自域名 mysso.com 但响应返回到 localhost
这是我发送给 IDP 的 AuthnRequest XML
<?xml version="1.0" encoding="UTF-8"?><saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" AssertionConsumerServiceURL="http://localhost:8080/madison-sso-self/saml/SSO" Destination="https://fedsvc-stage.pwc.com/ofiss/" ForceAuthn="false" ID="a345ia5236e6hc2g48ea13fcf4386h7" IsPassive="false" IssueInstant="2018-12-18T07:46:41.812Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">urn:saml2:test:s</saml2:Issuer>
</saml2p:AuthnRequest>
我能理解的是 AuthnRequest 中的 AssertionConsumerServiceURL 值是http://localhost:8080/madison-sso-self/saml/SSO,这就是它返回到这个 url 的原因。 现在我不明白为什么这个值是 localhost 而不是我的主机名 http://mysso.com:8080/madison-sso-self/saml/SSO。
如果您需要更多信息来解决问题,请回复。 提前致谢。
【问题讨论】:
标签: spring single-sign-on saml-2.0 spring-saml