当前位置: 代码迷 >> 高性能WEB开发 >> Spring security3.1.0实现登陆后跳转至登录前页面,该怎么解决
  详细解决方案

Spring security3.1.0实现登陆后跳转至登录前页面,该怎么解决

热度:276   发布时间:2012-06-14 16:00:31.0
Spring security3.1.0实现登陆后跳转至登录前页面
@Service
public class AuthenticationSuccessHandler extends
SavedRequestAwareAuthenticationSuccessHandler {

该类中的onAuthenticationSuccess方法如下:
每次获取为空:SavedRequest savedRequest = this.requestCache.getRequest(request, response);
saveRequest为Null,求解,大神帮忙呀!


@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws ServletException, IOException {
bindUserToSession(request);
User user = (User) request.getSession().getAttribute(
ConstValueUtil.CUR_USER);


SavedRequest savedRequest = this.requestCache.getRequest(request, response);

  if (savedRequest == null) {
  super.onAuthenticationSuccess(request, response, authentication);
  return;
  }

  if (isAlwaysUseDefaultTargetUrl()
  || StringUtils.hasText(request
  .getParameter(getTargetUrlParameter()))) {
  this.requestCache.removeRequest(request, response);
  super.onAuthenticationSuccess(request, response, authentication);
  return;
  }

// List<User> onlineLawyers = userService.getOnlineLawyers();
// request.getSession().setAttribute("onlineLawyers", onlineLawyers);

saveLoginHistory(user, request);
clearAuthenticationAttributes(request);
if (user.isClientRole()) {
response.sendRedirect(loginSuccessUrl
.get(ConstValueUtil.CUR_CLIENT));
} else if (user.isLawyerRole()) {
response.sendRedirect(loginSuccessUrl
.get(ConstValueUtil.CUR_LAWYER));
} else if (user.isAgentRole()) {
response.sendRedirect(loginSuccessUrl.get(ConstValueUtil.CUR_AGENT));
} else if (user.isAdminRole()) {
response.sendRedirect(loginSuccessUrl.get(ConstValueUtil.CUR_ADMIN));
} else {
response.sendRedirect("home");
}
}

------解决方案--------------------
我配置的,没你怎么复杂,也没继承SavedRequestAwareAuthenticationSuccessHandler 类。
你这个
<beans:entry key="CUR_LAWYER" value="lawyer/index" />
<beans:entry key="CUR_AGENT" value="agent/index" />
<beans:entry key="CUR_CLIENT" value="client/index" />
<beans:entry key="CUR_ADMIN" value="admin/index" />

是CUR_ADMIN权限跳到admin/index,CUR_CLIENT跳到client/index,这样吗?
我做了个简单例子
SavedRequest savedRequest = this.requestCache.getRequest(request, response);
savedRequest 不会为null呀。

你继承这个SavedRequestAwareAuthenticationSuccessHandler 的目的是什么?
说详细一点你想要实现的东西



  相关解决方案