Skip to content

Commit 92bd4da

Browse files
committed
Fix NPE due to concurrent access
1 parent 49e61ab commit 92bd4da

File tree

3 files changed

+319
-3
lines changed

3 files changed

+319
-3
lines changed

dependency-reduced-pom.xml

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>software.amazon.s3.accessgrants</groupId>
5+
<artifactId>aws-s3-accessgrants-java-plugin</artifactId>
6+
<name>${project.groupId}:${project.artifactId}</name>
7+
<version>2.3.0</version>
8+
<description>The Amazon Web Services Plugin for S3 Access Grants. The plugin allows customers to integrate S3 Access grants as an additional permission layer on top of S3 calls.</description>
9+
<url>https://github.com/aws/aws-s3-accessgrants-plugin-java-v2</url>
10+
<developers>
11+
<developer>
12+
<id>amazonwebservices</id>
13+
<organization>Amazon Web Services</organization>
14+
<organizationUrl>https://aws.amazon.com</organizationUrl>
15+
<roles>
16+
<role>developer</role>
17+
</roles>
18+
</developer>
19+
</developers>
20+
<licenses>
21+
<license>
22+
<name>Apache License, Version 2.0</name>
23+
<url>https://aws.amazon.com/apache2.0</url>
24+
<distribution>repo</distribution>
25+
</license>
26+
</licenses>
27+
<scm>
28+
<connection>scm:git:git://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git</connection>
29+
<url>https://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git</url>
30+
</scm>
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<artifactId>maven-shade-plugin</artifactId>
35+
<version>3.5.1</version>
36+
<executions>
37+
<execution>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<artifactSet>
43+
<includes>
44+
<include>software.amazon.awssdk.s3accessgrants:*</include>
45+
<include>com.github.ben-manes.caffeine:*</include>
46+
<include>com.google:*</include>
47+
</includes>
48+
</artifactSet>
49+
</configuration>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-jar-plugin</artifactId>
55+
<version>3.3.0</version>
56+
<configuration>
57+
<excludes>
58+
<exclude>log4j2.properties</exclude>
59+
</excludes>
60+
</configuration>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
<profiles>
65+
<profile>
66+
<id>release</id>
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.sonatype.plugins</groupId>
71+
<artifactId>nexus-staging-maven-plugin</artifactId>
72+
<version>1.6.13</version>
73+
<extensions>true</extensions>
74+
<configuration>
75+
<serverId>ossrh</serverId>
76+
<nexusUrl>https://aws.oss.sonatype.org/</nexusUrl>
77+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
78+
</configuration>
79+
</plugin>
80+
<plugin>
81+
<artifactId>maven-gpg-plugin</artifactId>
82+
<version>3.1.0</version>
83+
<executions>
84+
<execution>
85+
<id>sign-artifacts</id>
86+
<phase>verify</phase>
87+
<goals>
88+
<goal>sign</goal>
89+
</goals>
90+
<configuration>
91+
<keyname>s3-user-security</keyname>
92+
<passphraseServerId>s3-user-security</passphraseServerId>
93+
</configuration>
94+
</execution>
95+
</executions>
96+
</plugin>
97+
<plugin>
98+
<artifactId>maven-source-plugin</artifactId>
99+
<version>2.2.1</version>
100+
<executions>
101+
<execution>
102+
<id>attach-sources</id>
103+
<goals>
104+
<goal>jar-no-fork</goal>
105+
</goals>
106+
</execution>
107+
</executions>
108+
</plugin>
109+
<plugin>
110+
<artifactId>maven-javadoc-plugin</artifactId>
111+
<version>2.9.1</version>
112+
<executions>
113+
<execution>
114+
<id>attach-javadocs</id>
115+
<goals>
116+
<goal>jar</goal>
117+
</goals>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
<plugin>
122+
<artifactId>maven-shade-plugin</artifactId>
123+
<version>3.5.1</version>
124+
<executions>
125+
<execution>
126+
<phase>package</phase>
127+
<goals>
128+
<goal>shade</goal>
129+
</goals>
130+
<configuration>
131+
<artifactSet>
132+
<includes>
133+
<include>software.amazon.s3.accessgrants:*</include>
134+
</includes>
135+
</artifactSet>
136+
</configuration>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
<plugin>
141+
<artifactId>maven-shade-plugin</artifactId>
142+
<version>3.5.1</version>
143+
<executions>
144+
<execution>
145+
<phase>package</phase>
146+
<goals>
147+
<goal>shade</goal>
148+
</goals>
149+
<configuration>
150+
<artifactSet>
151+
<includes>
152+
<include>software.amazon.awssdk.s3accessgrants:*</include>
153+
</includes>
154+
</artifactSet>
155+
</configuration>
156+
</execution>
157+
</executions>
158+
</plugin>
159+
<plugin>
160+
<artifactId>maven-jar-plugin</artifactId>
161+
<version>3.3.0</version>
162+
<configuration>
163+
<excludes>
164+
<exclude>log4j2.properties</exclude>
165+
</excludes>
166+
</configuration>
167+
</plugin>
168+
</plugins>
169+
</build>
170+
</profile>
171+
</profiles>
172+
<dependencies>
173+
<dependency>
174+
<groupId>software.amazon.awssdk</groupId>
175+
<artifactId>s3</artifactId>
176+
<version>2.25.67</version>
177+
<scope>compile</scope>
178+
</dependency>
179+
<dependency>
180+
<groupId>software.amazon.awssdk</groupId>
181+
<artifactId>http-auth-spi</artifactId>
182+
<version>2.25.67</version>
183+
<scope>compile</scope>
184+
</dependency>
185+
<dependency>
186+
<groupId>software.amazon.awssdk</groupId>
187+
<artifactId>identity-spi</artifactId>
188+
<version>2.25.67</version>
189+
<scope>compile</scope>
190+
</dependency>
191+
<dependency>
192+
<groupId>org.mockito</groupId>
193+
<artifactId>mockito-core</artifactId>
194+
<version>4.3.1</version>
195+
<scope>test</scope>
196+
<exclusions>
197+
<exclusion>
198+
<artifactId>byte-buddy</artifactId>
199+
<groupId>net.bytebuddy</groupId>
200+
</exclusion>
201+
<exclusion>
202+
<artifactId>byte-buddy-agent</artifactId>
203+
<groupId>net.bytebuddy</groupId>
204+
</exclusion>
205+
<exclusion>
206+
<artifactId>objenesis</artifactId>
207+
<groupId>org.objenesis</groupId>
208+
</exclusion>
209+
</exclusions>
210+
</dependency>
211+
<dependency>
212+
<groupId>org.mockito</groupId>
213+
<artifactId>mockito-inline</artifactId>
214+
<version>2.13.0</version>
215+
<scope>test</scope>
216+
</dependency>
217+
<dependency>
218+
<groupId>junit</groupId>
219+
<artifactId>junit</artifactId>
220+
<version>4.13.2</version>
221+
<scope>test</scope>
222+
<exclusions>
223+
<exclusion>
224+
<artifactId>hamcrest-core</artifactId>
225+
<groupId>org.hamcrest</groupId>
226+
</exclusion>
227+
</exclusions>
228+
</dependency>
229+
<dependency>
230+
<groupId>org.apache.logging.log4j</groupId>
231+
<artifactId>log4j-slf4j-impl</artifactId>
232+
<version>2.20.0</version>
233+
<scope>compile</scope>
234+
</dependency>
235+
<dependency>
236+
<groupId>org.assertj</groupId>
237+
<artifactId>assertj-core</artifactId>
238+
<version>3.20.2</version>
239+
<scope>test</scope>
240+
</dependency>
241+
<dependency>
242+
<groupId>software.amazon.awssdk</groupId>
243+
<artifactId>s3control</artifactId>
244+
<version>2.25.67</version>
245+
<scope>compile</scope>
246+
</dependency>
247+
<dependency>
248+
<groupId>software.amazon.awssdk</groupId>
249+
<artifactId>iam</artifactId>
250+
<version>2.25.67</version>
251+
<scope>compile</scope>
252+
</dependency>
253+
<dependency>
254+
<groupId>software.amazon.awssdk</groupId>
255+
<artifactId>sts</artifactId>
256+
<version>2.25.67</version>
257+
<scope>compile</scope>
258+
</dependency>
259+
<dependency>
260+
<groupId>software.amazon.awssdk</groupId>
261+
<artifactId>cloudwatch-metric-publisher</artifactId>
262+
<version>2.25.67</version>
263+
<scope>compile</scope>
264+
</dependency>
265+
</dependencies>
266+
<distributionManagement>
267+
<snapshotRepository>
268+
<id>ossrh</id>
269+
<url>https://aws.oss.sonatype.org/content/repositories/snapshots/</url>
270+
</snapshotRepository>
271+
</distributionManagement>
272+
<properties>
273+
<sdk.version>2.25.67</sdk.version>
274+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
275+
<maven.compiler.source>8</maven.compiler.source>
276+
<maven.compiler.target>8</maven.compiler.target>
277+
</properties>
278+
</project>

