【发布时间】: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