7

I trying authenticate user in Spring Security application via oAuth. I'm already received token and user's data.

How can I authenticate user manually without password and classic login form? Thank you.

Taras Sheremeta
  • 117
  • 1
  • 1
  • 8

1 Answers1

22

Something like this:

Authentication authentication =  new UsernamePasswordAuthenticationToken(person, null, person.getAuthorities());
log.debug("Logging in with {}", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);

Where person is your UserDetailsBean object.

vacuum
  • 2,273
  • 3
  • 20
  • 32
  • 1
    Please note that this will work only if your signIn path uses security mapping of following type `` In the newer versions of spring security there is a better and faster way of skipping security for eg. `` with the new format the given solution will not work as there is no SecurityContextHolder created in later scenario. – Saumitra R. Bhave Nov 11 '12 at 18:59