title: How to store facebook authenticated user in DB?
body: <p>I tried to implement this tutorial <a href="https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_logout" rel="nofollow">https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_logout</a>
  This is my application config(spring boot)</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = {"org.fiodorov.controller","org.fiodorov.service", "org.fiodorov.config"})
  @EntityScan(basePackages = "org.fiodorov.model")
  @EnableJpaRepositories(basePackages = "org.fiodorov.repository")
  @EnableOAuth2Client
  @EnableAutoConfiguration
  public class Application extends WebSecurityConfigurerAdapter{
  
      @Autowired
      OAuth2ClientContext oauth2ClientContext;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.antMatcher("/**")
          .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
      }
  
  
      public static void main(String[] args) {
          SpringApplication.run(
                  Application.class, args);
      }
  
      private Filter ssoFilter() {
          OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/facebook");
          OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oauth2ClientContext);
          facebookFilter.setRestTemplate(facebookTemplate);
          facebookFilter.setTokenServices(new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId()));
          return facebookFilter;
      }
  
      @Bean
      @ConfigurationProperties("facebook.client")
      OAuth2ProtectedResourceDetails facebook() {
          return new AuthorizationCodeResourceDetails();
      }
  
      @Bean
      @ConfigurationProperties("facebook.resource")
      ResourceServerProperties facebookResource() {
          return new ResourceServerProperties();
      }
  
      @Bean
      public FilterRegistrationBean oauth2ClientFilterRegistration(
              OAuth2ClientContextFilter filter) {
          FilterRegistrationBean registration = new FilterRegistrationBean();
          registration.setFilter(filter);
          registration.setOrder(-100);
          return registration;
      }
  
  }
  </code></pre>
  
  <p>And it works. I can login and can get user info as described in tutorial. But I don't know how can I find the moment just after login and before redirect to main page for storing user details in database if user does not exist and verify his roles if exists.</p>
  
  <p>How can I do this?</p>