Home Ask Login Register

Developers Planet

Your answer is one click away!

Gaurav Tyagi February 2016

Thymeleaf: Login user via sign up page instead of /login

So far I know that it works automatically, but don't know how to use it if i had created a new user via some sign page. Now instead of taking the user to log in page again. Is there any way to log in user automatically on sign up.


Martin Cron February 2016

As part of where you register your user, you can manually stuff a new authentication object into the SecurityContextHolder. This will keep the user from having to log in manually.

// build authentication token based on the username and password provided Collection authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("user")); Authentication auth = new UsernamePasswordAuthenticationToken(email, password, authorities); // set authentication in context SecurityContextHolder.getContext().setAuthentication(auth);

Post Status

Asked in February 2016
Viewed 1,832 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life