[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
This commit is contained in:
Sebastien Rosset
2020-06-28 08:14:22 -07:00
committed by GitHub
parent 6041acd225
commit 6dfd029c63
4 changed files with 36 additions and 6 deletions

View File

@@ -308,7 +308,7 @@
<jackson-databind-nullable-version>0.2.1</jackson-databind-nullable-version>
<javax-annotation-version>1.3.2</javax-annotation-version>
<junit-version>4.13</junit-version>
<http-signature-version>1.4</http-signature-version>
<http-signature-version>1.5</http-signature-version>
<scribejava-apis-version>6.9.0</scribejava-apis-version>
</properties>
</project>

View File

@@ -60,6 +60,9 @@ public class HttpSignatureAuth implements Authentication {
// The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
private String digestAlgorithm;
// The maximum validity duration of the HTTP signature.
private Long maxSignatureValidity;
/**
* Construct a new HTTP signature auth configuration object.
*
@@ -68,19 +71,23 @@ public class HttpSignatureAuth implements Authentication {
* @param algorithm The cryptographic algorithm.
* @param digestAlgorithm The digest algorithm.
* @param headers The list of HTTP headers that should be included in the HTTP signature.
* @param maxSignatureValidity The maximum validity duration of the HTTP signature.
* Used to set the '(expires)' field in the HTTP signature.
*/
public HttpSignatureAuth(String keyId,
SigningAlgorithm signingAlgorithm,
Algorithm algorithm,
String digestAlgorithm,
AlgorithmParameterSpec parameterSpec,
List<String> headers) {
List<String> headers,
Long maxSignatureValidity) {
this.keyId = keyId;
this.signingAlgorithm = signingAlgorithm;
this.algorithm = algorithm;
this.parameterSpec = parameterSpec;
this.digestAlgorithm = digestAlgorithm;
this.headers = headers;
this.maxSignatureValidity = maxSignatureValidity;
}
/**
@@ -190,6 +197,14 @@ public class HttpSignatureAuth implements Authentication {
this.headers = headers;
}
/**
* Returns the maximum validity duration of the HTTP signature.
* @return The maximum validity duration of the HTTP signature.
*/
public Long getMaxSignatureValidity() {
return maxSignatureValidity;
}
/**
* Returns the signer instance used to sign HTTP messages.
*
@@ -220,7 +235,7 @@ public class HttpSignatureAuth implements Authentication {
if (key == null) {
throw new ApiException("Private key (java.security.Key) cannot be null");
}
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers));
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers, maxSignatureValidity));
}
@Override