title: Authentication is null on the SecurityContextHolder.getContext();
body: <p>I am trying to add Facebook authorization using Spring Security in Spring Boot app. Currently, my problem is extracting data from Principal.</p>
  
  <p>Here is my security config:</p>
  
  <pre><code>public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure (HttpSecurity http) throws Exception {
          http
              .csrf().disable()
              .antMatcher("/**")
              .authorizeRequests()
                  .antMatchers("/", "/login**").permitAll()
                  .anyRequest().authenticated()
                  .and()
              .logout()
                  .deleteCookies("JSESSIONID")
                  .clearAuthentication(true)
                  .logoutSuccessUrl("/").permitAll();
      }
  
      @Bean
      public PrincipalExtractor facebookPrincipalExtractor(){
          return new FacebookPrincipalExtractor();
      }
  }
  </code></pre>
  
  <p>and principal extractor:</p>
  
  <pre><code>public class FacebookPrincipalExtractor implements PrincipalExtractor {
  
      @Autowired
      UserService userService;
  
      @Override
      public Object extractPrincipal(Map&lt;String, Object&gt; map) {
          String name = (String) map.get("name");
          String id = (String) map.get("id");
          User user = userService.findOne(id);
          if (user == null) {
              SecurityContext securityContext = SecurityContextHolder.getContext();
              Authentication authentication = securityContext.getAuthentication();
              String token = ((OAuth2AuthenticationDetails) authentication.getDetails()).getTokenValue();
              user = new User();
  
              FacebookClient facebookClient = new DefaultFacebookClient(token, Version.VERSION_2_10);
  
              JSONObject object = facebookClient.fetchObject("me", JSONObject.class);
  //           userService.createUser(object);
          }
          return user;
      }
  }
  </code></pre>
  
  <p>After login, the <code>Map&lt;String, Object&gt; map</code> contains only the name and id. Call to <code>securityContext.getAuthentication()</code> returns <code>null</code>. </p>
  
  <p>Moreover, if I create something similar to the endpoint and pass the <code>Principal</code> there as a parameter, then this will work. Example:</p>
  
  <pre><code>@RequestMapping("/user")
  public Principal user(Principal principal) {
      return principal;
  }
  </code></pre>
  
  <p>The <code>principal</code> will contain all the necessary data.</p>
  
  <p>In this regard, 2 questions:</p>
  
  <ol>
  <li>Why security context does not contain authentication?</li>
  <li>Where does the <code>principal</code> come from if it is passed as a parameter to a method?</li>
  </ol>
  
  <hr>
  
  <p>This is what the debug looks like inside</p>
  
  <p><a href="https://i.stack.imgur.com/4C6Cj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4C6Cj.png" alt="enter image description here"></a></p>