src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ String userAgent() {
7272
return this.userAgent;
7373
}
7474

75-
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
76-
.putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build();
77-
7875
/**
7976
* Change the configuration on the S3Clients to use S3 Access Grants specific AuthScheme and identityProviders.
8077
* @param config the existing configuration on the clients. Passed by the SDK on request path.
8178
* */
8279
@Override
8380
public void configureClient(SdkServiceClientConfiguration.Builder config) {
81+
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
82+
.putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build();
8483
logger.info(() -> "Configuring S3 Clients to use S3 Access Grants as a permission layer!");
8584
logger.info(() -> "Running the S3 Access grants plugin with fallback setting enabled : "+enableFallback());
8685
if(!enableFallback()) {

src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import software.amazon.awssdk.services.s3.auth.scheme.S3AuthSchemeProvider;
2525
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
2626
import software.amazon.awssdk.regions.Region;
27+
import java.util.concurrent.CountDownLatch;
28+
import java.util.concurrent.ExecutorService;
29+
import java.util.concurrent.Executors;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.atomic.AtomicInteger;
2732

2833
public class S3AccessGrantsPluginTests {
2934

@@ -156,4 +161,38 @@ public void create_access_grants_plugin_without_userAgent_specified() {
156161
public void create_access_grants_plugin_with_not_permitted_userAgent_name() {
157162
Assertions.assertThatThrownBy(() -> S3AccessGrantsPlugin.builder().userAgent("testUserAgent/").build()).isInstanceOf(IllegalArgumentException.class);
158163
}
164+
165+
@Test
166+
public void configureClient_concurrent_access_should_not_throw_null_pointer_exception() throws InterruptedException {
167+
S3AccessGrantsPlugin accessGrantsPlugin = S3AccessGrantsPlugin.builder().build();
168+
int threadCount = 10;
169+
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
170+
CountDownLatch latch = new CountDownLatch(threadCount);
171+
AtomicInteger successCount = new AtomicInteger(0);
172+
AtomicInteger exceptionCount = new AtomicInteger(0);
173+
174+
for (int i = 0; i < threadCount; i++) {
175+
executor.submit(() -> {
176+
try {
177+
SdkServiceClientConfiguration.Builder config = S3ServiceClientConfiguration.builder()
178+
.authSchemeProvider(S3AuthSchemeProvider.defaultProvider())
179+
.credentialsProvider(DefaultCredentialsProvider.create())
180+
.region(Region.US_EAST_2);
181+
182+
accessGrantsPlugin.configureClient(config);
183+
successCount.incrementAndGet();
184+
} catch (Exception e) {
185+
exceptionCount.incrementAndGet();
186+
} finally {
187+
latch.countDown();
188+
}
189+
});
190+
}
191+
192+
latch.await(10, TimeUnit.SECONDS);
193+
executor.shutdown();
194+
195+
Assertions.assertThat(successCount.get()).isEqualTo(threadCount);
196+
Assertions.assertThat(exceptionCount.get()).isEqualTo(0);
197+
}
159198
}

0 commit comments

Comments
 (0)