content: package ag.selm.gateway.config;
  
  import de.codecentric.boot.admin.client.config.ClientProperties;
  import de.codecentric.boot.admin.client.registration.ReactiveRegistrationClient;
  import de.codecentric.boot.admin.client.registration.RegistrationClient;
  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.oauth2.client.AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager;
  import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientService;
  import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
  import org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction;
  import org.springframework.web.reactive.function.client.WebClient;
  
  @Configuration
  public class ClientBeans {
  
      @Bean
      @ConditionalOnProperty(name = "spring.boot.admin.client.enabled", havingValue = "true")
      public RegistrationClient registrationClient(
              ClientProperties clientProperties,
              ReactiveClientRegistrationRepository clientRegistrationRepository,
              ReactiveOAuth2AuthorizedClientService authorizedClientService
      ) {
          ServerOAuth2AuthorizedClientExchangeFilterFunction filter =
                  new ServerOAuth2AuthorizedClientExchangeFilterFunction(
                          new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(clientRegistrationRepository,
                                  authorizedClientService));
          filter.setDefaultClientRegistrationId("metrics");
  
          return new ReactiveRegistrationClient(WebClient.builder()
                  .filter(filter)
                  .build(), clientProperties.getReadTimeout());
      }
  }
  