java是否可以通过编程方式使用Spring安全性进行身份验证并使其持久化?
我在Spring控制器中使用以下方法来允许通过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);
}
}
我需要做什么才能使身份验证持久化
# 1 楼答案
确定
SecurityContextPersistenceFilter
<security:http>
标记的create-session
属性设置为none
李>