Spring 安全:来自外部网站的调用无法重定向到我们的应用程序

Spring Security : Call from external website unable to redirect to our application

我们正在开发一个基于 Spring 的 Web 应用程序,它使用 Spring Security 3.2.3。我们正在与外部支付网关 (Paytm) 集成以接受用户的付款。以下是我们面临问题的场景:

  1. 用户登录应用程序(这是一个 HTTP 非 S 应用程序)并点击一个按钮 将他重定向到支付网关(Paytm 支付网关 - 它是 HTTPS url)。
  2. 对于 Paytm 集成,我们配置了回调 URL 即我们应用程序的索引页面(例如 http://server:port/app/index.jsp)。用户完成付款,Paytm 将控件重定向回我们的 Spring 应用程序。
  3. Paytm 尝试调用我们应用程序的索引页面(例如 http://server:port/app/index.jsp)时,它失败了,在 Chrome 调试器中,我们可以看到 403 Forbidden 响应。
  4. 但是,这种情况在 Mozilla FirexfoxIE 11 中运行良好。该问题仅在 Google ChromeOpera 浏览器中出现。
  5. 我们尝试在回调 URL 中提供一些其他网站(如 https://google.com),重定向成功。

我们怀疑可能是某些配置问题或 Spring 安全设置缺失,但我们不确定。

这是我们的 Spring 安全配置:

<http auto-config="true" use-expressions="true">
        <!-- Un-comment when authorization is implemented -->
        <intercept-url pattern="/**" access="isAuthenticated()"/>
        <form-login authentication-failure-handler-ref="failureHandler"
            authentication-success-handler-ref="successHandler" />
        <intercept-url pattern="/**" />
        <logout logout-success-url="${login.page.url}" />
    </http>

    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <password-encoder ref="encoder" />
            <jdbc-user-service data-source-ref="dataSource"
                users-by-username-query="select gu.email, gu.password, gu.enabled from global_user gu,global_organization_user gou, global_organization go where email=? and gu.enabled=1 and gu.is_deleted=0 and gou.user_id = gu.id and gou.organization_id=go.id and go.current_stage='ACTIVE' and go.is_deleted=0"
                authorities-by-username-query="select u.email, r.role_id from global_user u, security_user_role r
                where u.id = r.user_id and u.email=?" />
        </authentication-provider>
    </authentication-manager>

    <beans:bean id="encoder"
        class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
    <beans:bean id="successHandler"
        class="app.server.security.authentication.AuthenticationSuccessHandler" />
    <beans:bean id="failureHandler"
        class="app.server.security.authentication.AuthenticationFailureHandler" />

    <beans:bean id="expressionHandler"
        class="app.server.security.authorization.CustomMethodSecurityExpressionHandler">
        <beans:property name="permissionEvaluator" ref="authorizationEvaluator">
        </beans:property>
    </beans:bean>

    <beans:bean id="authorizationEvaluator"
        class="app.server.security.authorization.AuthorizationEvaluator" />


    <global-method-security pre-post-annotations="enabled">
        <expression-handler ref="expressionHandler" />
    </global-method-security>

    <http pattern="/rest/app/someurl**" security="none"/>
    // other URLs which are escaped from spring security

如有任何建议和指点,我们将不胜感激。

通过将支付网关响应重定向到中间 URL(我们创建了一个单独的 Web 项目并提供了它的 link),暂时解决了这个问题。这个中间 URL 然后将控件重定向到我们的 Spring 应用程序。

这个问题也在我的本地主机站点上使用 https 解决了。 添加SSL证书并尝试。

遇到了与 op 类似的问题,但我们设法通过将回调 URL 配置为使用 https 来解决此问题http。但是,这可能并不适用于所有人,因为每个支付网关都有不同的安全控制。希望这对您有所帮助!