Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java-jersey2] Add new ApiClient constructor with auth objects #6393

Merged
merged 13 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,19 @@ public class ApiClient {

protected DateFormat dateFormat;

/**
* Constructs a new ApiClient with default parameters.
*/
public ApiClient() {
this(null);
}

/**
* Constructs a new ApiClient with the specified authentication parameters.
*
* @param authMap A hash map containing authentication parameters.
*/
public ApiClient(Map<String, Authentication> authMap) {
json = new JSON();
httpClient = buildHttpClient(debugging);

Expand All @@ -163,23 +175,47 @@ public class ApiClient {

// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
Authentication auth = null;
{{#authMethods}}
if (authMap != null) {
auth = authMap.get("{{name}}");
}
{{#isBasic}}
{{#isBasicBasic}}
authentications.put("{{name}}", new HttpBasicAuth());
if (auth instanceof HttpBasicAuth) {
authentications.put("{{name}}", auth);
} else {
authentications.put("{{name}}", new HttpBasicAuth());
}
{{/isBasicBasic}}
{{#isBasicBearer}}
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
if (auth instanceof HttpBearerAuth) {
authentications.put("{{name}}", auth);
} else {
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
}
{{/isBasicBearer}}
{{#isHttpSignature}}
authentications.put("{{name}}", new HttpSignatureAuth("{{name}}", null, null));
if (auth instanceof HttpSignatureAuth) {
authentications.put("{{name}}", auth);
} else {
authentications.put("{{name}}", null);
}
{{/isHttpSignature}}
{{/isBasic}}
{{#isApiKey}}
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
if (auth instanceof ApiKeyAuth) {
authentications.put("{{name}}", auth);
} else {
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
}
{{/isApiKey}}
{{#isOAuth}}
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
if (auth instanceof OAuth) {
authentications.put("{{name}}", auth);
} else {
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
}
{{/isOAuth}}
{{/authMethods}}
// Prevent the authentications from being modified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ public class ApiClient {

protected DateFormat dateFormat;

/**
* Constructs a new ApiClient with default parameters.
*/
public ApiClient() {
this(null);
}

/**
* Constructs a new ApiClient with the specified authentication parameters.
*
* @param authMap A hash map containing authentication parameters.
*/
public ApiClient(Map<String, Authentication> authMap) {
json = new JSON();
httpClient = buildHttpClient(debugging);

Expand All @@ -98,10 +110,39 @@ public ApiClient() {

// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth(basePath, ""));
Authentication auth = null;
if (authMap != null) {
auth = authMap.get("api_key");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key", auth);
} else {
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
}
if (authMap != null) {
auth = authMap.get("api_key_query");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key_query", auth);
} else {
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
}
if (authMap != null) {
auth = authMap.get("http_basic_test");
}
if (auth instanceof HttpBasicAuth) {
authentications.put("http_basic_test", auth);
} else {
authentications.put("http_basic_test", new HttpBasicAuth());
}
if (authMap != null) {
auth = authMap.get("petstore_auth");
}
if (auth instanceof OAuth) {
authentications.put("petstore_auth", auth);
} else {
authentications.put("petstore_auth", new OAuth(basePath, ""));
}
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ public class ApiClient {

protected DateFormat dateFormat;

/**
* Constructs a new ApiClient with default parameters.
*/
public ApiClient() {
this(null);
}

/**
* Constructs a new ApiClient with the specified authentication parameters.
*
* @param authMap A hash map containing authentication parameters.
*/
public ApiClient(Map<String, Authentication> authMap) {
json = new JSON();
httpClient = buildHttpClient(debugging);

Expand All @@ -98,10 +110,39 @@ public ApiClient() {

// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth(basePath, ""));
Authentication auth = null;
if (authMap != null) {
auth = authMap.get("api_key");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key", auth);
} else {
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
}
if (authMap != null) {
auth = authMap.get("api_key_query");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key_query", auth);
} else {
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
}
if (authMap != null) {
auth = authMap.get("http_basic_test");
}
if (auth instanceof HttpBasicAuth) {
authentications.put("http_basic_test", auth);
} else {
authentications.put("http_basic_test", new HttpBasicAuth());
}
if (authMap != null) {
auth = authMap.get("petstore_auth");
}
if (auth instanceof OAuth) {
authentications.put("petstore_auth", auth);
} else {
authentications.put("petstore_auth", new OAuth(basePath, ""));
}
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);

Expand Down