16

通常我的基于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
...

我在启用SSL的Tomcat 7上使用(作为Spring Security的默认设置)HTTP Strict Transport Security (HSTS) 。

有没有办法解决这个错误?


注意:示例源代码在Github上:vdenotaris/spring-boot-security-saml-sample

4

3 回答 3

31

我不知道为什么你的问题是随机发生的,但至少解决它的一种方法是配置SAMLContextProviderLB而不是你当前的SAMLContextProviderImpl.

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

您还应该确保正确设置bean 的属性,因为如果不这样做,生成的元数据将取决于您是使用 http 还是 https 向应用程序发出第一个请求entityBaseURLMetadataGenerator同样,所有这些都记录在案

于 2014-07-17T16:56:31.163 回答
5

我对 Spring Security SAML 有同样的问题。所以我不得不从 SAMLContextProviderImpl 更改 contextProvider:

  @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;
  }
于 2019-12-05T10:15:40.817 回答
0

我认为您的应用程序服务器位于负载均衡器后面!

对于在 AWS 应用程序负载均衡器后面运行的 Apache Tomcat 服务器,需要启用RemoteIPValue以便基于x-forwarded-proto标头,Tomcat 将相应地覆盖方案(https) 和端口(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+" />
于 2019-08-13T05:37:22.450 回答