how to get login user info

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!

你可能感兴趣的:(Security,Acegi)