diff --git a/modules/openapi-generator-maven-plugin/examples/multi-module/pom.xml b/modules/openapi-generator-maven-plugin/examples/multi-module/pom.xml index ecf4716707c8..c8a899829925 100644 --- a/modules/openapi-generator-maven-plugin/examples/multi-module/pom.xml +++ b/modules/openapi-generator-maven-plugin/examples/multi-module/pom.xml @@ -20,6 +20,6 @@ 2.7 1.0.0 4.8.1 - 1.3 + 1.4 diff --git a/modules/openapi-generator/src/main/resources/Java/README.mustache b/modules/openapi-generator/src/main/resources/Java/README.mustache index 917f873d5dce..85fd77af6422 100644 --- a/modules/openapi-generator/src/main/resources/Java/README.mustache +++ b/modules/openapi-generator/src/main/resources/Java/README.mustache @@ -104,7 +104,24 @@ public class {{{classname}}}Example { //{{{name}}}.setApiKeyPrefix("Token");{{/isApiKey}}{{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}"); - {{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}} + {{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}{{#isHttpSignature}} + // Configure HTTP signature authorization: {{{name}}} + HttpSignatureAuth {{{name}}} = (HttpSignatureAuth) defaultClient.getAuthentication("{{{name}}}"); + // All the HTTP signature parameters below should be customized to your environment. + // Configure the keyId + {{{name}}}.setKeyId("YOUR KEY ID"); + // Configure the signature algorithm + {{{name}}}.setSigningAlgorithm(SigningAlgorithm.HS2019); + // Configure the specific cryptographic algorithm + {{{name}}}.setAlgorithm(Algorithm.ECDSA_SHA256); + // Configure the cryptographic algorithm parameters, if applicable + {{{name}}}.setAlgorithmParameterSpec(null); + // Set the cryptographic digest algorithm. + {{{name}}}.setDigestAlgorithm("SHA-256"); + // Set the HTTP headers that should be included in the HTTP signature. + {{{name}}}.setHeaders(Arrays.asList("date", "host")); + // Set the private key used to sign the HTTP messages + {{{name}}}.setPrivateKey();{{/isHttpSignature}} {{/authMethods}} {{/hasAuthMethods}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache index e56e0d229106..75adbdbba3fd 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/auth/HttpSignatureAuth.mustache @@ -16,8 +16,12 @@ import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.List; +import java.security.spec.AlgorithmParameterSpec; -import org.tomitribe.auth.signatures.*; +import org.tomitribe.auth.signatures.Algorithm; +import org.tomitribe.auth.signatures.Signer; +import org.tomitribe.auth.signatures.Signature; +import org.tomitribe.auth.signatures.SigningAlgorithm; /** * A Configuration object for the HTTP message signature security scheme. @@ -30,8 +34,14 @@ public class HttpSignatureAuth implements Authentication { private String keyId; // The HTTP signature algorithm. + private SigningAlgorithm signingAlgorithm; + + // The HTTP cryptographic algorithm. private Algorithm algorithm; + // The cryptographic parameters. + private AlgorithmParameterSpec parameterSpec; + // The list of HTTP headers that should be included in the HTTP signature. private List headers; @@ -42,14 +52,23 @@ public class HttpSignatureAuth implements Authentication { * Construct a new HTTP signature auth configuration object. * * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - * @param algorithm The signature algorithm. + * @param signingAlgorithm The signature algorithm. + * @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. */ - public HttpSignatureAuth(String keyId, Algorithm algorithm, List headers) { + public HttpSignatureAuth(String keyId, + SigningAlgorithm signingAlgorithm, + Algorithm algorithm, + String digestAlgorithm, + AlgorithmParameterSpec parameterSpec, + List headers) { this.keyId = keyId; + this.signingAlgorithm = signingAlgorithm; this.algorithm = algorithm; + this.parameterSpec = parameterSpec; + this.digestAlgorithm = digestAlgorithm; this.headers = headers; - this.digestAlgorithm = "SHA-256"; } /** @@ -73,19 +92,51 @@ public class HttpSignatureAuth implements Authentication { /** * Returns the HTTP signature algorithm which is used to sign HTTP requests. */ - public Algorithm getAlgorithm() { - return algorithm; + public SigningAlgorithm getSigningAlgorithm() { + return signingAlgorithm; } /** * Sets the HTTP signature algorithm which is used to sign HTTP requests. * + * @param signingAlgorithm The HTTP signature algorithm. + */ + public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) { + this.signingAlgorithm = signingAlgorithm; + } + + /** + * Returns the HTTP cryptographic algorithm which is used to sign HTTP requests. + */ + public Algorithm getAlgorithm() { + return algorithm; + } + + /** + * Sets the HTTP cryptographic algorithm which is used to sign HTTP requests. + * * @param algorithm The HTTP signature algorithm. */ public void setAlgorithm(Algorithm algorithm) { this.algorithm = algorithm; } + /** + * Returns the cryptographic parameters which are used to sign HTTP requests. + */ + public AlgorithmParameterSpec getAlgorithmParameterSpec() { + return parameterSpec; + } + + /** + * Sets the cryptographic parameters which are used to sign HTTP requests. + * + * @param parameterSpec The cryptographic parameters. + */ + public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) { + this.parameterSpec = parameterSpec; + } + /** * Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. * @@ -127,10 +178,20 @@ public class HttpSignatureAuth implements Authentication { this.headers = headers; } + /** + * Returns the signer instance used to sign HTTP messages. + * + * @returrn the signer instance. + */ public Signer getSigner() { return signer; } + /** + * Sets the signer instance used to sign HTTP messages. + * + * @param signer The signer instance to set. + */ public void setSigner(Signer signer) { this.signer = signer; } @@ -145,7 +206,7 @@ public class HttpSignatureAuth implements Authentication { throw new ApiException("Private key (java.security.Key) cannot be null"); } - signer = new Signer(key, new Signature(keyId, algorithm, null, headers)); + signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers)); } @Override diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache index 9030427467c8..707c31284841 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache @@ -385,7 +385,7 @@ 2.9.10 {{/threetenbp}} 4.13 - 1.3 + 1.4 {{#hasOAuthMethods}} 6.9.0 {{/hasOAuthMethods}} diff --git a/samples/client/petstore/java/jersey2-java7/pom.xml b/samples/client/petstore/java/jersey2-java7/pom.xml index 2e89bebce3ff..f299e5a8b38b 100644 --- a/samples/client/petstore/java/jersey2-java7/pom.xml +++ b/samples/client/petstore/java/jersey2-java7/pom.xml @@ -306,7 +306,7 @@ 0.2.1 2.9.10 4.13 - 1.3 + 1.4 6.9.0 diff --git a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java index 336d15934686..628ba5c18df5 100644 --- a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java +++ b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java @@ -27,8 +27,12 @@ import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.List; +import java.security.spec.AlgorithmParameterSpec; -import org.tomitribe.auth.signatures.*; +import org.tomitribe.auth.signatures.Algorithm; +import org.tomitribe.auth.signatures.Signer; +import org.tomitribe.auth.signatures.Signature; +import org.tomitribe.auth.signatures.SigningAlgorithm; /** * A Configuration object for the HTTP message signature security scheme. @@ -41,8 +45,14 @@ public class HttpSignatureAuth implements Authentication { private String keyId; // The HTTP signature algorithm. + private SigningAlgorithm signingAlgorithm; + + // The HTTP cryptographic algorithm. private Algorithm algorithm; + // The cryptographic parameters. + private AlgorithmParameterSpec parameterSpec; + // The list of HTTP headers that should be included in the HTTP signature. private List headers; @@ -53,14 +63,23 @@ public class HttpSignatureAuth implements Authentication { * Construct a new HTTP signature auth configuration object. * * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - * @param algorithm The signature algorithm. + * @param signingAlgorithm The signature algorithm. + * @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. */ - public HttpSignatureAuth(String keyId, Algorithm algorithm, List headers) { + public HttpSignatureAuth(String keyId, + SigningAlgorithm signingAlgorithm, + Algorithm algorithm, + String digestAlgorithm, + AlgorithmParameterSpec parameterSpec, + List headers) { this.keyId = keyId; + this.signingAlgorithm = signingAlgorithm; this.algorithm = algorithm; + this.parameterSpec = parameterSpec; + this.digestAlgorithm = digestAlgorithm; this.headers = headers; - this.digestAlgorithm = "SHA-256"; } /** @@ -84,19 +103,51 @@ public class HttpSignatureAuth implements Authentication { /** * Returns the HTTP signature algorithm which is used to sign HTTP requests. */ - public Algorithm getAlgorithm() { - return algorithm; + public SigningAlgorithm getSigningAlgorithm() { + return signingAlgorithm; } /** * Sets the HTTP signature algorithm which is used to sign HTTP requests. * + * @param signingAlgorithm The HTTP signature algorithm. + */ + public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) { + this.signingAlgorithm = signingAlgorithm; + } + + /** + * Returns the HTTP cryptographic algorithm which is used to sign HTTP requests. + */ + public Algorithm getAlgorithm() { + return algorithm; + } + + /** + * Sets the HTTP cryptographic algorithm which is used to sign HTTP requests. + * * @param algorithm The HTTP signature algorithm. */ public void setAlgorithm(Algorithm algorithm) { this.algorithm = algorithm; } + /** + * Returns the cryptographic parameters which are used to sign HTTP requests. + */ + public AlgorithmParameterSpec getAlgorithmParameterSpec() { + return parameterSpec; + } + + /** + * Sets the cryptographic parameters which are used to sign HTTP requests. + * + * @param parameterSpec The cryptographic parameters. + */ + public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) { + this.parameterSpec = parameterSpec; + } + /** * Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. * @@ -138,10 +189,20 @@ public class HttpSignatureAuth implements Authentication { this.headers = headers; } + /** + * Returns the signer instance used to sign HTTP messages. + * + * @returrn the signer instance. + */ public Signer getSigner() { return signer; } + /** + * Sets the signer instance used to sign HTTP messages. + * + * @param signer The signer instance to set. + */ public void setSigner(Signer signer) { this.signer = signer; } @@ -156,7 +217,7 @@ public class HttpSignatureAuth implements Authentication { throw new ApiException("Private key (java.security.Key) cannot be null"); } - signer = new Signer(key, new Signature(keyId, algorithm, null, headers)); + signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers)); } @Override diff --git a/samples/client/petstore/java/jersey2-java8/pom.xml b/samples/client/petstore/java/jersey2-java8/pom.xml index 4bf52a3ef02d..f3a8ffe108b6 100644 --- a/samples/client/petstore/java/jersey2-java8/pom.xml +++ b/samples/client/petstore/java/jersey2-java8/pom.xml @@ -299,7 +299,7 @@ 2.10.4 0.2.1 4.13 - 1.3 + 1.4 6.9.0 diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java index 336d15934686..628ba5c18df5 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java @@ -27,8 +27,12 @@ import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.List; +import java.security.spec.AlgorithmParameterSpec; -import org.tomitribe.auth.signatures.*; +import org.tomitribe.auth.signatures.Algorithm; +import org.tomitribe.auth.signatures.Signer; +import org.tomitribe.auth.signatures.Signature; +import org.tomitribe.auth.signatures.SigningAlgorithm; /** * A Configuration object for the HTTP message signature security scheme. @@ -41,8 +45,14 @@ public class HttpSignatureAuth implements Authentication { private String keyId; // The HTTP signature algorithm. + private SigningAlgorithm signingAlgorithm; + + // The HTTP cryptographic algorithm. private Algorithm algorithm; + // The cryptographic parameters. + private AlgorithmParameterSpec parameterSpec; + // The list of HTTP headers that should be included in the HTTP signature. private List headers; @@ -53,14 +63,23 @@ public class HttpSignatureAuth implements Authentication { * Construct a new HTTP signature auth configuration object. * * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - * @param algorithm The signature algorithm. + * @param signingAlgorithm The signature algorithm. + * @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. */ - public HttpSignatureAuth(String keyId, Algorithm algorithm, List headers) { + public HttpSignatureAuth(String keyId, + SigningAlgorithm signingAlgorithm, + Algorithm algorithm, + String digestAlgorithm, + AlgorithmParameterSpec parameterSpec, + List headers) { this.keyId = keyId; + this.signingAlgorithm = signingAlgorithm; this.algorithm = algorithm; + this.parameterSpec = parameterSpec; + this.digestAlgorithm = digestAlgorithm; this.headers = headers; - this.digestAlgorithm = "SHA-256"; } /** @@ -84,19 +103,51 @@ public class HttpSignatureAuth implements Authentication { /** * Returns the HTTP signature algorithm which is used to sign HTTP requests. */ - public Algorithm getAlgorithm() { - return algorithm; + public SigningAlgorithm getSigningAlgorithm() { + return signingAlgorithm; } /** * Sets the HTTP signature algorithm which is used to sign HTTP requests. * + * @param signingAlgorithm The HTTP signature algorithm. + */ + public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) { + this.signingAlgorithm = signingAlgorithm; + } + + /** + * Returns the HTTP cryptographic algorithm which is used to sign HTTP requests. + */ + public Algorithm getAlgorithm() { + return algorithm; + } + + /** + * Sets the HTTP cryptographic algorithm which is used to sign HTTP requests. + * * @param algorithm The HTTP signature algorithm. */ public void setAlgorithm(Algorithm algorithm) { this.algorithm = algorithm; } + /** + * Returns the cryptographic parameters which are used to sign HTTP requests. + */ + public AlgorithmParameterSpec getAlgorithmParameterSpec() { + return parameterSpec; + } + + /** + * Sets the cryptographic parameters which are used to sign HTTP requests. + * + * @param parameterSpec The cryptographic parameters. + */ + public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) { + this.parameterSpec = parameterSpec; + } + /** * Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. * @@ -138,10 +189,20 @@ public class HttpSignatureAuth implements Authentication { this.headers = headers; } + /** + * Returns the signer instance used to sign HTTP messages. + * + * @returrn the signer instance. + */ public Signer getSigner() { return signer; } + /** + * Sets the signer instance used to sign HTTP messages. + * + * @param signer The signer instance to set. + */ public void setSigner(Signer signer) { this.signer = signer; } @@ -156,7 +217,7 @@ public class HttpSignatureAuth implements Authentication { throw new ApiException("Private key (java.security.Key) cannot be null"); } - signer = new Signer(key, new Signature(keyId, algorithm, null, headers)); + signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers)); } @Override