Spring Boot OAuth2 - authenticate with Facebook using local user database
<p>I am creating website using Spring Boot, Spring MVC and spring-security-oauth2 and I am trying to authenticate my locally stored users against Google, Facebook, GitHub ... OAuth2 services. I also have standard username-password for them. </p>

<p>My idea is to store pair of [OAuth2_provider_type,OAuth2_subjectId] for each user to local database from the first success oauth login and then use this pair to find correct user when user authenticate himself by Google (or FB...) again. I have correctly authenticate with Google/Facebook but I don't know how to connect my local stored users to Spring OAuth2 Security and get them to SecurityContext.</p>

<p>Could somebody point me to some example or integration test where I can see something similar?</p>

<p>Here I found great tutorial <a href="https://spring.io/guides/tutorials/spring-boot-oauth2/" rel="nofollow">Spring Boot and OAuth2</a> with hints in section <em>How to Add a Local User Database</em> . Tried to redirect from Google to <em>Authorized redirect URI</em> <code>http://localhost:10001/user</code> endpoint which is defined like <code>.antMatchers("/user").authenticated()</code> and get <em>Access Denied</em></p>

<p><code>o.s.s.w.a.i.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /user?state=Wj7RVk&amp;code=4/wa2AFtJr0K3cKTxDAYo8rTOu2p41km5o3YCPnimx4wU; Attributes: [authenticated]
o.s.s.w.a.i.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@6fa8940c: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffde5d4: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 5888363FA9E329992073DCE4B21E8B5C; Granted Authorities: ROLE_ANONYMOUS
o.s.s.access.vote.AffirmativeBased - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@29802df4, returned: -1
o.s.s.w.a.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
</code></p>

<p>Thank you very much for any help!</p>