---
title: "how to get login user info"
author: "freesky1002"
date: "2007-11-23T10:33:57Z"
tags: []
slug: "how-to-get-login-user-info"
draft: false
lastmod: "2007-11-23T10:33:57Z"
id: 142956
url: "https://freesky1002.iteye.com/blog/142956"
---

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!