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

Adjust auth scheme name for compatibility #392

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -77,7 +77,7 @@ public Map<String, List<String>> updateSecurity(
) {
// Only modify requirements that exactly match the updated scheme.
if (requirement.size() != 1
|| !requirement.keySet().iterator().next().equals(converter.getAuthSchemeId().toString())) {
|| !requirement.keySet().iterator().next().equals(converter.getOpenApiAuthSchemeName())) {
return requirement;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"aws.auth#cognitoUserPools": {
"aws.auth.cognitoUserPools": {
"type": "apiKey",
"description": "Amazon Cognito User Pools authentication",
"name": "Authorization",
Expand All @@ -35,7 +35,7 @@
},
"security": [
{
"aws.auth#cognitoUserPools": [ ]
"aws.auth.cognitoUserPools": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"components": {
"securitySchemes": {
"smithy.api#httpBasicAuth": {
"smithy.api.httpBasicAuth": {
"type": "http",
"description": "HTTP Basic authentication",
"scheme": "Basic"
Expand All @@ -82,7 +82,7 @@
},
"security": [
{
"smithy.api#httpBasicAuth": [ ]
"smithy.api.httpBasicAuth": [ ]
}
],
"x-amazon-apigateway-gateway-responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@
}
},
"securitySchemes": {
"aws.auth#sigv4": {
"aws.auth.sigv4": {
"type": "apiKey",
"description": "AWS Signature Version 4 authentication",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "awsSigv4"
},
"smithy.api#httpBasicAuth": {
"smithy.api.httpBasicAuth": {
"type": "http",
"description": "HTTP Basic authentication",
"scheme": "Basic"
Expand All @@ -405,10 +405,10 @@
},
"security": [
{
"smithy.api#httpBasicAuth": [ ]
"smithy.api.httpBasicAuth": [ ]
},
{
"aws.auth#sigv4": [ ]
"aws.auth.sigv4": [ ]
}
],
"x-amazon-apigateway-gateway-responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"components": {
"securitySchemes": {
"smithy.api#httpBasicAuth": {
"smithy.api.httpBasicAuth": {
"type": "http",
"description": "HTTP Basic authentication",
"scheme": "Basic"
Expand All @@ -82,7 +82,7 @@
},
"security": [
{
"smithy.api#httpBasicAuth": [ ]
"smithy.api.httpBasicAuth": [ ]
}
],
"x-amazon-apigateway-gateway-responses": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"aws.auth#cognitoUserPools": {
"aws.auth.cognitoUserPools": {
"type": "apiKey",
"description": "Amazon Cognito User Pools authentication",
"name": "Authorization",
Expand All @@ -36,7 +36,7 @@
},
"security": [
{
"aws.auth#cognitoUserPools": [ ]
"aws.auth.cognitoUserPools": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"aws.auth#cognitoUserPools": {
"aws.auth.cognitoUserPools": {
"type": "apiKey",
"description": "Amazon Cognito User Pools authentication",
"name": "Authorization",
Expand All @@ -36,7 +36,7 @@
},
"security": [
{
"aws.auth#cognitoUserPools": [ ]
"aws.auth.cognitoUserPools": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ private <T extends Trait> void addOperationSecurity(
context, authSchemeClasses);
for (SecuritySchemeConverter<? extends Trait> converter : converters) {
List<String> result = createSecurityRequirements(context, converter, service);
String openApiAuthName = converter.getAuthSchemeId().toString();
String openApiAuthName = converter.getOpenApiAuthSchemeName();
Map<String, List<String>> authMap = MapUtils.of(openApiAuthName, result);
Map<String, List<String>> requirement = plugin.updateSecurity(context, shape, converter, authMap);
if (requirement != null) {
Expand Down Expand Up @@ -625,7 +625,7 @@ private <T extends Trait> void addSecurityComponents(
for (SecuritySchemeConverter<? extends Trait> converter : context.getSecuritySchemeConverters()) {
SecurityScheme createdScheme = createAndUpdateSecurityScheme(context, plugin, converter, service);
if (createdScheme != null) {
components.putSecurityScheme(converter.getAuthSchemeId().toString(), createdScheme);
components.putSecurityScheme(converter.getOpenApiAuthSchemeName(), createdScheme);
}
}

Expand All @@ -637,7 +637,7 @@ private <T extends Trait> void addSecurityComponents(
for (SecuritySchemeConverter<? extends Trait> converter : context.getSecuritySchemeConverters()) {
if (defaultAuthTraits.contains(converter.getAuthSchemeType())) {
List<String> result = createSecurityRequirements(context, converter, context.getService());
String authSchemeName = converter.getAuthSchemeId().toString();
String authSchemeName = converter.getOpenApiAuthSchemeName();
Map<String, List<String>> requirement = plugin.updateSecurity(
context, context.getService(), converter, MapUtils.of(authSchemeName, result));
if (requirement != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ default List<String> createSecurityRequirements(Context<? extends Trait> context
return ListUtils.of();
}

/**
* Gets the name of OpenApi auth scheme.
*
* <p>For compatibility with Amazon API Gateway, the `#` is replaced with
* an `.` when deriving the name from the auth scheme's shape ID.
*
* @return Returns the auth scheme's name.
*/
default String getOpenApiAuthSchemeName() {
return getAuthSchemeId().toString().replace("#", ".");
}

/**
* Gets the names of the headers set on HTTP requests used by this
* authentication scheme.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"security": [
{
"smithy.api#httpBasicAuth": [ ]
"smithy.api.httpBasicAuth": [ ]
}
]
}
Expand All @@ -40,23 +40,23 @@
},
"security": [
{
"smithy.api#httpBasicAuth": []
"smithy.api.httpBasicAuth": []
},
{
"aws.auth#sigv4": [ ]
"aws.auth.sigv4": [ ]
}
]
}
}
},
"components": {
"securitySchemes": {
"smithy.api#httpBasicAuth": {
"smithy.api.httpBasicAuth": {
"type": "http",
"description": "HTTP Basic authentication",
"scheme": "Basic"
},
"aws.auth#sigv4": {
"aws.auth.sigv4": {
"type": "apiKey",
"description": "AWS Signature Version 4 authentication",
"name": "Authorization",
Expand All @@ -67,7 +67,7 @@
},
"security": [
{
"aws.auth#sigv4": [ ]
"aws.auth.sigv4": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"aws.auth#sigv4": {
"aws.auth.sigv4": {
"type": "apiKey",
"description": "AWS Signature Version 4 authentication",
"name": "Authorization",
Expand All @@ -29,7 +29,7 @@
},
"security": [
{
"aws.auth#sigv4": [ ]
"aws.auth.sigv4": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"smithy.api#httpApiKeyAuth": {
"smithy.api.httpApiKeyAuth": {
"type": "apiKey",
"description": "X-Api-Key authentication",
"name": "x-api-key",
Expand All @@ -28,7 +28,7 @@
},
"security": [
{
"smithy.api#httpApiKeyAuth": [ ]
"smithy.api.httpApiKeyAuth": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"smithy.api#httpBasicAuth": {
"smithy.api.httpBasicAuth": {
"type": "http",
"description": "HTTP Basic authentication",
"scheme": "Basic"
Expand All @@ -27,7 +27,7 @@
},
"security": [
{
"smithy.api#httpBasicAuth": [ ]
"smithy.api.httpBasicAuth": [ ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"components": {
"securitySchemes": {
"smithy.api#httpDigestAuth": {
"smithy.api.httpDigestAuth": {
"type": "http",
"scheme": "Digest",
"description": "HTTP Digest authentication"
Expand All @@ -27,7 +27,7 @@
},
"security": [
{
"smithy.api#httpDigestAuth": [ ]
"smithy.api.httpDigestAuth": [ ]
}
]
}