ITeye博客

how to get login user info

freesky1002 · 2007-11-23 10:33 · APPFUSE · Markdown

request.getRemoteUser() 

SecurityContext context = SecurityContextHolder.getContext();

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

In order to log the user in automatically after signup, I discovered that Ineeded to place the SecurityContext in the session. I did this by changing
the following code in SignupController:

         // log user in automatically
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword(),user.getAuthorities());
         auth.setDetails(user);
         SecurityContextHolder.getContext().setAuthentication(auth);

To:

// log user in automatically
UsernamePasswordAuthenticationToken auth = new
UsernamePasswordAuthenticationToken(
user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
auth.setDetails(user);
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(auth);
request.getSession().setAttribute("ACEGI_SECURITY_CONTEXT", context);

Hope this helps someone!

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。