github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/resttemplate/auth/ApiKeyAuth.mustache (about) 1 package {{invokerPackage}}.auth; 2 3 import org.springframework.http.HttpHeaders; 4 import org.springframework.util.MultiValueMap; 5 6 {{>generatedAnnotation}} 7 public class ApiKeyAuth implements Authentication { 8 private final String location; 9 private final String paramName; 10 11 private String apiKey; 12 private String apiKeyPrefix; 13 14 public ApiKeyAuth(String location, String paramName) { 15 this.location = location; 16 this.paramName = paramName; 17 } 18 19 public String getLocation() { 20 return location; 21 } 22 23 public String getParamName() { 24 return paramName; 25 } 26 27 public String getApiKey() { 28 return apiKey; 29 } 30 31 public void setApiKey(String apiKey) { 32 this.apiKey = apiKey; 33 } 34 35 public String getApiKeyPrefix() { 36 return apiKeyPrefix; 37 } 38 39 public void setApiKeyPrefix(String apiKeyPrefix) { 40 this.apiKeyPrefix = apiKeyPrefix; 41 } 42 43 @Override 44 public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) { 45 if (apiKey == null) { 46 return; 47 } 48 String value; 49 if (apiKeyPrefix != null) { 50 value = apiKeyPrefix + " " + apiKey; 51 } else { 52 value = apiKey; 53 } 54 if (location.equals("query")) { 55 queryParams.add(paramName, value); 56 } else if (location.equals("header")) { 57 headerParams.add(paramName, value); 58 } else if (location.equals("cookie")) { 59 cookieParams.add(paramName, value); 60 } 61 } 62 }