Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Autologin to site upon registering using spring security

 
kuldeep sidhu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we achieve auto-login upon registering using spring-security.?
In my application i am having register page at /users/new.
Upon successful registration, i am redirecting the user to new page /users/username which will display user details.

Using the following interceptor pattern



In above scenario it again asks for login. But i dont want that login. I should directly login the user upon successful registeration.

Please suggest.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should store the authentication object in the session. By default, if you put an Authentication in the SecurityContextHolder, Spring will put the authentication object in the session. Next time, the user comes to the website, it will load it from the session. ALso, by default loggiing in stores the authentication in the session, so you don;t have to do anything in the login page yourself. In your case, if you registration page puts the authentication object in the SecurityContextHolder, you might be good to go.

If you want to remember the user beyond the http session, you have to enable Remember-Me authentication. Basically, you have to put the cookie on the user's browser that persists beyond the HTTP session, and link that cookie to the user's login. When user comes to your website again with the cookie, you authenticate the user using the cookie rather than username/password. You can enable Remember me using Spring easily. You will have to build something in the backend to persist the remember me cookie in a database.
 
Raghvendra Pratap Singh
Greenhorn
Posts: 22
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this after successfully completing the registration

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic