github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/feign/auth/HttpBasicAuth.mustache (about)

     1  package {{invokerPackage}}.auth;
     2  
     3  import feign.RequestInterceptor;
     4  import feign.RequestTemplate;
     5  import feign.auth.BasicAuthRequestInterceptor;
     6  
     7  /**
     8   * An interceptor that adds the request header needed to use HTTP basic authentication.
     9   */
    10  public class HttpBasicAuth implements RequestInterceptor {
    11  
    12      private String username;
    13      private String password;
    14      
    15      public String getUsername() {
    16          return username;
    17      }
    18  
    19      public void setUsername(String username) {
    20          this.username = username;
    21      }
    22  
    23      public String getPassword() {
    24          return password;
    25      }
    26  
    27      public void setPassword(String password) {
    28          this.password = password;
    29      }
    30  
    31      public void setCredentials(String username, String password) {
    32          this.username = username;
    33          this.password = password;
    34      }
    35  
    36    @Override
    37    public void apply(RequestTemplate template) {
    38        RequestInterceptor requestInterceptor = new BasicAuthRequestInterceptor(username, password);
    39        requestInterceptor.apply(template);
    40    }
    41  }