Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically log user in with Spring Security 3.1

What's the proper way to programmatically log a web visitor in under a particular username in Spring and Spring Security 3.1? It seems the way I was doing it under 2.5 has changed a little. I'm sure there's a much better way of doing this now.

Basically, when I create a new user, I need to also log them in at the same time.

like image 643
at. Avatar asked Sep 30 '11 18:09

at.


1 Answers

Create an Authentication (usually a UsernamePasswordAuthenticationToken) and then call

SecurityContextHolder.getContext().setAuthentication(authentication)
like image 181
sourcedelica Avatar answered Sep 21 '22 02:09

sourcedelica