title: How to get current user from ReactiveSecurityContextHolder in WebFlux?
body: <p>Usually while working with Spring Boot, a common way to get currently logged users is to use:</p>
  <pre><code>SecurityContextHolder.getContext();
  </code></pre>
  <p>This does not work when working with reactive programming, and Mono in Java since they do not belong to the same thread. It's recommended to use:</p>
  <pre><code>ReactiveSecurityContextHolder.getContext()
  </code></pre>
  <p>I've read many articles, StackOverflow questions, and answers, but never found a full explanation or example of how to fully integrate ReactiveSecurityContextHolder.</p>
  <p>Any help would be highly appreciated.</p>
  <p>This is what I have tried:</p>
  <pre><code>   @RequestMapping(value = &quot;/get-auth&quot;, method = RequestMethod.GET)
  public @ResponseBody Mono&lt;Authentication&gt; test(Authentication authp) {
      return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication).doOnNext(auth -&gt; {
          log.info(&quot;print auth&quot;, String.valueOf(auth));
      }).doOnSuccess(auth -&gt; {
          log.error(&quot;print auth&quot;, auth);
      });
  }
  </code></pre>
  <p>doOnSuccess - returns null<br />
  doOnNext - not triggered</p>