• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Autologin to site upon registering using spring security

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 22
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try this after successfully completing the registration

 
All of the following truths are shameless lies. But what about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic