public S3TokenExpiredResponseInterceptor(final S3Session session, final LoginCallback prompt) { this.host = session.getHost(); this.prompt = prompt; }
@Override protected boolean isTargettingGoogleStorageService() { return session.getHost().getHostname().equals(Constants.GS_DEFAULT_HOSTNAME); }
@Override public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { if(response.containsHeader("x-amz-bucket-region")) { final String host = ((HttpUriRequest) request).getURI().getHost(); if(!StringUtils.equals(session.getHost().getHostname(), host)) { regionEndpointCache.putRegionForBucketName( StringUtils.split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0], response.getFirstHeader("x-amz-bucket-region").getValue()); } } return super.getRedirect(request, response, context); } });
@Override public Set<Name> getLocations() { if(StringUtils.isNotBlank(session.getHost().getRegion())) { return Collections.singleton(new S3Region(session.getHost().getRegion())); } // Only for AWS if(session.getHost().getHostname().endsWith(PreferencesFactory.get().getProperty("s3.hostname.default"))) { return session.getHost().getProtocol().getRegions(); } return Collections.emptySet(); }
private String getHostnameForContainer(final Path bucket) { if(!ServiceUtils.isBucketNameValidDNSName(containerService.getContainer(bucket).getName())) { return session.getHost().getHostname(); } if(session.getHost().getHostname().equals(session.getHost().getProtocol().getDefaultHostname())) { return String.format("%s.%s", bucket.getName(), session.getHost().getHostname()); } return session.getHost().getHostname(); } }
private boolean accelerate(final Path file, final ConnectionCallback prompt) throws BackgroundException { switch(session.getSignatureVersion()) { case AWS2: return false; } if(accelerationService.getStatus(file)) { log.info(String.format("S3 transfer acceleration enabled for file %s", file)); return true; } if(preferences.getBoolean("s3.accelerate.prompt")) { if(accelerationService.prompt(session.getHost(), file, prompt)) { log.info(String.format("S3 transfer acceleration enabled for file %s", file)); return true; } } return false; } }
/** * Distribution methods supported by this S3 provider. * * @return Download and Streaming for AWS. */ @Override public List<Distribution.Method> getMethods(final Path container) { if(!ServiceUtils.isBucketNameValidDNSName(container.getName())) { // Disable website configuration if bucket name is not DNS compatible return super.getMethods(container); } final List<Distribution.Method> methods = new ArrayList<Distribution.Method>(); if(session.getHost().getHostname().endsWith(preferences.getProperty("s3.hostname.default"))) { methods.addAll(super.getMethods(container)); methods.addAll(Arrays.asList(Distribution.WEBSITE, Distribution.WEBSITE_CDN)); } else { // Only allow website configuration for non AWS endpoints. methods.add(Distribution.WEBSITE); } return methods; }
/** * Properly URI encode and prepend the bucket name. * * @param scheme Protocol * @return URL to be displayed in browser */ protected DescriptiveUrl toUrl(final Path file, final Scheme scheme) { final StringBuilder url = new StringBuilder(scheme.name()); url.append("://"); if(file.isRoot()) { url.append(session.getHost().getHostname()); } else { final String hostname = this.getHostnameForContainer(containerService.getContainer(file)); if(hostname.startsWith(containerService.getContainer(file).getName())) { url.append(hostname); if(!containerService.isContainer(file)) { url.append(Path.DELIMITER); url.append(URIEncoder.encode(containerService.getKey(file))); } } else { url.append(session.getHost().getHostname()); url.append(URIEncoder.encode(file.getAbsolute())); } } return new DescriptiveUrl(URI.create(url.toString()), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), scheme.name().toUpperCase(Locale.ROOT))); }
@Override protected Map<Path, Distribution> operate(final PasswordCallback callback, final Path file) throws BackgroundException { final DistributionConfiguration feature = session.getFeature(DistributionConfiguration.class); if(null == feature) { return Collections.emptyMap(); } final AttributedList<Path> containers = new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list(file, new DisabledListProgressListener()); final Map<Path, Distribution> distributions = new ConcurrentHashMap<>(); for(Path container : containers) { for(Distribution.Method method : feature.getMethods(container)) { if(Distribution.WEBSITE.equals(method)) { continue; } if(Distribution.WEBSITE_CDN.equals(method)) { continue; } final Distribution distribution = feature.read(container, method, new DisabledLoginCallback()); if(distribution.isEnabled()) { if(log.isInfoEnabled()) { log.info(String.format("Cache distribution %s", distribution)); } distributions.put(container, distribution); } } } return distributions; } }
final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in keychain required to sign temporary URL"); return DescriptiveUrl.EMPTY; String region = session.getHost().getRegion(); if(session.isConnected()) { if(session.getClient().getRegionEndpointCache().containsRegionForBucketName(containerService.getContainer(file).getName())) { session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), expiry.getTimeInMillis())), DescriptiveUrl.Type.signed,
/** * Prompt for MFA credentials * * @param mfaSerial Serial number for a hardware device (such as GAHT12345678) or an Amazon Resource Name (ARN) for * a virtual device (such as arn:aws:iam::123456789012:mfa/user) * @param callback Prompt controller * @return MFA one time authentication password. * @throws ch.cyberduck.core.exception.ConnectionCanceledException Prompt dismissed */ @Override public Credentials getToken(final String mfaSerial, final PasswordCallback callback) throws ConnectionCanceledException { // Prompt for multi factor authentication credentials. return callback.prompt( session.getHost(), LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), String.format("%s %s", LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), mfaSerial), new LoginOptions() .icon(session.getHost().getProtocol().disk()) .password(true) .user(false) .passwordPlaceholder(LocaleFactory.localizedString("MFA Authentication Code", "S3")) .keychain(false) ); } }
@Override protected HttpUriRequest setupConnection(final HTTP_METHOD method, final String bucketName, final String objectKey, final Map<String, String> requestParameters) throws S3ServiceException { final HttpUriRequest request = super.setupConnection(method, bucketName, objectKey, requestParameters); if(preferences.getBoolean("s3.upload.expect-continue")) { if("PUT".equals(request.getMethod())) { // #7621 final Jets3tProperties properties = getJetS3tProperties(); if(!properties.getBoolProperty("s3service.disable-expect-continue", false)) { request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE); } } } if(preferences.getBoolean("s3.bucket.requesterpays")) { // Only for AWS if(session.getHost().getHostname().endsWith(preferences.getProperty("s3.hostname.default"))) { // Downloading Objects in Requester Pays Buckets if("GET".equals(request.getMethod()) || "POST".equals(request.getMethod())) { final Jets3tProperties properties = getJetS3tProperties(); if(!properties.getBoolProperty("s3service.disable-request-payer", false)) { // For GET and POST requests, include x-amz-request-payer : requester in the header request.addHeader("x-amz-request-payer", "requester"); } } } } return request; }
if(file.isFile()) { list.add(this.toUrl(file, session.getHost().getProtocol().getScheme())); list.add(this.toUrl(file, Scheme.http)); if(!session.getHost().getCredentials().isAnonymousLogin()) { list.add(new DescriptiveUrl(URI.create(new S3TorrentUrlProvider(session.getHost()).create( containerService.getContainer(file).getName(), containerService.getKey(file))), DescriptiveUrl.Type.torrent, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Torrent")))); list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file)); if(!file.isRoot()) { list.add(new DescriptiveUrl(URI.create(String.format("s3://%s%s",
status.getTargetBucketName()); try { configuration.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList());
@Override public Distribution read(final Path container, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { if(method.equals(Distribution.WEBSITE)) { try { final WebsiteConfig configuration = session.getClient().getWebsiteConfig(container.getName()); final Distribution distribution = new Distribution(this.getOrigin(container, method), method, configuration.isWebsiteConfigActive()); distribution.setStatus(LocaleFactory.localizedString("Deployed", "S3")); // http://example-bucket.s3-website-us-east-1.amazonaws.com/ distribution.setUrl(URI.create(String.format("%s://%s", method.getScheme(), this.getWebsiteHostname(container)))); distribution.setIndexDocument(configuration.getIndexDocumentSuffix()); distribution.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList()); return distribution; } catch(ServiceException e) { // Not found. Website configuration not enabled. final Distribution distribution = new Distribution(this.getOrigin(container, method), method, false); distribution.setStatus(e.getErrorMessage()); distribution.setUrl(URI.create(String.format("%s://%s", method.getScheme(), this.getWebsiteHostname(container)))); return distribution; } } else { return super.read(container, method, prompt); } }
if(directory.isRoot()) { return new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list(directory, listener);
distribution.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList());
distribution.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList());
public KMSEncryptionFeature(final S3Session session, final int timeout) { super(session); this.bookmark = session.getHost(); configuration = new ClientConfiguration(); configuration.setConnectionTimeout(timeout); configuration.setSocketTimeout(timeout); final UseragentProvider ua = new PreferencesUseragentProvider(); configuration.setUserAgentPrefix(ua.get()); configuration.setMaxErrorRetry(0); configuration.setMaxConnections(1); configuration.setUseGzip(PreferencesFactory.get().getBoolean("http.compression.enable")); final Proxy proxy = ProxyFactory.get().find(bookmark); switch(proxy.getType()) { case HTTP: case HTTPS: configuration.setProxyHost(proxy.getHostname()); configuration.setProxyPort(proxy.getPort()); } locationFeature = session.getFeature(Location.class); }
public CloudFrontDistributionConfiguration(final S3Session session, final Map<Path, Distribution> distributions) { this.session = session; this.bookmark = session.getHost(); this.distributions = distributions; final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000; configuration = new ClientConfiguration(); configuration.setConnectionTimeout(timeout); configuration.setSocketTimeout(timeout); final UseragentProvider ua = new PreferencesUseragentProvider(); configuration.setUserAgentPrefix(ua.get()); configuration.setMaxErrorRetry(0); configuration.setMaxConnections(1); configuration.setUseGzip(preferences.getBoolean("http.compression.enable")); final Proxy proxy = ProxyFactory.get().find(bookmark); switch(proxy.getType()) { case HTTP: case HTTPS: configuration.setProxyHost(proxy.getHostname()); configuration.setProxyPort(proxy.getPort()); } locationFeature = session.getFeature(Location.class); }