Skip to content

Commit e2cfa56

Browse files
committed
Fix #13738.
1 parent 0fbbce8 commit e2cfa56

File tree

3 files changed

+30
-51
lines changed

3 files changed

+30
-51
lines changed

s3/src/main/java/ch/cyberduck/core/s3/S3Session.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ protected XmlResponsesSaxParser getXmlResponseSaxParser() throws ServiceExceptio
160160
return new XmlResponsesSaxParser(client.getConfiguration(), false);
161161
}
162162

163+
public S3CredentialsStrategy getAuthentication() {
164+
return authentication;
165+
}
166+
163167
/**
164168
* @return the identifier for the signature algorithm.
165169
*/
@@ -289,21 +293,17 @@ protected S3CredentialsStrategy configureCredentialsStrategy(final ProxyFinder p
289293
);
290294
}
291295
else {
296+
final Credentials credentials = new S3CredentialsConfigurator(
297+
new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt).reload().configure(host);
292298
// Fetch temporary session token from AWS CLI configuration
293-
interceptor = new S3AuthenticationResponseInterceptor(this, new S3CredentialsStrategy() {
294-
@Override
295-
public Credentials get() throws LoginCanceledException {
296-
return new S3CredentialsConfigurator(
297-
new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt).reload().configure(host);
298-
}
299-
});
299+
interceptor = new S3AuthenticationResponseInterceptor(this, () -> credentials);
300300
}
301301
configuration.setServiceUnavailableRetryStrategy(new CustomServiceUnavailableRetryStrategy(host,
302302
new ExecutionCountServiceUnavailableRetryStrategy(interceptor)));
303303
return interceptor;
304304
}
305305
else {
306-
return host::getCredentials;
306+
return () -> new Credentials(host.getCredentials());
307307
}
308308
}
309309
}

s3/src/main/java/ch/cyberduck/core/s3/S3UrlProvider.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@
1717
* Bug fixes, suggestions and comments should be sent to [email protected]
1818
*/
1919

20-
import ch.cyberduck.core.*;
20+
import ch.cyberduck.core.DescriptiveUrl;
21+
import ch.cyberduck.core.DescriptiveUrlBag;
22+
import ch.cyberduck.core.HostWebUrlProvider;
23+
import ch.cyberduck.core.LocaleFactory;
24+
import ch.cyberduck.core.Path;
25+
import ch.cyberduck.core.PathContainerService;
26+
import ch.cyberduck.core.Scheme;
27+
import ch.cyberduck.core.SimplePathPredicate;
28+
import ch.cyberduck.core.URIEncoder;
29+
import ch.cyberduck.core.UrlProvider;
30+
import ch.cyberduck.core.UserDateFormatterFactory;
2131
import ch.cyberduck.core.cdn.Distribution;
2232
import ch.cyberduck.core.cdn.DistributionUrlProvider;
33+
import ch.cyberduck.core.exception.BackgroundException;
2334
import ch.cyberduck.core.preferences.HostPreferencesFactory;
2435
import ch.cyberduck.core.shared.DefaultUrlProvider;
2536

