spring security 如何实现登录后跳转至登录前访问的页面?
1个回答
展开全部
增加一个入口
<sec:http entry-point-ref="loginUrlEntryPoint">
定义实现
<bean id="loginUrlEntryPoint" class="xxx.xxx.LoginUrlEntryPoint" />
public class LoginUrlEntryPoint implements AuthenticationEntryPoint{
private static final Log log = LogFactory.getLog(LoginUrlEntryPoint.class);
@Override
public void commence(HttpServletRequest request,
HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
String targetUrl = null;
String url = request.getRequestURI();
// 取得登陆前的url
String refererUrl = request.getHeader("Referer");
// TODO 增加处理逻辑
targetUrl = refererUrl;
response.sendRedirect(targetUrl);
}
}
<sec:http entry-point-ref="loginUrlEntryPoint">
定义实现
<bean id="loginUrlEntryPoint" class="xxx.xxx.LoginUrlEntryPoint" />
public class LoginUrlEntryPoint implements AuthenticationEntryPoint{
private static final Log log = LogFactory.getLog(LoginUrlEntryPoint.class);
@Override
public void commence(HttpServletRequest request,
HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
String targetUrl = null;
String url = request.getRequestURI();
// 取得登陆前的url
String refererUrl = request.getHeader("Referer");
// TODO 增加处理逻辑
targetUrl = refererUrl;
response.sendRedirect(targetUrl);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询