0

I have a Spring MVC web-app that uses Spring Security for authentication. I have a registration page and after the user successfully enters all the details I want them to be automatically logged in using the information they just entered. How can I do this?

Samantha Catania
  • 5,116
  • 5
  • 39
  • 69

1 Answers1

1

This can be done by setting the Authentication object manually while processing the user details. Here is the code:

List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
Authentication a =  new UsernamePasswordAuthenticationToken(newUsername, newPassword, grantedAuths);
SecurityContextHolder.getContext().setAuthentication(a);`

Where newUser and newPassword are two Strings with registered user's credentials

Samantha Catania
  • 5,116
  • 5
  • 39
  • 69