@@ -45,16 +56,10 @@ public class S3UrlProvider implements UrlProvider {
4556
private final S3Session session;
4657
private final PathContainerService containerService;
4758
private final Map<Path, Set<Distribution>> distributions;
48-
private final HostPasswordStore store;
4959

5060
public S3UrlProvider(final S3Session session, final Map<Path, Set<Distribution>> distributions) {
51-
this(session, distributions, PasswordStoreFactory.get());
52-
}
53-
54-
public S3UrlProvider(final S3Session session, final Map<Path, Set<Distribution>> distributions, final HostPasswordStore store) {
5561
this.session = session;
5662
this.distributions = distributions;
57-
this.store = store;
5863
this.containerService = session.getFeature(PathContainerService.class);
5964
}
6065

@@ -198,12 +203,12 @@ public PresignedUrl(final Path file, final Calendar expiry) {
198203
@Override
199204
public String getUrl() {
200205
final String secret;
201-
final Credentials credentials = CredentialsConfiguratorFactory.get(session.getHost().getProtocol()).configure(session.getHost());
202-
if(credentials.isPasswordAuthentication()) {
203-
secret = credentials.getPassword();
206+
try {
207+
secret = session.getAuthentication().get().getPassword();
204208
}
205-
else {
206-
secret = store.findLoginPassword(session.getHost());
209+
catch(BackgroundException e) {
210+
log.error("Failure retrieving secret required to sign temporary URL", e);
211+
return DescriptiveUrl.EMPTY.getUrl();
207212
}
208213
if(StringUtils.isBlank(secret)) {
209214
log.error("No secret found in password store required to sign temporary URL");

s3/src/test/java/ch/cyberduck/core/s3/S3UrlProviderTest.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import ch.cyberduck.core.DisabledCancelCallback;
77
import ch.cyberduck.core.DisabledHostKeyCallback;
88
import ch.cyberduck.core.DisabledLoginCallback;
9-
import ch.cyberduck.core.DisabledPasswordStore;
109
import ch.cyberduck.core.Host;
1110
import ch.cyberduck.core.Path;
1211
import ch.cyberduck.core.exception.BackgroundException;
@@ -45,12 +44,7 @@ public RequestEntityRestStorageService getClient() {
4544
}
4645
};
4746
Path p = new Path("/bucket/f/key f", EnumSet.of(Path.Type.file));
48-
assertEquals(5, new S3UrlProvider(session, Collections.emptyMap(), new DisabledPasswordStore() {
49-
@Override
50-
public String findLoginPassword(final Host bookmark) {
51-
return "k";
52-
}
53-
}).toUrl(p).filter(DescriptiveUrl.Type.signed).size());
47+
assertEquals(5, new S3UrlProvider(session, Collections.emptyMap()).toUrl(p).filter(DescriptiveUrl.Type.signed).size());
5448
}
5549

5650
@Test
@@ -122,12 +116,7 @@ public RequestEntityRestStorageService getClient() {
122116
}
123117
};
124118
assertEquals(DescriptiveUrl.EMPTY,
125-
new S3UrlProvider(session, Collections.emptyMap(), new DisabledPasswordStore() {
126-
@Override
127-
public String findLoginPassword(final Host bookmark) {
128-
return "k";
129-
}
130-
}).toUrl(new Path("/test-eu-west-1-cyberduck/test f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.signed)
119+
new S3UrlProvider(session, Collections.emptyMap()).toUrl(new Path("/test-eu-west-1-cyberduck/test f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.signed)
131120
);
132121
}
133122

@@ -146,37 +135,22 @@ public RequestEntityRestStorageService getClient() {
146135
}
147136
}
148137
};
149-
final S3UrlProvider provider = new S3UrlProvider(session, Collections.emptyMap(), new DisabledPasswordStore() {
150-
@Override
151-
public String findLoginPassword(final Host bookmark) {
152-
return "k";
153-
}
154-
});
138+
final S3UrlProvider provider = new S3UrlProvider(session, Collections.emptyMap());
155139
assertNotNull(
156140
provider.toUrl(new Path("/test-eu-west-1-cyberduck/test", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.signed)
157141
);
158142
}
159143

160144
@Test
161145
public void testToSignedUrl() {
162-
final S3UrlProvider provider = new S3UrlProvider(session, Collections.emptyMap(), new DisabledPasswordStore() {
163-
@Override
164-
public String findLoginPassword(final Host bookmark) {
165-
return "k";
166-
}
167-
});
146+
final S3UrlProvider provider = new S3UrlProvider(session, Collections.emptyMap());
168147
assertTrue(provider.toSignedUrl(new Path("/test-eu-west-1-cyberduck/test", EnumSet.of(Path.Type.file)), 30).getUrl().startsWith(
169148
"https://test-eu-west-1-cyberduck.s3.amazonaws.com/test?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential="));
170149
}
171150

172151
@Test
173152
public void testToSignedUrlVirtualHost() {
174-
final S3UrlProvider provider = new S3UrlProvider(virtualhost, Collections.emptyMap(), new DisabledPasswordStore() {
175-
@Override
176-
public String findLoginPassword(final Host bookmark) {
177-
return "k";
178-
}
179-
});
153+
final S3UrlProvider provider = new S3UrlProvider(virtualhost, Collections.emptyMap());
180154
final String url = provider.toSignedUrl(new Path("/t", EnumSet.of(Path.Type.file)), 30).getUrl();
181155
assertTrue(url, url.startsWith(
182156
"https://test-eu-central-1-cyberduck.s3.amazonaws.com/t?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential="));

0 commit comments

Comments
 (0)