Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remember me in Spring security to remember only user-name

I am using Spring security in my application and wish to know if there is a way to "ask" spring to only remember the user-name of the user that comes to the application (by means of the remember-me checkbox). What I could gather from the reference documentation is that Spring is able to save the userName and the password of the user, and directly log him/her in the next time. But what I want is that user be taken to the login page each time he comes back, but with his user-name already typed in.

Ofcourse if Spring doesn't have a way to do this, I would need to implement some cookie storage logic to take care of this requirement.

Many thanks for your answers as always.

like image 716
PaiS Avatar asked Aug 03 '10 18:08

PaiS


1 Answers

So, you need to set a cookie containing the user name after authentication, and access it during rendering of the login page.

If you use Spring Security 3.x, the former can be done by subclassing AuthenticationSuccessHandler (SavedRequestAwareAuthenticationSuccessHandler is the default implementation) and setting a cookie with response.addCookie().

The latter is a regular cookie access (request.getCookies(), etc).

like image 109
axtavt Avatar answered Oct 07 '22 23:10

axtavt