我正在尝试这样做:让spring security在登录页面的查询字符串中添加返回url,即:获取spring告诉登录页面我来自哪里.我有一些SSO集成..所以我会发送url给他们,或者他们会为我添加引用,所以我知道用户应该登录并发送给/some/url.这都是花花公子.我遇到的问题是扩展LoginUrlAuthenticationEntryPoint(除非你能告诉我一个很好的理由来实现AuthenticationEntryPoint).我只需要修改登录页面的请求,如下所示:
RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
// only append returnto to '/login' urls
if(request.getServletPath() == "/login") {
// indicates we want to return to this page after login
redirectStrategy.sendRedirect(request, response, "/login?returnto=" + request.getServletPath());
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让剩下的请求做他们的事情?这是不正确的(我刚刚做的):
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
// just forward the request
dispatcher.forward(request, response);
Run Code Online (Sandbox Code Playgroud)
因为它把我们放在一个重定向循环中.然而,它似乎是春天的版本commence.我糊涂了.我应该commence在自定义扩展程序中做LoginUrlAuthenticationEntryPoint什么?
弄清楚了.只需要转发到登录页面并附加'returnto'.我一开始觉得很困惑,因为LoginUrlAuthenticationEntryPoint这并不意味着"这会将用户重定向到登录页面"乍一看.这就是我所需要的:
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException) throws IOException, ServletException {
RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
redirectStrategy.sendRedirect(request, response, "/login?returnto=" + request.getServletPath());
}
Run Code Online (Sandbox Code Playgroud)
这很有用:grepcode.com上的LoginUrlAuthenticationEntryPoint.java
| 归档时间: |
|
| 查看次数: |
11069 次 |
| 最近记录: |