Spring SAML : SAML message intended destination endpoint did not match recipient endpoint

标签 spring spring-security saml saml-2.0 spring-saml

在我的应用程序 SP 和客户端 IdP 之间进行 SSO 时,我收到 'Caused by: org.opensaml.xml.security.SecurityException: SAML message intended destination endpoint did not match recipient endpoint' 异常。

服务器日志显示模式差异,如下所示:

Checking SAML message intended destination endpoint against receiver endpoint
2019-03-05 15:02:44.599 DEBUG [204 default task-41][BaseSAMLMessageDecoder] Intended message destination endpoint: https://my.app.com/app-gateway/saml/SSO
2019-03-05 15:02:44.599 DEBUG [204 default task-41][BaseSAMLMessageDecoder] Actual message receiver endpoint: http://my.app.com/app-gateway/saml/SSO
2019-03-05 15:02:44.600 ERROR [204 default task-41][BaseSAMLMessageDecoder] SAML message intended destination endpoint 'https://my.app.com/app-gateway/saml/SSO' did not match the recipient endpoint 'http://my.app.com/app-gateway/saml/SSO'

我的应用程序在 2 个实例上的 STG 上运行,LB 在前面,因此我使用 SAMLContextProviderLB 上下文提供程序而不是 SAMLContextProviderImpl:

<bean id="contextProvider" class="org.springframework.security.saml.context.SAMLContextProviderLB">
        <property name="scheme" value="https"/>
        <property name="serverName" value="my.app.com"/>
        <property name="serverPort" value="443"/>
        <property name="includeServerPortInRequestURL" value="false"/>
        <property name="contextPath" value="/app-gateway"/>
    </bean>

<bean id="metadataGeneratorFilter" class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
        <constructor-arg>
            <bean class="org.springframework.security.saml.metadata.MetadataGenerator">
                <property name="entityBaseURL" value="https://my.app.com/app-gateway1"/>
                <property name="entityId" value="${cas.sso.entityId}"/>
                <property name="includeDiscoveryExtension" value="false"/>
                <property name="extendedMetadata" ref="extendedMetadata"/>
                <property name="keyManager" ref="keyManager"/>
            </bean>
        </constructor-arg>
    </bean>

getActualReceiverEndpointURI 的源代码中,接收方端点 URL 是从请求 httpRequest obj 中获取的。 因此,我试图了解错误 URL http://my.app.com/app-gateway/saml/SSO 在哪一步被设置为它。谁能给我解释一下?

protected String getActualReceiverEndpointURI(SAMLMessageContext messageContext) throws MessageDecodingException {
        InTransport inTransport = messageContext.getInboundMessageTransport();
        if (! (inTransport instanceof HttpServletRequestAdapter)) {
            log.error("Message context InTransport instance was an unsupported type: {}", 
                    inTransport.getClass().getName());
            throw new MessageDecodingException("Message context InTransport instance was an unsupported type");
        }
        HttpServletRequest httpRequest = ((HttpServletRequestAdapter)inTransport).getWrappedRequest();

        StringBuffer urlBuilder = httpRequest.getRequestURL();

        return urlBuilder.toString();
    }

最佳答案

您可能需要查看以下页面: https://developer.jboss.org/thread/240113

我有一个类似的问题,即使在 LB 上正确设置了 X-Forwarded-Proto,请求仍然只在 http 中被解释。 后端必须知道 header 。

在 http 监听器和两个 filter-ref 上添加 proxy-address-forwarding="true"

<http-listener name="default" socket-binding="http" proxy-address-forwarding="true"/>  
            <filter-ref name="server-header"/>  
            <filter-ref name="x-powered-by-header"/>  

希望对您有所帮助,

关于 Spring SAML : SAML message intended destination endpoint did not match recipient endpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55012162/

相关文章:

java - Liquibase Hibernate Java 8 支持

java - Spring PropertySourcesPlaceholderConfigurer : local properties vs environment ones?

java - 多个分片数据库 Hibernate 事务

java.lang.NoClassDefFoundError : org/springframework/web/servlet/support/RequestDataValueProcessor

spring - 如何在同一应用程序中使用 spring-sample 示例配置 spring 安全基本身份验证和 SAML 身份验证

Azure AD - 是否可以在企业应用程序之间复制/复制/克隆角色/用户/组?

spring - 在 JSP 页面中使用 Spring MVC 时出现错误 500

Spring Boot 应用程序通过服务器上的物理存在对用户进行身份验证

java - 从/登录重定向到/针对经过身份验证的用户

testing - 你能推荐一个 SAML 2.0 身份提供者进行测试吗?