From 600eb81b4a84c3d399bc3214090011158175e11e Mon Sep 17 00:00:00 2001 From: Syed Shameerur Rahman Date: Wed, 3 Sep 2025 15:50:19 +0530 Subject: [PATCH 1/3] Fix NPE due to concurrent access of ClientOverrideConfiguration --- .../plugin/S3AccessGrantsPlugin.java | 5 +-- .../plugin/S3AccessGrantsPluginTests.java | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java b/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java index 77e61bb..665d1c6 100644 --- a/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java +++ b/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java @@ -72,15 +72,14 @@ String userAgent() { return this.userAgent; } - ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() - .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build(); - /** * Change the configuration on the S3Clients to use S3 Access Grants specific AuthScheme and identityProviders. * @param config the existing configuration on the clients. Passed by the SDK on request path. * */ @Override public void configureClient(SdkServiceClientConfiguration.Builder config) { + ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() + .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build(); logger.info(() -> "Configuring S3 Clients to use S3 Access Grants as a permission layer!"); logger.info(() -> "Running the S3 Access grants plugin with fallback setting enabled : "+enableFallback()); if(!enableFallback()) { diff --git a/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java b/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java index 933d11f..9906c9b 100644 --- a/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java +++ b/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java @@ -24,6 +24,11 @@ import software.amazon.awssdk.services.s3.auth.scheme.S3AuthSchemeProvider; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; public class S3AccessGrantsPluginTests { @@ -156,4 +161,38 @@ public void create_access_grants_plugin_without_userAgent_specified() { public void create_access_grants_plugin_with_not_permitted_userAgent_name() { Assertions.assertThatThrownBy(() -> S3AccessGrantsPlugin.builder().userAgent("testUserAgent/").build()).isInstanceOf(IllegalArgumentException.class); } + + @Test + public void configureClient_concurrent_access_should_not_throw_null_pointer_exception() throws InterruptedException { + S3AccessGrantsPlugin accessGrantsPlugin = S3AccessGrantsPlugin.builder().build(); + int threadCount = 10; + ExecutorService executor = Executors.newFixedThreadPool(threadCount); + CountDownLatch latch = new CountDownLatch(threadCount); + AtomicInteger successCount = new AtomicInteger(0); + AtomicInteger exceptionCount = new AtomicInteger(0); + + for (int i = 0; i < threadCount; i++) { + executor.submit(() -> { + try { + SdkServiceClientConfiguration.Builder config = S3ServiceClientConfiguration.builder() + .authSchemeProvider(S3AuthSchemeProvider.defaultProvider()) + .credentialsProvider(DefaultCredentialsProvider.create()) + .region(Region.US_EAST_2); + + accessGrantsPlugin.configureClient(config); + successCount.incrementAndGet(); + } catch (Exception e) { + exceptionCount.incrementAndGet(); + } finally { + latch.countDown(); + } + }); + } + + latch.await(10, TimeUnit.SECONDS); + executor.shutdown(); + + Assertions.assertThat(successCount.get()).isEqualTo(threadCount); + Assertions.assertThat(exceptionCount.get()).isEqualTo(0); + } } From 3594accf8d7c2ca613b4b22571bf93f934e1d20c Mon Sep 17 00:00:00 2001 From: Syed Shameerur Rahman Date: Mon, 8 Sep 2025 12:53:01 +0530 Subject: [PATCH 2/3] PR review comments --- dependency-reduced-pom.xml | 278 ++++++++++++++++++ .../plugin/S3AccessGrantsPlugin.java | 5 +- .../plugin/S3AccessGrantsPluginTests.java | 5 + 3 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 dependency-reduced-pom.xml diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..fe2920e --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,278 @@ + + + 4.0.0 + software.amazon.s3.accessgrants + aws-s3-accessgrants-java-plugin + ${project.groupId}:${project.artifactId} + 2.3.0 + 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. + https://github.com/aws/aws-s3-accessgrants-plugin-java-v2 + + + amazonwebservices + Amazon Web Services + https://aws.amazon.com + + developer + + + + + + Apache License, Version 2.0 + https://aws.amazon.com/apache2.0 + repo + + + + scm:git:git://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git + https://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git + + + + + maven-shade-plugin + 3.5.1 + + + + shade + + + + + software.amazon.awssdk.s3accessgrants:* + com.github.ben-manes.caffeine:* + com.google:* + + + + + + + + maven-jar-plugin + 3.3.0 + + + log4j2.properties + + + + + + + + release + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://aws.oss.sonatype.org/ + false + + + + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + s3-user-security + s3-user-security + + + + + + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + maven-shade-plugin + 3.5.1 + + + package + + shade + + + + + software.amazon.s3.accessgrants:* + + + + + + + + maven-shade-plugin + 3.5.1 + + + package + + shade + + + + + software.amazon.awssdk.s3accessgrants:* + + + + + + + + maven-jar-plugin + 3.3.0 + + + log4j2.properties + + + + + + + + + + software.amazon.awssdk + s3 + 2.25.67 + compile + + + software.amazon.awssdk + http-auth-spi + 2.25.67 + compile + + + software.amazon.awssdk + identity-spi + 2.25.67 + compile + + + org.mockito + mockito-core + 4.3.1 + test + + + byte-buddy + net.bytebuddy + + + byte-buddy-agent + net.bytebuddy + + + objenesis + org.objenesis + + + + + org.mockito + mockito-inline + 2.13.0 + test + + + junit + junit + 4.13.2 + test + + + hamcrest-core + org.hamcrest + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.20.0 + compile + + + org.assertj + assertj-core + 3.20.2 + test + + + software.amazon.awssdk + s3control + 2.25.67 + compile + + + software.amazon.awssdk + iam + 2.25.67 + compile + + + software.amazon.awssdk + sts + 2.25.67 + compile + + + software.amazon.awssdk + cloudwatch-metric-publisher + 2.25.67 + compile + + + + + ossrh + https://aws.oss.sonatype.org/content/repositories/snapshots/ + + + + 2.25.67 + UTF-8 + 8 + 8 + + diff --git a/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java b/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java index 665d1c6..6586e11 100644 --- a/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java +++ b/src/main/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPlugin.java @@ -78,8 +78,6 @@ String userAgent() { * */ @Override public void configureClient(SdkServiceClientConfiguration.Builder config) { - ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() - .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build(); logger.info(() -> "Configuring S3 Clients to use S3 Access Grants as a permission layer!"); logger.info(() -> "Running the S3 Access grants plugin with fallback setting enabled : "+enableFallback()); if(!enableFallback()) { @@ -102,6 +100,9 @@ public void configureClient(SdkServiceClientConfiguration.Builder config) { S3ControlAsyncClientBuilder s3ControlAsyncClientBuilder = S3ControlAsyncClient.builder() .credentialsProvider(serviceClientConfiguration.credentialsProvider()); + ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() + .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build(); + S3Client s3Client = S3Client .builder() .crossRegionAccessEnabled(true) diff --git a/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java b/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java index 9906c9b..9e170cb 100644 --- a/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java +++ b/src/test/java/software/amazon/awssdk/s3accessgrants/plugin/S3AccessGrantsPluginTests.java @@ -18,6 +18,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.assertj.core.api.Assertions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import software.amazon.awssdk.core.SdkServiceClientConfiguration; import software.amazon.awssdk.core.exception.SdkClientException; import software.amazon.awssdk.services.s3.S3ServiceClientConfiguration; @@ -32,6 +34,8 @@ public class S3AccessGrantsPluginTests { + private static final Logger logger = LoggerFactory.getLogger(S3AccessGrantsPluginTests.class); + @BeforeClass public static void setUp() { System.setProperty("aws.region", "us-east-2"); @@ -183,6 +187,7 @@ public void configureClient_concurrent_access_should_not_throw_null_pointer_exce successCount.incrementAndGet(); } catch (Exception e) { exceptionCount.incrementAndGet(); + logger.error("An error occurred: ", e); } finally { latch.countDown(); } From a521d8c1dd1a69e13a4cb11c991d6a50e83e88e8 Mon Sep 17 00:00:00 2001 From: Syed Shameerur Rahman Date: Mon, 8 Sep 2025 12:54:21 +0530 Subject: [PATCH 3/3] Remove intended commit of dependency-reduced-pom.xml --- dependency-reduced-pom.xml | 278 ------------------------------------- 1 file changed, 278 deletions(-) delete mode 100644 dependency-reduced-pom.xml diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml deleted file mode 100644 index fe2920e..0000000 --- a/dependency-reduced-pom.xml +++ /dev/null @@ -1,278 +0,0 @@ - - - 4.0.0 - software.amazon.s3.accessgrants - aws-s3-accessgrants-java-plugin - ${project.groupId}:${project.artifactId} - 2.3.0 - 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. - https://github.com/aws/aws-s3-accessgrants-plugin-java-v2 - - - amazonwebservices - Amazon Web Services - https://aws.amazon.com - - developer - - - - - - Apache License, Version 2.0 - https://aws.amazon.com/apache2.0 - repo - - - - scm:git:git://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git - https://github.com/aws/aws-s3-accessgrants-plugin-java-v2.git - - - - - maven-shade-plugin - 3.5.1 - - - - shade - - - - - software.amazon.awssdk.s3accessgrants:* - com.github.ben-manes.caffeine:* - com.google:* - - - - - - - - maven-jar-plugin - 3.3.0 - - - log4j2.properties - - - - - - - - release - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 - true - - ossrh - https://aws.oss.sonatype.org/ - false - - - - maven-gpg-plugin - 3.1.0 - - - sign-artifacts - verify - - sign - - - s3-user-security - s3-user-security - - - - - - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - maven-shade-plugin - 3.5.1 - - - package - - shade - - - - - software.amazon.s3.accessgrants:* - - - - - - - - maven-shade-plugin - 3.5.1 - - - package - - shade - - - - - software.amazon.awssdk.s3accessgrants:* - - - - - - - - maven-jar-plugin - 3.3.0 - - - log4j2.properties - - - - - - - - - - software.amazon.awssdk - s3 - 2.25.67 - compile - - - software.amazon.awssdk - http-auth-spi - 2.25.67 - compile - - - software.amazon.awssdk - identity-spi - 2.25.67 - compile - - - org.mockito - mockito-core - 4.3.1 - test - - - byte-buddy - net.bytebuddy - - - byte-buddy-agent - net.bytebuddy - - - objenesis - org.objenesis - - - - - org.mockito - mockito-inline - 2.13.0 - test - - - junit - junit - 4.13.2 - test - - - hamcrest-core - org.hamcrest - - - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.20.0 - compile - - - org.assertj - assertj-core - 3.20.2 - test - - - software.amazon.awssdk - s3control - 2.25.67 - compile - - - software.amazon.awssdk - iam - 2.25.67 - compile - - - software.amazon.awssdk - sts - 2.25.67 - compile - - - software.amazon.awssdk - cloudwatch-metric-publisher - 2.25.67 - compile - - - - - ossrh - https://aws.oss.sonatype.org/content/repositories/snapshots/ - - - - 2.25.67 - UTF-8 - 8 - 8 - -