Skip to content

Commit 607cb04

Browse files
committed
Fixes from PR
1 parent a49acc3 commit 607cb04

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

services/sso/src/main/java/software/amazon/awssdk/services/sso/auth/ExpiredTokenException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@SdkPublicApi
3232
public final class ExpiredTokenException extends SdkClientException {
3333

34-
public static final String DEFAULT_MESSAGE =
34+
private static final String DEFAULT_MESSAGE =
3535
"The SSO session associated with this profile has expired or is otherwise invalid."
3636
+ " To refresh this SSO session run aws sso login with the corresponding profile.";
3737

services/sso/src/main/java/software/amazon/awssdk/services/sso/auth/SsoProfileCredentialsProviderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static SdkToken resolveTokenOrThrow(SdkTokenProvider tokenProvider) {
147147
SdkToken token;
148148
try {
149149
token = tokenProvider.resolveToken();
150-
} catch (ExpiredTokenException | SdkServiceException e) {
150+
} catch (ExpiredTokenException | SdkServiceException | IllegalArgumentException e) {
151151
throw e;
152152
} catch (RuntimeException e) {
153153
throw ExpiredTokenException.builder()

services/sso/src/main/java/software/amazon/awssdk/services/sso/internal/SsoAccessTokenProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public SdkToken resolveToken() {
5252
} catch (ExpiredTokenException e) {
5353
throw e;
5454
} catch (Exception e) {
55+
// Any exception raised while trying to read the token file (invalid file, unable to access, does not exist, ect)
56+
// should be treated as an invalid/expired token and requires the user to re-authenticate
5557
throw ExpiredTokenException.builder()
5658
.cause(e)
5759
.build();

services/sso/src/test/java/software/amazon/awssdk/services/sso/auth/SsoProfileCredentialsProviderFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ public void tokenProviderThrowsOnSecondCall_staleCachedCredentialsReturned() {
578578
// First call succeeds and caches credentials
579579
credentialsProvider.resolveCredentials();
580580

581-
// Second call: token provider throws InvalidTokenException, but CachedSupplier with
582-
// StaleValueBehavior.ALLOW returns stale cached credentials (static stability)
581+
// Second call: token provider throws, but CachedSupplier returns the previously
582+
// cached credentials since they haven't reached their stale time yet.
583583
assertThat(credentialsProvider.resolveCredentials()).isNotNull();
584584
}
585585

test/auth-tests/src/it/java/software/amazon/awssdk/auth/sso/ProfileCredentialProviderTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ private static Stream<Arguments> ssoTokenErrorValues() {
4040
"[sso-session foo]\n" +
4141
"sso_start_url=https//d-abc123.awsapps.com/start\n" +
4242
"sso_region=region")
43-
, "Unable to load SSO token"),
43+
, "expired or is otherwise invalid"),
4444
Arguments.of(configFile("[profile test]\n" +
4545
"sso_account_id=accountId\n" +
4646
"sso_role_name=roleName\n" +
4747
"sso_session=foo\n" +
4848
"[sso-session foo]\n" +
4949
"sso_region=region")
50-
, "Property 'sso_start_url' was not configured for profile 'test'"),
50+
, "Property 'sso_start_url' was not configured for profile"),
5151
Arguments.of(configFile("[profile test]\n" +
5252
"sso_account_id=accountId\n" +
5353
"sso_role_name=roleName\n" +
5454
"sso_region=region\n" +
5555
"sso_start_url=https//non-existing-Token/start")
56-
, "java.nio.file.NoSuchFileException")
56+
, "expired or is otherwise invalid")
5757

5858

5959
);
@@ -71,10 +71,13 @@ private static ProfileFile configFile(String configFile) {
7171
void validateSsoFactoryErrorWithIncorrectProfiles(ProfileFile profiles, String expectedValue) {
7272
assertThat(profiles.profile("test")).hasValueSatisfying(profile -> {
7373
SsoProfileCredentialsProviderFactory factory = new SsoProfileCredentialsProviderFactory();
74-
assertThatThrownBy(() -> factory.create(ProfileProviderCredentialsContext.builder()
75-
.profile(profile)
76-
.profileFile(profiles)
77-
.build())).hasMessageContaining(expectedValue);
74+
assertThatThrownBy(() -> {
75+
factory.create(ProfileProviderCredentialsContext.builder()
76+
.profile(profile)
77+
.profileFile(profiles)
78+
.build())
79+
.resolveCredentials();
80+
}).hasMessageContaining(expectedValue);
7881
});
7982
}
8083

0 commit comments

Comments
 (0)