首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > 高性能WEB开发 >

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

2012-12-29 
Spring security3.1.0实现登陆后跳转至登录前页面@Servicepublic class AuthenticationSuccessHandler ext

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 的目的是什么?
说详细一点你想要实现的东西



热点排行