【发布时间】:2012-03-11 03:51:53
【问题描述】:
只是一个简单的问题:在成功认证时向 HttpSession 添加属性(属性)的最佳方法是什么?以用户 ID 为例。
现在我在 UsernamePasswordAuthenticationFilter 中使用我自己的 SimpleUrlAuthenticationSuccessHandler 实现,并这样做:
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication auth)
throws IOException, ServletException {
PersonBean person = (PersonBean) auth.getPrincipal();
request.getSession().setAttribute("currentUserId", person .getId().toString());
super.onAuthenticationSuccess(request, response, auth);
但我认为这不是一个好方法,因为还有其他方法可以进行身份验证(例如 RememberMe)。
那么我需要在这里使用什么?
【问题讨论】:
标签: spring session authentication spring-security