Jersey2: Move setting of authentication parameters before generating target URL to consider API keys in URL parameters (#20688)

* Move setting of authentication parameters before generating target URL to consider API keys in URL parameters

* Regenerate Jersey2/3 examples
This commit is contained in:
jheyens 2025-04-23 10:04:26 +02:00 committed by GitHub
parent d2e20253e4
commit e767496357
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 218 additions and 218 deletions

View File

@ -1233,6 +1233,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1263,27 +1284,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1233,6 +1233,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1263,27 +1284,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
{{#hasHttpSignatureMethods}}
serializeToString(body, formParams, contentType, isBodyNullable),
{{/hasHttpSignatureMethods}}
{{^hasHttpSignatureMethods}}
null,
{{/hasHttpSignatureMethods}}
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1012,6 +1012,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1042,22 +1058,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1012,6 +1012,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1042,22 +1058,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1153,6 +1153,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1183,22 +1199,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1153,6 +1153,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1183,22 +1199,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1012,6 +1012,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1042,22 +1058,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1235,6 +1235,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
serializeToString(body, formParams, contentType, isBodyNullable),
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1265,22 +1281,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
serializeToString(body, formParams, contentType, isBodyNullable),
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1061,6 +1061,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1091,22 +1107,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1012,6 +1012,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1042,22 +1058,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1137,6 +1137,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1167,22 +1183,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1137,6 +1137,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1167,22 +1183,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {

View File

@ -1235,6 +1235,22 @@ public class ApiClient extends JavaTimeFormatter {
// to support (constant) query string in `path`, e.g. "/posts?draft=1" // to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL); WebTarget target = httpClient.target(targetURL);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
serializeToString(body, formParams, contentType, isBodyNullable),
method,
target.getUri());
}
if (queryParams != null) { if (queryParams != null) {
for (Pair queryParam : queryParams) { for (Pair queryParam : queryParams) {
if (queryParam.getValue() != null) { if (queryParam.getValue() != null) {
@ -1265,22 +1281,6 @@ public class ApiClient extends JavaTimeFormatter {
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable); Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
// put all headers in one place
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
serializeToString(body, formParams, contentType, isBodyNullable),
method,
target.getUri());
}
for (Entry<String, String> entry : allHeaderParams.entrySet()) { for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue(); String value = entry.getValue();
if (value != null) { if (value != null) {