Taras Sheremeta
Taras Sheremeta

Reputation: 117

Spring Security: Authentication user manually

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.

Upvotes: 7

Views: 10273

Answers (1)

vacuum
vacuum

Reputation: 2273

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.

Upvotes: 22

Related Questions