title: Java Future - Spring Authentication is null into AuditorAware
body: <p>This is my scenario: </p>
  
  <p>My app has Mongo Auditing enabled, with a custom AuditorAware which gets the current user from the <code>SecurityContext</code>. This works well with synchronous methods, and the current auditor is successfully saved, but I can't make it work properly with <code>@Async</code> methods.</p>
  
  <p>I have an async method (<code>CompletableFuture</code>) that makes some updates on my Mongo Database. When the <code>AuditorAware.getCurrentAuditor()</code> is called, no authentication info exists, and I can't get the current auditor (<code>SecurityContextHolder.getContext().getAuthentication()</code> returns <code>null</code>). </p>
  
  <pre><code>@Override
  public User getCurrentAuditor() {
     Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  
     if (authentication == null || !authentication.isAuthenticated()
                  || authentication instanceof AnonymousAuthenticationToken) {
              log.error("Not authenticated");
              return null;
      }
  
      [...]
  
  }
  </code></pre>
  
  <p>I'm using a <code>DelegatingSecurityContextAsyncTaskExecutor</code>:</p>
  
  <pre><code>@Configuration
  @EnableAsync
  public class AsyncConfig implements AsyncConfigurer {
  
      @Override
      public Executor getAsyncExecutor() {
          ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(20);
          executor.setMaxPoolSize(100);
          executor.setQueueCapacity(200);
          executor.initialize();
  
          return new DelegatingSecurityContextAsyncTaskExecutor(executor);
      }
  
      @Override
      public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
          return new ItacaExceptionHandler();
      }
  
  } 
  </code></pre>
  
  <p>How can I make it work properly?</p>