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

[CORE] Add support for HTTP signature #4993

Merged
merged 25 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d626293
Add support for HTTP signature
sebastien-rosset Jan 13, 2020
9eca52c
Add code comments
sebastien-rosset Jan 13, 2020
a59f759
Add code comments
sebastien-rosset Jan 13, 2020
9e6395f
add code comments
sebastien-rosset Jan 14, 2020
d8175a0
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 14, 2020
acfb44d
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 15, 2020
bb12421
move method to ProcessUtils
sebastien-rosset Jan 15, 2020
7c1967e
Code reformatting
sebastien-rosset Jan 16, 2020
755335c
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 16, 2020
1bf286f
Add http-signature security scheme
sebastien-rosset Jan 17, 2020
5170195
Run sample scripts for go
sebastien-rosset Jan 17, 2020
ef59c0c
add http_signature_test to security scheme
sebastien-rosset Jan 17, 2020
0f7cbb1
Merge branch 'master' into http-signature
sebastien-rosset Jan 17, 2020
f8dea28
remove http signature from petapi
sebastien-rosset Jan 17, 2020
21e35f0
Add separate OAS file with support for HTTP signature
sebastien-rosset Jan 17, 2020
daf060e
remove http signature from petstore-with-fake-endpoints-models-for-te…
sebastien-rosset Jan 17, 2020
1b1aef6
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 19, 2020
4f7e6eb
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 19, 2020
066237f
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 20, 2020
34f126f
do not throw exception if security scheme is unrecognized
sebastien-rosset Jan 20, 2020
7b3a54b
change URL of apache license to use https
sebastien-rosset Jan 21, 2020
d8b0dc6
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 22, 2020
7d89594
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 23, 2020
9054137
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 24, 2020
0ca756e
add log warning to indicate the 'http signature' security scheme is s…
sebastien-rosset Jan 24, 2020
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 @@ -29,8 +29,11 @@ public class CodegenSecurity {
public String type;
public String scheme;
public Boolean hasMore, isBasic, isOAuth, isApiKey;
// is Basic is true for all http authentication type. Those are to differentiate basic and bearer authentication
public Boolean isBasicBasic, isBasicBearer;
// is Basic is true for all http authentication type.
// Those are to differentiate basic and bearer authentication
// isHttpSignature is to support HTTP signature authorization scheme.
// https://datatracker.ietf.org/doc/draft-cavage-http-signatures/
public Boolean isBasicBasic, isBasicBearer, isHttpSignature;
public String bearerFormat;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
// ApiKey specific
Expand All @@ -50,6 +53,7 @@ public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
filteredSecurity.hasMore = false;
filteredSecurity.isBasic = isBasic;
filteredSecurity.isBasicBasic = isBasicBasic;
filteredSecurity.isHttpSignature = isHttpSignature;
filteredSecurity.isBasicBearer = isBasicBearer;
filteredSecurity.isApiKey = isApiKey;
filteredSecurity.isOAuth = isOAuth;
Expand Down Expand Up @@ -97,6 +101,7 @@ public boolean equals(Object o) {
Objects.equals(isOAuth, that.isOAuth) &&
Objects.equals(isApiKey, that.isApiKey) &&
Objects.equals(isBasicBasic, that.isBasicBasic) &&
Objects.equals(isHttpSignature, that.isHttpSignature) &&
Objects.equals(isBasicBearer, that.isBasicBearer) &&
Objects.equals(bearerFormat, that.bearerFormat) &&
Objects.equals(vendorExtensions, that.vendorExtensions) &&
Expand All @@ -117,8 +122,9 @@ public boolean equals(Object o) {
@Override
public int hashCode() {

return Objects.hash(name, type, scheme, hasMore, isBasic, isOAuth, isApiKey, isBasicBasic, isBasicBearer,
bearerFormat, vendorExtensions, keyParamName, isKeyInQuery, isKeyInHeader, isKeyInCookie, flow,
return Objects.hash(name, type, scheme, hasMore, isBasic, isOAuth, isApiKey,
isBasicBasic, isHttpSignature, isBasicBearer, bearerFormat, vendorExtensions,
keyParamName, isKeyInQuery, isKeyInHeader, isKeyInCookie, flow,
authorizationUrl, tokenUrl, scopes, isCode, isPassword, isApplication, isImplicit);
}

Expand All @@ -133,6 +139,7 @@ public String toString() {
sb.append(", isOAuth=").append(isOAuth);
sb.append(", isApiKey=").append(isApiKey);
sb.append(", isBasicBasic=").append(isBasicBasic);
sb.append(", isHttpSignature=").append(isHttpSignature);
sb.append(", isBasicBearer=").append(isBasicBearer);
sb.append(", bearerFormat='").append(bearerFormat).append('\'');
sb.append(", vendorExtensions=").append(vendorExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,7 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySc
cs.name = key;
cs.type = securityScheme.getType().toString();
cs.isCode = cs.isPassword = cs.isApplication = cs.isImplicit = false;
cs.isHttpSignature = false;
cs.isBasicBasic = cs.isBasicBearer = false;
cs.scheme = securityScheme.getScheme();
if (securityScheme.getExtensions() != null) {
Expand All @@ -3638,6 +3639,14 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySc
} else if ("bearer".equals(securityScheme.getScheme())) {
cs.isBasicBearer = true;
cs.bearerFormat = securityScheme.getBearerFormat();
} else if ("signature".equals(securityScheme.getScheme())) {
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
// HTTP signature as defined in https://datatracker.ietf.org/doc/draft-cavage-http-signatures/
// The registry of security schemes is maintained by IANA.
// https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml
// As of January 2020, the "signature" scheme has not been registered with IANA yet.
// This scheme may have to be changed when it is officially registered with IANA.
cs.isHttpSignature = true;
LOGGER.warn("Security scheme 'HTTP signature' is a draft IETF RFC and subject to change.");
}
} else if (SecurityScheme.Type.OAUTH2.equals(securityScheme.getType())) {
cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isBasic = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.openapitools.codegen.templating.MustacheEngineAdapter;
import org.openapitools.codegen.utils.ImplementationVersion;
import org.openapitools.codegen.utils.ModelUtils;
import org.openapitools.codegen.utils.ProcessUtils;
import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -851,6 +852,9 @@ private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, L
if (hasBearerMethods(authMethods)) {
bundle.put("hasBearerMethods", true);
}
if (ProcessUtils.hasHttpSignatureMethods(authMethods)) {
bundle.put("hasHttpSignatureMethods", true);
}
}

List<CodegenServer> servers = config.fromServers(openAPI.getServers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,22 @@ public static boolean hasBearerMethods(Map<String, Object> objs) {
return false;
}

/**
* Returns true if the specified OAS model has at least one operation with the HTTP signature
* security scheme.
* The HTTP signature scheme is defined in https://datatracker.ietf.org/doc/draft-cavage-http-signatures/
*
* @param authMethods List of auth methods.
* @return True if at least one operation has HTTP signature security schema defined
*/
public static boolean hasHttpSignatureMethods(List<CodegenSecurity> authMethods) {
if (authMethods != null && !authMethods.isEmpty()) {
for (CodegenSecurity cs : authMethods) {
if (Boolean.TRUE.equals(cs.isHttpSignature)) {
return true;
}
}
}
return false;
}
}
Loading