title: where to put username and password of WebClient of Spring Webflux?
body: <p>I try to make spring webflux security application with router and handler classes. First, below codes are the configuration codes of webflux security.</p>
  
  <pre><code>@Configuration
  @EnableWebFluxSecurity
  public class BlogWebFluxSecurityConfig {
  
      @Bean
      public MapReactiveUserDetailsService userDetailsService() {
  
          UserDetails userWebFlux = User.withUsername("joseph").password("password").roles("USER").build();
          return new MapReactiveUserDetailsService(userWebFlux);
      }
  
      @Bean
      public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
          http
          .authorizeExchange()
          .pathMatchers("/route/user/all", "/route/post/all").permitAll()
          .pathMatchers(HttpMethod.GET, "/route/user/**", "/route/post/**").hasRole("USER")
          .anyExchange().authenticated()
          .and()
          .httpBasic();
  
          return http.build();
      } 
  }
  </code></pre>
  
  <p>And the next codes are about the router classe.</p>
  
  <pre><code>@Configuration
  @EnableWebFlux
  public class BlogWebFluxEndpointRouter {
  
      @Bean
      public RouterFunction&lt;ServerResponse&gt; routesUser(UserHandler handler) {
  
          return RouterFunctions.route(RequestPredicates.GET("/route/user/all"), handler::findAll)
                      .andRoute(RequestPredicates.GET("/route/user/id/{id}"), handler::findById)
                      .andRoute(RequestPredicates.GET("/route/user/username/{username}"), handler::findByUsername)
                      .andRoute(RequestPredicates.GET("/route/user/email/{email}"), handler::findByEmail)
                      .andRoute(RequestPredicates.POST("/route/user/create"), handler::register)
                      .andRoute(RequestPredicates.GET("/route/user/login/{username}/{password}"), handler::authenticate);
      }
  
      @Bean
      public RouterFunction&lt;ServerResponse&gt; routesPost(PostHandler handler) {
  
          return RouterFunctions.route(RequestPredicates.GET("/route/post/all"), handler::findAll)
                      .andRoute(RequestPredicates.GET("/route/post/id/{id}"), handler::findById)
                      .andRoute(RequestPredicates.GET("/route/post/delete/{id}"), handler::deleteById)
                      .andRoute(RequestPredicates.POST("/route/post/create"), handler::create)
                      .andRoute(RequestPredicates.PUT("/route/post/{id}/{content}"), handler::edit);
      }
  }
  </code></pre>
  
  <p>Even the network is rest web service, But I use WebClient class of WebFlux.</p>
  
  <pre><code>public void functionOnUserDocument() { 
          client.get().uri("/route/user/all").accept(MediaType.APPLICATION_JSON).exchange()
                  .flatMapMany(response -&gt; response.bodyToFlux(User.class))
                  .subscribe(u -&gt; System.out.println("All Users : " + u.getUsername() + ":" + u.getEmail() + ":" + u.getFullname()));
  
          client.get().uri("/route/user/id/{id}", "0002").accept(MediaType.APPLICATION_JSON).exchange()
                  .flatMap(response -&gt; response.bodyToMono(User.class))
                  .subscribe(u -&gt; System.out.println("GET by Id : " + u.getUsername() + ":" + u.getEmail() + ":" + u.getFullname()));
  
          client.get().uri("/route/user/username/{username}", "jina").accept(MediaType.APPLICATION_JSON).exchange()
                  .flatMap(response -&gt; response.bodyToMono(User.class))
                  .subscribe(u -&gt; System.out.println("Get by username : " + u.getUsername() + ":" + u.getEmail() + ":" + u.getFullname()));
  
          client.get().uri("/route/user/email/{email}", "myson@college.ac.kr").accept(MediaType.APPLICATION_JSON).exchange()
                  .flatMap(response -&gt; response.bodyToMono(User.class))
                  .subscribe(u -&gt; System.out.println("Get By Email : " + u.getUsername() + ":" + u.getEmail() + ":" + u.getFullname()));
  
          client.get().uri("/route/user/login/{username}/{password}", "julian", "password").exchange()
                  .map(ClientResponse::statusCode).subscribe(response -&gt; System.out.println("Login : " + response.getReasonPhrase()));
  
          User user = new User("0005", 4L, "jane", "password", "aaa@bbb.com", "누나", "USER");
  
          client.post().uri("/route/user/create").body(Mono.just(user), User.class).exchange() 
                  .map(ClientResponse::statusCode).subscribe(response -&gt; System.out.println("User Creation: " + response.getReasonPhrase()));
      }
  </code></pre>
  
  <p>Because I make the webflux security configuration, definitely some webclient can not be executed and forbidden like below,</p>
  
  <pre><code>Login : Unauthorized
  User Creation: Forbidden
  </code></pre>
  
  <p>I do not use curl. So what I want to know is what my WebClient methods are to be, where username and password have to be located and transferred to WebClient class. Any reply will be thankful. </p>