/** * Return a filter that adds an Authorization header for HTTP Basic Authentication. * @param username the username to use * @param password the password to use * @return the {@link ExchangeFilterFunction} that adds the Authorization header */ public static ExchangeFilterFunction basicAuthentication(String username, String password) { Assert.notNull(username, "'username' must not be null"); Assert.notNull(password, "'password' must not be null"); return ExchangeFilterFunction.ofRequestProcessor( clientRequest -> { String authorization = authorization(username, password); ClientRequest<?> authorizedRequest = ClientRequest.from(clientRequest) .header(HttpHeaders.AUTHORIZATION, authorization) .body(clientRequest.inserter()); return Mono.just(authorizedRequest); }); }