Skip to content

Commit d699b20

Browse files
committed
Only refresh OAuth tokens when expired and save in credentials.
1 parent 161ed38 commit d699b20

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

s3/src/main/java/ch/cyberduck/core/sts/STSAssumeRoleWithWebIdentityRequestInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TemporaryAccessTokens refresh(final Credentials credentials) throws Backg
6161
try {
6262
final String arn = new ProxyPreferencesReader(host, credentials).getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn");
6363
log.debug("Use ARN {}", arn);
64-
return tokens = this.assumeRoleWithWebIdentity(oauth.refresh(credentials.getOauth()), arn);
64+
return tokens = this.assumeRoleWithWebIdentity(oauth.validate(credentials.getOauth()), arn);
6565
}
6666
finally {
6767
lock.unlock();

s3/src/test/java/ch/cyberduck/core/sts/AssumeRoleWithWebIdentityAuthenticationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public class AssumeRoleWithWebIdentityAuthenticationTest extends AbstractAssumeR
5454
public void testSuccessfulLogin() throws BackgroundException {
5555
final Protocol profile = new ProfilePlistReader(new ProtocolFactory(new HashSet<>(Collections.singleton(new S3Protocol())))).read(
5656
AbstractAssumeRoleWithWebIdentityTest.class.getResourceAsStream("/S3 (OIDC).cyberduckprofile"));
57-
final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials("rouser", "rouser"));
57+
final Credentials credentials = new Credentials("rouser", "rouser");
58+
final Host host = new Host(profile, profile.getDefaultHostname(), credentials);
5859
final S3Session session = new S3Session(host);
5960
session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
6061
session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
6162

62-
final Credentials credentials = host.getCredentials();
6363
assertEquals("rouser", credentials.getUsername());
6464
assertEquals("rouser", credentials.getPassword());
6565

@@ -98,18 +98,18 @@ public void testInvalidPassword() throws BackgroundException {
9898
public void testTokenRefresh() throws BackgroundException, InterruptedException {
9999
final Protocol profile = new ProfilePlistReader(new ProtocolFactory(new HashSet<>(Collections.singleton(new S3Protocol())))).read(
100100
AbstractAssumeRoleWithWebIdentityTest.class.getResourceAsStream("/S3 (OIDC).cyberduckprofile"));
101-
final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials("rawuser", "rawuser"));
101+
final Credentials credentials = new Credentials("rawuser", "rawuser");
102+
final Host host = new Host(profile, profile.getDefaultHostname(), credentials);
102103
final S3Session session = new S3Session(host);
103104
session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
104105
session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
105106

106-
final Credentials credentials = host.getCredentials();
107107
final OAuthTokens oauth = credentials.getOauth();
108108
assertTrue(oauth.validate());
109109
final TemporaryAccessTokens tokens = credentials.getTokens();
110110
assertTrue(tokens.validate());
111111

112-
host.getCredentials().reset();
112+
credentials.reset();
113113

114114
Path container = new Path("cyberduckbucket", EnumSet.of(Path.Type.directory, Path.Type.volume));
115115
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(container));
@@ -147,7 +147,7 @@ public void testLoginInvalidOAuthTokensLogin() throws Exception {
147147
session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
148148
assertNotEquals(OAuthTokens.EMPTY, credentials.getOauth());
149149
assertNotEquals(TemporaryAccessTokens.EMPTY, credentials.getTokens());
150-
host.getCredentials().reset();
150+
credentials.reset();
151151
assertEquals(OAuthTokens.EMPTY, credentials.getOauth());
152152
assertEquals(TemporaryAccessTokens.EMPTY, credentials.getTokens());
153153
new S3BucketListService(session).list(
@@ -179,7 +179,7 @@ public void testBucketListInvalidOAuthTokensList() throws Exception {
179179
new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener());
180180
assertNotEquals(OAuthTokens.EMPTY, credentials.getOauth());
181181
assertNotEquals(TemporaryAccessTokens.EMPTY, credentials.getTokens());
182-
host.getCredentials().reset();
182+
credentials.reset();
183183
assertEquals(OAuthTokens.EMPTY, credentials.getOauth());
184184
assertEquals(TemporaryAccessTokens.EMPTY, credentials.getTokens());
185185
new S3BucketListService(session).list(

0 commit comments

Comments
 (0)