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

Spring security3.1.0兑现登陆后跳转至登录前页面

热度:352   发布时间:2012-12-29 10:28:09.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);
  相关解决方案