Skip to content

Commit 1d92f36

Browse files
authored
Skip Signing of requests which are defined with authtype as none (#3281)
1 parent d220360 commit 1d92f36

File tree

18 files changed

+564
-9
lines changed

18 files changed

+564
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Requests which are defined with AuthType as None should not be signed or authorized by the SDK."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import software.amazon.awssdk.codegen.poet.PoetExtension;
4242
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
4343
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
44+
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
4445
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
4546
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
4647
import software.amazon.awssdk.core.SdkPojoBuilder;
@@ -177,7 +178,8 @@ public CodeBlock executionHandler(OperationModel opModel) {
177178
.add(".withInput($L)\n", opModel.getInput().getVariableName())
178179
.add(".withMetricCollector(apiCallMetricCollector)")
179180
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
180-
.add(HttpChecksumTrait.create(opModel));
181+
.add(HttpChecksumTrait.create(opModel))
182+
.add(NoneAuthTypeRequestTrait.create(opModel));
181183

182184
if (opModel.hasStreamingInput()) {
183185
codeBlock.add(".withRequestBody(requestBody)")
@@ -245,6 +247,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
245247
.add(asyncRequestBody)
246248
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
247249
.add(HttpChecksumTrait.create(opModel))
250+
.add(NoneAuthTypeRequestTrait.create(opModel))
248251
.add(".withInput($L)$L);",
249252
opModel.getInput().getVariableName(), asyncResponseTransformerVariable(isStreaming, isRestJson, opModel));
250253

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/QueryProtocolSpec.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import software.amazon.awssdk.codegen.poet.PoetExtension;
3131
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
3232
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
33+
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
3334
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
3435
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
3536
import software.amazon.awssdk.core.http.HttpResponseHandler;
@@ -113,7 +114,9 @@ public CodeBlock executionHandler(OperationModel opModel) {
113114
.add(".withInput($L)", opModel.getInput().getVariableName())
114115
.add(".withMetricCollector(apiCallMetricCollector)")
115116
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
116-
.add(HttpChecksumTrait.create(opModel));
117+
.add(HttpChecksumTrait.create(opModel))
118+
.add(NoneAuthTypeRequestTrait.create(opModel));
119+
117120

118121
if (opModel.hasStreamingInput()) {
119122
return codeBlock.add(".withRequestBody(requestBody)")
@@ -145,7 +148,9 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
145148
.add(".withErrorResponseHandler(errorResponseHandler)\n")
146149
.add(".withMetricCollector(apiCallMetricCollector)\n")
147150
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
148-
.add(HttpChecksumTrait.create(opModel));
151+
.add(HttpChecksumTrait.create(opModel))
152+
.add(NoneAuthTypeRequestTrait.create(opModel));
153+
149154

150155
builder.add(hostPrefixExpression(opModel) + asyncRequestBody + ".withInput($L)$L);",
151156
opModel.getInput().getVariableName(),

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/XmlProtocolSpec.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.codegen.poet.PoetExtension;
3737
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
3838
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
39+
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
3940
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
4041
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
4142
import software.amazon.awssdk.core.SdkPojoBuilder;
@@ -132,7 +133,9 @@ public CodeBlock executionHandler(OperationModel opModel) {
132133
discoveredEndpoint(opModel))
133134
.add(".withInput($L)", opModel.getInput().getVariableName())
134135
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
135-
.add(HttpChecksumTrait.create(opModel));
136+
.add(HttpChecksumTrait.create(opModel))
137+
.add(NoneAuthTypeRequestTrait.create(opModel));
138+
136139

137140
s3ArnableFields(opModel, model).ifPresent(codeBlock::add);
138141

@@ -207,7 +210,8 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
207210
.add(".withMetricCollector(apiCallMetricCollector)\n")
208211
.add(asyncRequestBody(opModel))
209212
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
210-
.add(HttpChecksumTrait.create(opModel));
213+
.add(HttpChecksumTrait.create(opModel))
214+
.add(NoneAuthTypeRequestTrait.create(opModel));
211215

212216
s3ArnableFields(opModel, model).ifPresent(builder::add);
213217

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.poet.client.traits;
17+
18+
import com.squareup.javapoet.CodeBlock;
19+
import software.amazon.awssdk.annotations.SdkInternalApi;
20+
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
21+
import software.amazon.awssdk.codegen.model.service.AuthType;
22+
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
23+
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
24+
25+
/**
26+
* Trait which defines if a given request needs to be authenticated.
27+
* A request is not authenticated only if it has "auththpe" trait explicitly marked as "none"
28+
*/
29+
@SdkInternalApi
30+
public class NoneAuthTypeRequestTrait {
31+
32+
private NoneAuthTypeRequestTrait() {
33+
}
34+
35+
/**
36+
* Generate a ".putExecutionAttribute(...)" code-block for the provided operation model. This should be used within the
37+
* context of initializing {@link ClientExecutionParams}. If and only if "authType" trait is explicitly set as "none" the set
38+
* the execution attribute as false.
39+
*/
40+
public static CodeBlock create(OperationModel operationModel) {
41+
42+
if (operationModel.getAuthType() == AuthType.NONE) {
43+
CodeBlock.Builder codeBuilder = CodeBlock.builder();
44+
codeBuilder.add(CodeBlock.of(".putExecutionAttribute($T.IS_NONE_AUTH_TYPE_REQUEST, $L)",
45+
SdkInternalExecutionAttribute.class, operationModel.getAuthType() != AuthType.NONE));
46+
return codeBuilder.build();
47+
} else {
48+
return CodeBlock.of("");
49+
}
50+
}
51+
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/json/service-2.json

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
},
2323
"httpChecksumRequired": true
2424
},
25+
"OperationWithNoneAuthType": {
26+
"name": "APostOperation",
27+
"http": {
28+
"method": "POST",
29+
"requestUri": "/"
30+
},
31+
"authtype": "none"
32+
},
2533
"APostOperation": {
2634
"name": "APostOperation",
2735
"http": {

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/query/service-2.json

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
},
2222
"httpChecksumRequired": true
2323
},
24+
"OperationWithNoneAuthType": {
25+
"name": "APostOperation",
26+
"http": {
27+
"method": "POST",
28+
"requestUri": "/"
29+
},
30+
"authtype": "none"
31+
},
2432
"APostOperation": {
2533
"name": "APostOperation",
2634
"http": {

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/xml/service-2.json

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
},
2222
"httpChecksumRequired": true
2323
},
24+
"OperationWithNoneAuthType": {
25+
"name": "NoneAuthTypeOperation",
26+
"http": {
27+
"method": "POST",
28+
"requestUri": "/"
29+
},
30+
"authtype": "none"
31+
},
2432
"APostOperation": {
2533
"name": "APostOperation",
2634
"http": {

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-json-async-client-class.java

+60
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
import software.amazon.awssdk.services.json.model.JsonRequest;
7676
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest;
7777
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse;
78+
import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeRequest;
79+
import software.amazon.awssdk.services.json.model.OperationWithNoneAuthTypeResponse;
7880
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest;
7981
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse;
8082
import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest;
@@ -99,6 +101,7 @@
99101
import software.amazon.awssdk.services.json.transform.InputEventMarshaller;
100102
import software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller;
101103
import software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller;
104+
import software.amazon.awssdk.services.json.transform.OperationWithNoneAuthTypeRequestMarshaller;
102105
import software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller;
103106
import software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller;
104107
import software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller;
@@ -617,6 +620,63 @@ public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChe
617620
}
618621
}
619622

623+
/**
624+
* Invokes the OperationWithNoneAuthType operation asynchronously.
625+
*
626+
* @param operationWithNoneAuthTypeRequest
627+
* @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.<br/>
628+
* The CompletableFuture returned by this method can be completed exceptionally with the following
629+
* exceptions.
630+
* <ul>
631+
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
632+
* Can be used for catch all scenarios.</li>
633+
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
634+
* credentials, etc.</li>
635+
* <li>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
636+
* of this type.</li>
637+
* </ul>
638+
* @sample JsonAsyncClient.OperationWithNoneAuthType
639+
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/OperationWithNoneAuthType"
640+
* target="_top">AWS API Documentation</a>
641+
*/
642+
@Override
643+
public CompletableFuture<OperationWithNoneAuthTypeResponse> operationWithNoneAuthType(
644+
OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) {
645+
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest
646+
.overrideConfiguration().orElse(null));
647+
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
648+
.create("ApiCall");
649+
try {
650+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
651+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType");
652+
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
653+
.isPayloadJson(true).build();
654+
655+
HttpResponseHandler<OperationWithNoneAuthTypeResponse> responseHandler = protocolFactory.createResponseHandler(
656+
operationMetadata, OperationWithNoneAuthTypeResponse::builder);
657+
658+
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
659+
operationMetadata);
660+
661+
CompletableFuture<OperationWithNoneAuthTypeResponse> executeFuture = clientHandler
662+
.execute(new ClientExecutionParams<OperationWithNoneAuthTypeRequest, OperationWithNoneAuthTypeResponse>()
663+
.withOperationName("OperationWithNoneAuthType")
664+
.withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory))
665+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
666+
.withMetricCollector(apiCallMetricCollector)
667+
.putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false)
668+
.withInput(operationWithNoneAuthTypeRequest));
669+
CompletableFuture<OperationWithNoneAuthTypeResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
670+
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
671+
});
672+
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
673+
return executeFuture;
674+
} catch (Throwable t) {
675+
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
676+
return CompletableFutureUtils.failedFuture(t);
677+
}
678+
}
679+
620680
/**
621681
* Some paginated operation with result_key in paginators.json file
622682
*

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-async-client-class.java

+57
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import software.amazon.awssdk.services.query.model.InvalidInputException;
4545
import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredRequest;
4646
import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse;
47+
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeRequest;
48+
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeResponse;
4749
import software.amazon.awssdk.services.query.model.PutOperationWithChecksumRequest;
4850
import software.amazon.awssdk.services.query.model.PutOperationWithChecksumResponse;
4951
import software.amazon.awssdk.services.query.model.QueryException;
@@ -56,6 +58,7 @@
5658
import software.amazon.awssdk.services.query.transform.APostOperationWithOutputRequestMarshaller;
5759
import software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller;
5860
import software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller;
61+
import software.amazon.awssdk.services.query.transform.OperationWithNoneAuthTypeRequestMarshaller;
5962
import software.amazon.awssdk.services.query.transform.PutOperationWithChecksumRequestMarshaller;
6063
import software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller;
6164
import software.amazon.awssdk.services.query.transform.StreamingOutputOperationRequestMarshaller;
@@ -322,6 +325,60 @@ public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChe
322325
}
323326
}
324327

328+
/**
329+
* Invokes the OperationWithNoneAuthType operation asynchronously.
330+
*
331+
* @param operationWithNoneAuthTypeRequest
332+
* @return A Java Future containing the result of the OperationWithNoneAuthType operation returned by the service.<br/>
333+
* The CompletableFuture returned by this method can be completed exceptionally with the following
334+
* exceptions.
335+
* <ul>
336+
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
337+
* Can be used for catch all scenarios.</li>
338+
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
339+
* credentials, etc.</li>
340+
* <li>QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an
341+
* instance of this type.</li>
342+
* </ul>
343+
* @sample QueryAsyncClient.OperationWithNoneAuthType
344+
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/OperationWithNoneAuthType"
345+
* target="_top">AWS API Documentation</a>
346+
*/
347+
@Override
348+
public CompletableFuture<OperationWithNoneAuthTypeResponse> operationWithNoneAuthType(
349+
OperationWithNoneAuthTypeRequest operationWithNoneAuthTypeRequest) {
350+
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithNoneAuthTypeRequest
351+
.overrideConfiguration().orElse(null));
352+
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
353+
.create("ApiCall");
354+
try {
355+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
356+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithNoneAuthType");
357+
358+
HttpResponseHandler<OperationWithNoneAuthTypeResponse> responseHandler = protocolFactory
359+
.createResponseHandler(OperationWithNoneAuthTypeResponse::builder);
360+
361+
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
362+
363+
CompletableFuture<OperationWithNoneAuthTypeResponse> executeFuture = clientHandler
364+
.execute(new ClientExecutionParams<OperationWithNoneAuthTypeRequest, OperationWithNoneAuthTypeResponse>()
365+
.withOperationName("OperationWithNoneAuthType")
366+
.withMarshaller(new OperationWithNoneAuthTypeRequestMarshaller(protocolFactory))
367+
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
368+
.withMetricCollector(apiCallMetricCollector)
369+
.putExecutionAttribute(SdkInternalExecutionAttribute.IS_NONE_AUTH_TYPE_REQUEST, false)
370+
.withInput(operationWithNoneAuthTypeRequest));
371+
CompletableFuture<OperationWithNoneAuthTypeResponse> whenCompleteFuture = null;
372+
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
373+
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
374+
});
375+
return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
376+
} catch (Throwable t) {
377+
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
378+
return CompletableFutureUtils.failedFuture(t);
379+
}
380+
}
381+
325382
/**
326383
* Invokes the PutOperationWithChecksum operation asynchronously.
327384
*

0 commit comments

Comments
 (0)