Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2a7b0a9

Browse files
John Viegasjoviegas
authored andcommittedNov 10, 2020
PR#2123 STS not on class path when using parallel stream
1 parent 8f361fd commit 2a7b0a9

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed
 
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Replaced class loading from Thread.currentThread().getContextClassLoader() to ClassLoaderHelper in ProfileCredentialsUtils and WebIdentityCredentialsUtils, since it was causing Class not found error."
6+
}

‎build-tools/src/main/resources/software/amazon/awssdk/checkstyle-suppressions.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@
4242
<!-- Assumes getter/setter match JSON property -->
4343
<suppress checks="AbbreviationAsWordInName"
4444
files=".*[\\/]software[\\/]amazon[\\/]awssdk[\\/]services[\\/]s3[\\/]event[\\/]S3EventNotification.java$"/>
45+
46+
<!-- Ignore usage of Thread.currentThread().getContextClassLoader for ClassLoaderHelper.!-->
47+
<suppress checks="Regexp"
48+
files=".*ClassLoaderHelper\.java$"/>
49+
4550
</suppressions>

‎build-tools/src/main/resources/software/amazon/awssdk/checkstyle.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@
373373
<property name="ignoreComments" value="true"/>
374374
</module>
375375

376+
<!-- Checks that we don't use Thread.currentThread().getContextClassLoader() directly -->
377+
<module name="Regexp">
378+
<property name="format" value="Thread\s*\.\s*currentThread\s*\(\s*\)\s*(\.|::)\s*getContextClassLoader"/>
379+
<property name="illegalPattern" value="true"/>
380+
<property name="message" value="Use software.amazon.awssdk.core.internal.util.ClassLoaderHelper Class to load the class."/>
381+
<property name="ignoreComments" value="true"/>
382+
</module>
383+
376384
<!-- Checks that we don't use plural enum names -->
377385
<module name="software.amazon.awssdk.buildtools.checkstyle.PluralEnumNames"/>
378386

‎core/auth/src/main/java/software/amazon/awssdk/auth/credentials/internal/ProfileCredentialsUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import software.amazon.awssdk.auth.credentials.ProcessCredentialsProvider;
3838
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
3939
import software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider;
40+
import software.amazon.awssdk.core.internal.util.ClassLoaderHelper;
4041
import software.amazon.awssdk.profiles.Profile;
4142
import software.amazon.awssdk.profiles.ProfileProperty;
4243
import software.amazon.awssdk.utils.SdkAutoCloseable;
@@ -252,8 +253,8 @@ private IllegalStateException noSourceCredentialsException() {
252253
*/
253254
private ChildProfileCredentialsProviderFactory stsCredentialsProviderFactory() {
254255
try {
255-
Class<?> stsCredentialsProviderFactory = Class.forName(STS_PROFILE_CREDENTIALS_PROVIDER_FACTORY, true,
256-
Thread.currentThread().getContextClassLoader());
256+
Class<?> stsCredentialsProviderFactory = ClassLoaderHelper.loadClass(STS_PROFILE_CREDENTIALS_PROVIDER_FACTORY,
257+
getClass());
257258
return (ChildProfileCredentialsProviderFactory) stsCredentialsProviderFactory.getConstructor().newInstance();
258259
} catch (ClassNotFoundException e) {
259260
throw new IllegalStateException("To use assumed roles in the '" + name + "' profile, the 'sts' service module must "

‎core/auth/src/main/java/software/amazon/awssdk/auth/credentials/internal/WebIdentityCredentialsUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.lang.reflect.InvocationTargetException;
1919
import software.amazon.awssdk.annotations.SdkInternalApi;
2020
import software.amazon.awssdk.auth.credentials.WebIdentityTokenCredentialsProviderFactory;
21+
import software.amazon.awssdk.core.internal.util.ClassLoaderHelper;
2122

2223
/**
2324
* Utility class used to configure credential providers based on JWT web identity tokens.
@@ -39,8 +40,8 @@ private WebIdentityCredentialsUtils() {
3940
*/
4041
public static WebIdentityTokenCredentialsProviderFactory factory() {
4142
try {
42-
Class<?> stsCredentialsProviderFactory = Class.forName(STS_WEB_IDENTITY_CREDENTIALS_PROVIDER_FACTORY, true,
43-
Thread.currentThread().getContextClassLoader());
43+
Class<?> stsCredentialsProviderFactory = ClassLoaderHelper.loadClass(STS_WEB_IDENTITY_CREDENTIALS_PROVIDER_FACTORY,
44+
WebIdentityCredentialsUtils.class);
4445
return (WebIdentityTokenCredentialsProviderFactory) stsCredentialsProviderFactory.getConstructor().newInstance();
4546
} catch (ClassNotFoundException e) {
4647
throw new IllegalStateException("To use web identity tokens, the 'sts' service module must be on the class path.", e);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.services.sts.internal;
17+
18+
import org.junit.Assert;
19+
import org.junit.Test;
20+
import software.amazon.awssdk.auth.credentials.WebIdentityTokenCredentialsProviderFactory;
21+
import software.amazon.awssdk.auth.credentials.internal.WebIdentityCredentialsUtils;
22+
23+
public class StsWebIdentityCredentialsProviderFactoryTest {
24+
25+
26+
@Test
27+
public void stsWebIdentityCredentialsProviderFactory_with_webIdentityCredentialsUtils() {
28+
WebIdentityTokenCredentialsProviderFactory factory = WebIdentityCredentialsUtils.factory();
29+
Assert.assertNotNull(factory);
30+
}
31+
32+
}

0 commit comments

Comments
 (0)
Please sign in to comment.