Spring SAML发送错误的身份验证请求 [英] Spring SAML sending wrong AuthNRequest
本文介绍了Spring SAML发送错误的身份验证请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此问题由来已久,如有任何帮助,不胜感激。
我正在为我的应用程序实现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是公共可用的。我已在我的主机文件中添加了条目,因此我的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
我看到问题是,由于第一个请求来自域名mysso.com,但响应返回到本地主机
,邮件正被存储并从两个不同的会话中检索这是我要发送给IdP的AuthnRequestXML
<?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中的AssertionConsumer erServiceURL值是http://localhost:8080/madison-sso-self/saml/SSO,这就是它返回到这个URL的原因。 现在我不明白为什么此值是本地主机,而不是我的主机名http://mysso.com:8080/madison-sso-self/saml/SSO。
请回复,以防您需要更多信息来弄清楚。 提前谢谢。
推荐答案
您可以使用SAMLConextProviderLB来解决此问题。请将下面配置中的值替换为您的服务器URL。
@Bean
public SAMLContextProviderLB contextProvider() {
SAMLContextProviderLB samlContextProviderLB = new SAMLContextProviderLB();
samlContextProviderLB.setScheme("https");
samlContextProviderLB.setServerName("www.myserver.com");
samlContextProviderLB.setServerPort(443);
samlContextProviderLB.setContextPath("/spring-security-saml2-sample");
samlContextProviderLB.setStorageFactory(new EmptyStorageFactory());
return samlContextProviderLB;
}
上述配置将使用https://www.myserver.com/spring-security-saml2-sample/saml/SSO从SAML服务提供商重定向。
samlContextProviderLB.setStorageFactory(new EmptyStorageFactory());
上行将帮助解决多个会话问题。
这篇关于Spring SAML发送错误的身份验证请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文