【问题标题】:Spring Security 3.0: GET request after authenticationSpring Security 3.0:认证后的 GET 请求
【发布时间】:2012-03-13 23:44:55
【问题描述】:

我有一个类似于 Spring Security 3.0 SSO 的内置 Spring 应用程序和一个针对我的 SSO 服务器进行身份验证的外部 php 应用程序。

当用户登录此应用程序时,我也想在 php 应用程序中对他/她进行身份验证。

所以我这样做了:

……

public class CustomAuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler {

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet("http://localhost/phpapp/signin");
        httpget.setHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.2) Gecko/20100101 Firefox/10.0.2");
        httpget.setHeader("Connection", "keep-alive");
        httpget.setHeader("Referer", "http://localhost:8080/;jsessionid="+request.getSession().getId());
        httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        httpget.setHeader("Accept-Language", "en-gb,en;q=0.5");
        httpget.setHeader("Accept-Encoding", "gzip, deflate");
        httpget.setHeader("Cookie", "JSESSIONID="+request.getSession().getId());

        HttpResponse res = httpclient.execute(httpget);

    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
}

在身份验证后处理程序中,我针对 php 应用程序的登录创建了一个“GET”请求。 当它被执行时,在请求正文中返回“登录页面”,就像用户没有记录一样。注意我用过:

httpget.setHeader("Referer", "http://localhost:8080/;jsessionid="+request.getSession().getId());

作为当前经过身份验证的 jsessionid。

但是如果我把相同的链接:http://localhost/phpapp/signin作为正常的href链接放在页面中,然后点击它就可以正常工作。

知道为什么不能在过滤器中处理相同类型的请求吗?

【问题讨论】:

    标签: php spring authentication spring-security single-sign-on


    【解决方案1】:

    这很可能与 Cookie 路径有关。 Cookie 与子域、域、路径和端口相关联,因此除非两个应用程序都在 http://localhost/phpapp/ 上运行,否则您将遇到问题。您可以尝试修改 Spring 以不设置 cookie 的路径或端口元素,即仅将其绑定到 localhost。

    但是,我强烈建议您采用另一种方法,例如真正的单点登录系统,而不是尝试在应用之间代理 cookie。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-02
      • 2022-11-14
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 2020-07-17
      相关资源
      最近更新 更多