【发布时间】:2017-06-11 14:11:15
【问题描述】:
在我的Spring MVC Web 应用程序中,我使用Spring Security 进行登录和注销。在我的spring-security.xml 我有以下内容:
<form-login login-page="/login" default-target-url="/"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
在登录过程中,我将一个包含用户详细信息的 TO 设置为会话,如下所示:
request.getSession().setAttribute("USERTO", userTO);
其中userTO 是具有UserTO 类型的用户详细信息的对象。而我的注销控制器方法如下:
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(ModelMap model, @RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout)
{
try
{
UserTO user = (UserTO) httpSession.getAttribute("USERTO");
if (error != null)
{
//error during login
}
if (logout != null)
{
//succesful logout
}
model.addAttribute("smartWCMLayoutID", "smartly");
model.addAttribute("cm", new CommonModel("", "", ""));
return "smartwcm.login.definition";
}
catch(Exception ex)
{
}
}
但在注销期间,我总是将UserTO 设为空。有什么方法可以在注销之前从会话中捕获该值。
【问题讨论】:
标签: java spring spring-mvc session spring-security