Skip to content

Commit 6dfd029

Browse files
[java][jersey2] Add support for (expires) and (created) fields in HTTP signature (#6632)
* Add support for (expires) and (created) fields in HTTP signature * Add support for (expires) and (created) fields in HTTP signature
1 parent 6041acd commit 6dfd029

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class HttpSignatureAuth implements Authentication {
4949
// The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
5050
private String digestAlgorithm;
5151
52+
// The maximum validity duration of the HTTP signature.
53+
private Long maxSignatureValidity;
54+
5255
/**
5356
* Construct a new HTTP signature auth configuration object.
5457
*
@@ -57,19 +60,23 @@ public class HttpSignatureAuth implements Authentication {
5760
* @param algorithm The cryptographic algorithm.
5861
* @param digestAlgorithm The digest algorithm.
5962
* @param headers The list of HTTP headers that should be included in the HTTP signature.
63+
* @param maxSignatureValidity The maximum validity duration of the HTTP signature.
64+
* Used to set the '(expires)' field in the HTTP signature.
6065
*/
6166
public HttpSignatureAuth(String keyId,
6267
SigningAlgorithm signingAlgorithm,
6368
Algorithm algorithm,
6469
String digestAlgorithm,
6570
AlgorithmParameterSpec parameterSpec,
66-
List<String> headers) {
71+
List<String> headers,
72+
Long maxSignatureValidity) {
6773
this.keyId = keyId;
6874
this.signingAlgorithm = signingAlgorithm;
6975
this.algorithm = algorithm;
7076
this.parameterSpec = parameterSpec;
7177
this.digestAlgorithm = digestAlgorithm;
7278
this.headers = headers;
79+
this.maxSignatureValidity = maxSignatureValidity;
7380
}
7481

7582
/**
@@ -179,6 +186,14 @@ public class HttpSignatureAuth implements Authentication {
179186
this.headers = headers;
180187
}
181188

189+
/**
190+
* Returns the maximum validity duration of the HTTP signature.
191+
* @return The maximum validity duration of the HTTP signature.
192+
*/
193+
public Long getMaxSignatureValidity() {
194+
return maxSignatureValidity;
195+
}
196+
182197
/**
183198
* Returns the signer instance used to sign HTTP messages.
184199
*
@@ -209,7 +224,7 @@ public class HttpSignatureAuth implements Authentication {
209224
if (key == null) {
210225
throw new ApiException("Private key (java.security.Key) cannot be null");
211226
}
212-
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers));
227+
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers, maxSignatureValidity));
213228
}
214229

215230
@Override

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@
407407
<javax-annotation-version>1.3.2</javax-annotation-version>
408408
<junit-version>4.13</junit-version>
409409
{{#hasHttpSignatureMethods}}
410-
<http-signature-version>1.4</http-signature-version>
410+
<http-signature-version>1.5</http-signature-version>
411411
{{/hasHttpSignatureMethods}}
412412
{{#hasOAuthMethods}}
413413
<scribejava-apis-version>6.9.0</scribejava-apis-version>

samples/openapi3/client/petstore/java/jersey2-java8/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
<jackson-databind-nullable-version>0.2.1</jackson-databind-nullable-version>
309309
<javax-annotation-version>1.3.2</javax-annotation-version>
310310
<junit-version>4.13</junit-version>
311-
<http-signature-version>1.4</http-signature-version>
311+
<http-signature-version>1.5</http-signature-version>
312312
<scribejava-apis-version>6.9.0</scribejava-apis-version>
313313
</properties>
314314
</project>

samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class HttpSignatureAuth implements Authentication {
6060
// The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
6161
private String digestAlgorithm;
6262

63+
// The maximum validity duration of the HTTP signature.
64+
private Long maxSignatureValidity;
65+
6366
/**
6467
* Construct a new HTTP signature auth configuration object.
6568
*
@@ -68,19 +71,23 @@ public class HttpSignatureAuth implements Authentication {
6871
* @param algorithm The cryptographic algorithm.
6972
* @param digestAlgorithm The digest algorithm.
7073
* @param headers The list of HTTP headers that should be included in the HTTP signature.
74+
* @param maxSignatureValidity The maximum validity duration of the HTTP signature.
75+
* Used to set the '(expires)' field in the HTTP signature.
7176
*/
7277
public HttpSignatureAuth(String keyId,
7378
SigningAlgorithm signingAlgorithm,
7479
Algorithm algorithm,
7580
String digestAlgorithm,
7681
AlgorithmParameterSpec parameterSpec,
77-
List<String> headers) {
82+
List<String> headers,
83+
Long maxSignatureValidity) {
7884
this.keyId = keyId;
7985
this.signingAlgorithm = signingAlgorithm;
8086
this.algorithm = algorithm;
8187
this.parameterSpec = parameterSpec;
8288
this.digestAlgorithm = digestAlgorithm;
8389
this.headers = headers;
90+
this.maxSignatureValidity = maxSignatureValidity;
8491
}
8592

8693
/**
@@ -190,6 +197,14 @@ public void setHeaders(List<String> headers) {
190197
this.headers = headers;
191198
}
192199

200+
/**
201+
* Returns the maximum validity duration of the HTTP signature.
202+
* @return The maximum validity duration of the HTTP signature.
203+
*/
204+
public Long getMaxSignatureValidity() {
205+
return maxSignatureValidity;
206+
}
207+
193208
/**
194209
* Returns the signer instance used to sign HTTP messages.
195210
*
@@ -220,7 +235,7 @@ public void setPrivateKey(Key key) throws InvalidKeyException, ApiException {
220235
if (key == null) {
221236
throw new ApiException("Private key (java.security.Key) cannot be null");
222237
}
223-
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers));
238+
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers, maxSignatureValidity));
224239
}
225240

226241
@Override

0 commit comments

Comments
 (0)