mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-16 08:31:26 +00:00
Add authentication helper methods and test cases
This commit is contained in:
@@ -24,4 +24,48 @@ public class Configuration {
|
||||
public static Authentication getAuthentication(String authName) {
|
||||
return AUTH.get(authName);
|
||||
}
|
||||
|
||||
/** Set username for the first HTTP basic authentication. */
|
||||
public static void setUsername(String username) {
|
||||
for (Authentication auth : AUTH.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/** Set password for the first HTTP basic authentication. */
|
||||
public static void setPassword(String password) {
|
||||
for (Authentication auth : AUTH.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/** Set API key value for the first API key authentication. */
|
||||
public static void setApiKey(String apiKey) {
|
||||
for (Authentication auth : AUTH.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/** Set API key prefix for the first API key authentication. */
|
||||
public static void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : AUTH.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user