Class ServletBearerExchangeFilterFunction

  • All Implemented Interfaces:
    org.springframework.web.reactive.function.client.ExchangeFilterFunction

    public final class ServletBearerExchangeFilterFunction
    extends java.lang.Object
    implements org.springframework.web.reactive.function.client.ExchangeFilterFunction
    An ExchangeFilterFunction that adds the Bearer Token from an existing AbstractOAuth2Token tied to the current Authentication. Suitable for Servlet applications, applying it to a typical WebClient configuration:
      @Bean
      WebClient webClient() {
          ServletBearerExchangeFilterFunction bearer = new ServletBearerExchangeFilterFunction();
          return WebClient.builder()
                  .filter(bearer).build();
      }
     
    To locate the bearer token, this looks in the Reactor Context for a key of type Authentication. Registering {@see org.springframework.security.config.annotation.web.configuration.OAuth2ResourceServerConfiguration.OAuth2ResourceServerWebFluxSecurityConfiguration.BearerRequestContextSubscriberRegistrar}, as a @Bean will take care of this automatically, but certainly an application can supply a Context of its own to override.
    Since:
    5.2
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      reactor.core.publisher.Mono<org.springframework.web.reactive.function.client.ClientResponse> filter​(org.springframework.web.reactive.function.client.ClientRequest request, org.springframework.web.reactive.function.client.ExchangeFunction next)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.springframework.web.reactive.function.client.ExchangeFilterFunction

        andThen, apply
    • Constructor Detail

      • ServletBearerExchangeFilterFunction

        public ServletBearerExchangeFilterFunction()
    • Method Detail

      • filter

        public reactor.core.publisher.Mono<org.springframework.web.reactive.function.client.ClientResponse> filter​(org.springframework.web.reactive.function.client.ClientRequest request,
                                                                                                                   org.springframework.web.reactive.function.client.ExchangeFunction next)
        Specified by:
        filter in interface org.springframework.web.reactive.function.client.ExchangeFilterFunction