title: How to make AuditorAware work with Spring Data Mongo Reactive
body: <p>Spring Security 5 provides a <a href="https://stackoverflow.com/a/51133327/545127"><code>ReactiveSecurityContextHolder</code> to fetch  the <code>SecurityContext</code> from a Reactive context</a>, but when I want to implement <code>AuditorAware</code> and get audition work automatically, but it does not work. <strong>Currently I can not find a <code>Reactive</code> variant for <code>AuditorAware</code></strong>.</p>
  <pre><code>@Bean
  public AuditorAware&lt;Username&gt; auditor() {
      return () -&gt; ReactiveSecurityContextHolder.getContext()
          .map(SecurityContext::getAuthentication)
          .log()
          .filter(a -&gt; a != null &amp;&amp; a.isAuthenticated())
          .map(Authentication::getPrincipal)
          .cast(UserDetails.class)
          .map(auth -&gt; new Username(auth.getName()))
          .switchIfEmpty(Mono.empty())
          .blockOptional();
  }
  </code></pre>
  <p>I have added <code>@EnableMongoAuduting</code> on my boot <code>Application</code> class.</p>
  <p>On the Mongo document class. I added audition related annotations.</p>
  <pre><code>@CreatedDate
  private LocalDateTime createdDate;
  
  @CreatedBy
  private Username author;
  </code></pre>
  <p>When I added a post, the <code>createdDate</code> is filled, but author is null.</p>
  <pre><code>{&quot;id&quot;:&quot;5a49ccdb9222971f40a4ada1&quot;,&quot;title&quot;:&quot;my first post&quot;,&quot;content&quot;:&quot;content of my first post&quot;,&quot;createdDate&quot;:&quot;2018-01-01T13:53:31.234&quot;,&quot;author&quot;:null}
  </code></pre>
  <p>The complete codes is <a href="https://github.com/hantsy/angular-springboot2-sample/tree/master/server" rel="nofollow noreferrer">here</a>, based on Spring Boot 2.0.0.M7.</p>
  <p><strong>Update:</strong> Spring Boot 2.4.0-M2/Spring Data Common 2.4.0-M2/Spring Data Mongo 3.1.0-M2 includes a <code>ReactiveAuditorAware</code>, Check <a href="https://github.com/hantsy/spring-reactive-sample/tree/master/boot-data-mongo-auditing" rel="nofollow noreferrer">this new sample</a>, <strong>Note</strong>: use <code>@EnableReactiveMongoAuditing</code> to activiate it.</p>