【发布时间】:2011-07-02 12:13:27
【问题描述】:
我在 Spring Controller 中使用以下方法来允许通过 Ajax 进行身份验证。它可以工作,但它似乎没有创建 cookie 或任何使身份验证持久的东西。
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public LoginStatus login(@RequestParam("j_username") String username,
@RequestParam("j_password") String password) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
try {
Authentication auth = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(auth);
return new LoginStatus(auth.isAuthenticated(), auth.getName());
} catch (BadCredentialsException e) {
return new LoginStatus(false, null);
}
}
我需要做什么才能使身份验证持久化?
【问题讨论】:
-
Matt - 你有想过这个吗?我现在正在尝试做同样的事情。打算从 Spring Security 论坛尝试这段代码:forum.springsource.org/…
-
是的,请参阅以下评论并发布解决方案:raibledesigns.com/rd/entry/…
标签: java security spring spring-security