Skip to content

Commit ae8f716

Browse files
committed
Adding support for S3 control
1 parent c9bcf5b commit ae8f716

File tree

18 files changed

+2144
-1
lines changed

18 files changed

+2144
-1
lines changed

aws-sdk-java/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,11 @@ Amazon AutoScaling, etc).</description>
710710
<artifactId>s3</artifactId>
711711
<version>${awsjavasdk.version}</version>
712712
</dependency>
713+
<dependency>
714+
<groupId>software.amazon.awssdk</groupId>
715+
<artifactId>s3control</artifactId>
716+
<version>${awsjavasdk.version}</version>
717+
</dependency>
713718
<dependency>
714719
<groupId>software.amazon.awssdk</groupId>
715720
<artifactId>sagemaker</artifactId>

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,11 @@
820820
<artifactId>s3</artifactId>
821821
<version>${awsjavasdk.version}</version>
822822
</dependency>
823+
<dependency>
824+
<groupId>software.amazon.awssdk</groupId>
825+
<artifactId>s3control</artifactId>
826+
<version>${awsjavasdk.version}</version>
827+
</dependency>
823828
<dependency>
824829
<groupId>software.amazon.awssdk</groupId>
825830
<artifactId>sagemaker</artifactId>

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/AuthType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public enum AuthType {
2626
IAM("iam"),
2727
V4("v4"),
2828
V4_UNSIGNED_BODY("v4-unsigned-body"),
29-
S3("s3")
29+
S3("s3"),
30+
S3V4("s3v4")
3031
;
3132

3233
private final String value;

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ private CodeBlock signerDefinitionMethodBody() {
265265
case V4:
266266
return v4SignerDefinitionMethodBody();
267267
case S3:
268+
case S3V4:
268269
return s3SignerDefinitionMethodBody();
269270
default:
270271
throw new UnsupportedOperationException("Unsupported signer type: " + authType);

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/SigningStage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private SdkHttpFullRequest signRequest(SdkHttpFullRequest request, RequestExecut
6969
.signAsyncRequestBody(signedRequest, context.requestProvider(), context.executionAttributes());
7070
context.requestProvider(transformedRequestProvider);
7171
}
72+
updateInterceptorContext(signedRequest, context.executionContext());
7273
return signedRequest;
7374
}
7475

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@
727727
<title>Resource Groups Tagging API</title>
728728
<packages>software.amazon.awssdk.services.resourcegroupstaggingapi*</packages>
729729
</group>
730+
<group>
731+
<title>S3 Control</title>
732+
<packages>software.amazon.awssdk.services.s3control*</packages>
733+
</group>
730734
<group>
731735
<title>S3</title>
732736
<packages>software.amazon.awssdk.services.s3*</packages>

services/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<module>route53</module>
9191
<module>route53domains</module>
9292
<module>s3</module>
93+
<module>s3control</module>
9394
<module>sms</module>
9495
<module>servicecatalog</module>
9596
<module>ses</module>

services/s3control/pom.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
18+
xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>services</artifactId>
24+
<version>2.9.14-SNAPSHOT</version>
25+
</parent>
26+
<artifactId>s3control</artifactId>
27+
<name>AWS Java SDK :: Services :: Amazon S3 Control</name>
28+
<description>The AWS Java SDK for Amazon S3 Control module holds the client classes that are used for communicating with
29+
Amazon Simple Storage Service Control Plane
30+
</description>
31+
<url>https://aws.amazon.com/sdkforjava</url>
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-jar-plugin</artifactId>
37+
<configuration>
38+
<archive>
39+
<manifestEntries>
40+
<Automatic-Module-Name>software.amazon.awssdk.services.s3control</Automatic-Module-Name>
41+
</manifestEntries>
42+
</archive>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
48+
<dependencies>
49+
<dependency>
50+
<groupId>software.amazon.awssdk</groupId>
51+
<artifactId>aws-xml-protocol</artifactId>
52+
<version>${awsjavasdk.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>software.amazon.awssdk</groupId>
56+
<artifactId>protocol-core</artifactId>
57+
<version>${awsjavasdk.version}</version>
58+
</dependency>
59+
<!-- Test Dependencies -->
60+
<dependency>
61+
<artifactId>commons-io</artifactId>
62+
<groupId>commons-io</groupId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.apache.commons</groupId>
67+
<artifactId>commons-lang3</artifactId>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>software.amazon.awssdk</groupId>
72+
<artifactId>sts</artifactId>
73+
<version>${awsjavasdk.version}</version>
74+
<scope>test</scope>
75+
</dependency>
76+
</dependencies>
77+
</project>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright 2010-2019 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+
package software.amazon.awssdk.services.s3control;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.assertj.core.api.Fail.fail;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import software.amazon.awssdk.core.interceptor.Context;
27+
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
28+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
29+
import software.amazon.awssdk.http.SdkHttpFullRequest;
30+
import software.amazon.awssdk.services.s3control.model.DeletePublicAccessBlockRequest;
31+
import software.amazon.awssdk.services.s3control.model.GetPublicAccessBlockResponse;
32+
import software.amazon.awssdk.services.s3control.model.NoSuchPublicAccessBlockConfigurationException;
33+
import software.amazon.awssdk.services.s3control.model.PutPublicAccessBlockResponse;
34+
import software.amazon.awssdk.services.s3control.model.S3ControlException;
35+
import software.amazon.awssdk.services.sts.StsClient;
36+
import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase;
37+
38+
public class S3ControlIntegrationTest extends AwsIntegrationTestBase {
39+
40+
private String accountId;
41+
42+
private static final String INVALID_ACCOUNT_ID = "1";
43+
44+
private S3ControlClient client;
45+
46+
@Before
47+
public void setup() {
48+
StsClient sts = StsClient.create();
49+
accountId = sts.getCallerIdentity().account();
50+
client = S3ControlClient.builder()
51+
.overrideConfiguration(o -> o.addExecutionInterceptor(new AssertPayloadIsSignedExecutionInterceptor()))
52+
.build();
53+
}
54+
55+
@After
56+
public void tearDown() {
57+
try {
58+
client.deletePublicAccessBlock(DeletePublicAccessBlockRequest.builder().accountId(accountId).build());
59+
} catch (Exception ignore) {
60+
61+
}
62+
}
63+
64+
@Test
65+
public void putGetAndDeletePublicAccessBlock_ValidAccount() throws InterruptedException {
66+
PutPublicAccessBlockResponse result =
67+
client.putPublicAccessBlock(r -> r.accountId(accountId)
68+
.publicAccessBlockConfiguration(r2 -> r2.blockPublicAcls(true)
69+
.ignorePublicAcls(true)));
70+
assertNotNull(result);
71+
72+
// Wait a bit for the put to take affect
73+
Thread.sleep(5000);
74+
75+
GetPublicAccessBlockResponse config = client.getPublicAccessBlock(r -> r.accountId(accountId));
76+
assertTrue(config.publicAccessBlockConfiguration().blockPublicAcls());
77+
assertTrue(config.publicAccessBlockConfiguration().ignorePublicAcls());
78+
79+
assertNotNull(client.deletePublicAccessBlock(r -> r.accountId(accountId)));
80+
}
81+
82+
@Test
83+
public void putPublicAccessBlock_NoSuchAccount() {
84+
try {
85+
assertNotNull(client.putPublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID)
86+
.publicAccessBlockConfiguration(r2 -> r2.restrictPublicBuckets(true))));
87+
fail("Expected exception");
88+
} catch (S3ControlException e) {
89+
assertEquals("AccessDenied", e.awsErrorDetails().errorCode());
90+
assertNotNull(e.requestId());
91+
}
92+
}
93+
94+
@Test
95+
public void getPublicAccessBlock_NoSuchAccount() {
96+
try {
97+
client.getPublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID));
98+
fail("Expected exception");
99+
} catch (S3ControlException e) {
100+
assertEquals("AccessDenied", e.awsErrorDetails().errorCode());
101+
assertNotNull(e.requestId());
102+
}
103+
}
104+
105+
@Test
106+
public void getPublicAccessBlock_NoSuchConfig() {
107+
try {
108+
client.getPublicAccessBlock(r -> r.accountId(accountId));
109+
fail("Expected exception");
110+
} catch (NoSuchPublicAccessBlockConfigurationException e) {
111+
assertNotNull(e.requestId());
112+
}
113+
}
114+
115+
@Test
116+
public void deletePublicAccessBlock_NoSuchAccount() {
117+
try {
118+
client.deletePublicAccessBlock(r -> r.accountId(INVALID_ACCOUNT_ID));
119+
fail("Expected exception");
120+
} catch (S3ControlException e) {
121+
assertEquals("AccessDenied", e.awsErrorDetails().errorCode());
122+
assertNotNull(e.requestId());
123+
}
124+
}
125+
126+
/**
127+
* Request handler to assert that payload signing is enabled.
128+
*/
129+
private static final class AssertPayloadIsSignedExecutionInterceptor implements ExecutionInterceptor {
130+
@Override
131+
public void afterTransmission(Context.AfterTransmission context, ExecutionAttributes executionAttributes) {
132+
SdkHttpFullRequest request = (SdkHttpFullRequest) context.httpRequest();
133+
assertThat(context.httpRequest().headers().get("x-amz-content-sha256").get(0)).doesNotContain("UNSIGNED-PAYLOAD");
134+
}
135+
}
136+
137+
}

0 commit comments

Comments
 (0)