title: Spring WebFlux Security Custom AccessDeniedHandler
body: <p>I have a REST endpoint where access is restricted to ADMIN users only:</p>
  
  <pre><code>@GetMapping
  @PreAuthorize("hasAuthority('ADMIN')")
  fun getAll(): Flux&lt;User&gt; {
      return Flux.fromIterable(userRepository.findAll())
  }
  </code></pre>
  
  <p>When I try to access this endpoint with a non-ADMIN user, I get a 403 with a <code>denied</code> response (a non JSON response).</p>
  
  <p>How can I customize the response to still receive a 403 response, but with a JSON message something like</p>
  
  <pre><code>{
     "error": "Access denied"
  }
  </code></pre>
  
  <p>The <code>SecurityWebFilterChain</code> I'm implementing:</p>
  
  <pre><code>return http.csrf().disable()
      .formLogin().disable()
      .httpBasic().disable()
      .authenticationManager(authenticationManager)
      .securityContextRepository(securityContextRepository)
      .exceptionHandling().accessDeniedHandler { exchange, denied -&gt; ???? }
      .and()
      .authorizeExchange()
      .pathMatchers(HttpMethod.OPTIONS).permitAll()
      .pathMatchers("/auth").permitAll()
      .anyExchange().authenticated()
      .and().csrf().disable()
      .logout().disable()
      .build()
  </code></pre>