接收方端点与SAML响应不匹配。

17

通常我的基于Spring SAML服务提供商(SP)实现表现良好,但有时会返回以下错误:

[2014-07-17 16:00:58.767] boot - 1078 DEBUG [http-bio-80-exec-1] --- BaseMessageDecoder:     Successfully decoded message.
[2014-07-17 16:00:58.767] boot - 1078 DEBUG [http-bio-80-exec-1] --- BaseSAMLMessageDecoder: Checking SAML message intended destination endpoint against receiver endpoint
[2014-07-17 16:00:58.768] boot - 1078 DEBUG [http-bio-80-exec-1] --- BaseSAMLMessageDecoder: Intended message destination endpoint: https://prismasp.cloud.reply.eu:443/MIUR_PRISMA-2.1-WEBUI/saml/SSO/alias/defaultAlias
[2014-07-17 16:00:58.768] boot - 1078 DEBUG [http-bio-80-exec-1] --- BaseSAMLMessageDecoder: Actual message receiver endpoint: http://prismasp.cloud.reply.eu:443/MIUR_PRISMA-2.1-WEBUI/saml/SSO/alias/defaultAlias
[2014-07-17 16:00:58.768] boot - 1078 ERROR [http-bio-80-exec-1] --- BaseSAMLMessageDecoder: SAML message intended destination endpoint 'https://prismasp.cloud.reply.eu:443/MIUR_PRISMA-2.1-WEBUI/saml/SSO/alias/defaultAlias' did not match the recipient endpoint 'http://prismasp.cloud.reply.eu:443/MIUR_PRISMA-2.1-WEBUI/saml/SSO/alias/defaultAlias'
[2014-07-17 16:00:58.782] boot - 1078 DEBUG [http-bio-80-exec-1] --- SAMLProcessingFilter: Incoming SAML message is invalid
org.opensaml.xml.security.SecurityException: SAML message intended destination endpoint did not match recipient endpoint
...

我正在使用(作为 Spring Security 的默认设置)在启用了 SSLTomcat 7 上实现 HTTP 严格传输安全(HSTS)

是否有方法可以修复此错误?


注意:示例源代码位于 Githubvdenotaris/spring-boot-security-saml-sample


我认为您在idp端点配置的协议中漏掉了“s”。您期望使用“https”,但似乎收到的是“http”。 - alain.janinm
当前的配置通常都能正常工作,只是有时会导致上述错误。我认为问题可能出在其他地方。也许我需要手动设置元数据,或者我错过了某个特定的设置(我只是猜测)。 - vdenotaris
该链接显示“白标签错误页面”,不是元数据。同时,当你说“通常可以正常工作”时,这很奇怪,它应该始终或永远不能工作!我猜协议有点问题。也许有时你用http连接,有时用https连接。而你的idp似乎期望https连接。 - alain.janinm
只有一个“7”,而不是“/”。 - vdenotaris
3个回答

33

我不知道为什么你的问题会随机发生,但至少有一种方法可以修复它,那就是配置SAMLContextProviderLB而不是你目前正在使用的SAMLContextProviderImpl

SAMLContextProviderLB通常用于告诉Spring SAML公共端有关反向代理或负载均衡器上使用的公共URL,但在这种情况下,您可以使用它来强制Spring SAML认为它正在使用HTTPS。您可以在Spring SAML手册的第10.1章“高级配置”中找到详细信息。

您还应确保正确设置您的MetadataGenerator bean上的entityBaseURL属性,因为如果没有这样做,则生成的元数据将取决于您是否首次使用http或https请求您的应用程序。同样,所有这些都在文档中记录。


你可以使用 TLSProtocolConfigurer 进行配置,参见:https://docs.spring.io/spring-security-saml/docs/2.0.x/reference/htmlsingle/#configuration-metadata-https - Gregor

6

我在使用Spring Security SAML时也遇到了同样的问题。因此,我必须将contextProvider从SAMLContextProviderImpl更改为:

  @Bean
  public SAMLContextProviderImpl contextProvider() {
      return new SAMLContextProviderImpl();
  }

至于SAMLContextProviderLB:

  @Bean
  public SAMLContextProviderLB contextProvider() {
    SAMLContextProviderLB samlContextProviderLB = new SAMLContextProviderLB();
    samlContextProviderLB.setScheme(scheme);
    samlContextProviderLB.setServerName(serverName);
    samlContextProviderLB.setContextPath(contextPath);
      return samlContextProviderLB;
  }

3
我觉得你的应用服务器在负载均衡器后面。
对于运行在 AWS 应用负载均衡器后面的 Apache Tomcat 服务器,需要启用 RemoteIPValue,以便根据 x-forwarded-proto 标头,Tomcat 可以相应地覆盖 scheme(https) 和 port(443)。
server.xml 文件中:
<Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeader="X-Forwarded-Proto" internalProxies="10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|169\.254\.\d+\.\d+|127\.\d+\.\d+\.\d+|172\.(1[6-9]|2[0-9]|3[0-1])\.\d+\.\d+" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接