@Test public void testReadLoginFailureFix() throws Exception { assertTrue(session.isConnected()); session.getHost().getCredentials().setPassword(null); assertNull(session.getHost().getCredentials().getPassword()); final DistributionConfiguration configuration = new CloudFrontDistributionConfiguration(session, new DisabledX509TrustManager(), new DefaultX509KeyManager(), Collections.emptyMap()); final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final AtomicBoolean set = new AtomicBoolean(); configuration.read(container, Distribution.DOWNLOAD, new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) { set.set(true); return new Credentials(username, System.getProperties().getProperty("s3.secret")); } }); assertTrue(set.get()); session.close(); }
@Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); return this.authenticated(new Authenticated<Distribution>() { @Override public Distribution call() throws BackgroundException { try { if(log.isDebugEnabled()) { log.debug(String.format("List %s distributions", method)); } final AmazonCloudFront client = client(container); if(method.equals(Distribution.STREAMING)) { for(StreamingDistributionSummary d : client.listStreamingDistributions( new ListStreamingDistributionsRequest()).getStreamingDistributionList().getItems()) { final S3Origin config = d.getS3Origin(); if(config != null) { final URI origin = getOrigin(container, method); if(config.getDomainName().equals(origin.getHost())) { return readStreamingDistribution(client, d, container, method); } } } } else if(method.equals(Distribution.DOWNLOAD)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final S3OriginConfig config = o.getS3OriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } else if(method.equals(Distribution.CUSTOM) || method.equals(Distribution.WEBSITE_CDN)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final CustomOriginConfig config = o.getCustomOriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } final URI origin = getOrigin(container, method); return new Distribution(origin, method, false); } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e); } } }, prompt); }
CloudFrontDistributionConfiguration implements DistributionConfiguration, Purge, Index, DistributionLogging, Cname { @Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); return this.authenticated(new Authenticated<Distribution>() { @Override public Distribution call() throws BackgroundException { try { if(log.isDebugEnabled()) { log.debug(String.format("List %s distributions", method)); } final AmazonCloudFront client = client(container); if(method.equals(Distribution.STREAMING)) { for(StreamingDistributionSummary d : client.listStreamingDistributions( new ListStreamingDistributionsRequest()).getStreamingDistributionList().getItems()) { final S3Origin config = d.getS3Origin(); if(config != null) { final URI origin = getOrigin(container, method); if(config.getDomainName().equals(origin.getHost())) { return readStreamingDistribution(client, d, container, method); } } } } else if(method.equals(Distribution.DOWNLOAD)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final S3OriginConfig config = o.getS3OriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } else if(method.equals(Distribution.CUSTOM) || method.equals(Distribution.WEBSITE_CDN)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final CustomOriginConfig config = o.getCustomOriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } final URI origin = getOrigin(container, method); return new Distribution(origin, method, false); } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e); } } }, prompt); } }
CloudFrontDistributionConfiguration implements DistributionConfiguration, Purge, Index, DistributionLogging, Cname { @Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); return this.authenticated(new Authenticated<Distribution>() { @Override public Distribution call() throws BackgroundException { try { if(log.isDebugEnabled()) { log.debug(String.format("List %s distributions", method)); } final AmazonCloudFront client = client(container); if(method.equals(Distribution.STREAMING)) { for(StreamingDistributionSummary d : client.listStreamingDistributions( new ListStreamingDistributionsRequest()).getStreamingDistributionList().getItems()) { final S3Origin config = d.getS3Origin(); if(config != null) { final URI origin = getOrigin(container, method); if(config.getDomainName().equals(origin.getHost())) { return readStreamingDistribution(client, d, container, method); } } } } else if(method.equals(Distribution.DOWNLOAD)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final S3OriginConfig config = o.getS3OriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } else if(method.equals(Distribution.CUSTOM) || method.equals(Distribution.WEBSITE_CDN)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final CustomOriginConfig config = o.getCustomOriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } final URI origin = getOrigin(container, method); return new Distribution(origin, method, false); } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e); } } }, prompt); } CloudFrontDistributionConfiguration(final S3Session session, final X509TrustManager trust, final X509KeyManager key,
                                               final Map<Path, Distribution> distributions); }
CloudFrontDistributionConfiguration implements DistributionConfiguration, Purge, Index, DistributionLogging, Cname { @Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); return this.authenticated(new Authenticated<Distribution>() { @Override public Distribution call() throws BackgroundException { try { if(log.isDebugEnabled()) { log.debug(String.format("List %s distributions", method)); } final AmazonCloudFront client = client(container); if(method.equals(Distribution.STREAMING)) { for(StreamingDistributionSummary d : client.listStreamingDistributions( new ListStreamingDistributionsRequest()).getStreamingDistributionList().getItems()) { final S3Origin config = d.getS3Origin(); if(config != null) { final URI origin = getOrigin(container, method); if(config.getDomainName().equals(origin.getHost())) { return readStreamingDistribution(client, d, container, method); } } } } else if(method.equals(Distribution.DOWNLOAD)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final S3OriginConfig config = o.getS3OriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } else if(method.equals(Distribution.CUSTOM) || method.equals(Distribution.WEBSITE_CDN)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final CustomOriginConfig config = o.getCustomOriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } final URI origin = getOrigin(container, method); return new Distribution(origin, method, false); } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e); } } }, prompt); } CloudFrontDistributionConfiguration(final S3Session session, final X509TrustManager trust, final X509KeyManager key,
                                               final Map<Path, Distribution> distributions); @Override String getName(); @Override String getName(final Distribution.Method method); @Override String getHostname(); @Override DescriptiveUrlBag toUrl(final Path file); @Override List<Distribution.Method> getMethods(final Path container); @Override Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt); @Override void write(final Path file, final Distribution distribution, final LoginCallback prompt); @Override @SuppressWarnings("unchecked") T getFeature(final Class<T> type, final Distribution.Method method); @Override void invalidate(final Path container, final Distribution.Method method, final List<Path> files, final LoginCallback prompt); }
CloudFrontDistributionConfiguration implements DistributionConfiguration, Purge, Index, DistributionLogging, Cname { @Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); return this.authenticated(new Authenticated<Distribution>() { @Override public Distribution call() throws BackgroundException { try { if(log.isDebugEnabled()) { log.debug(String.format("List %s distributions", method)); } final AmazonCloudFront client = client(container); if(method.equals(Distribution.STREAMING)) { for(StreamingDistributionSummary d : client.listStreamingDistributions( new ListStreamingDistributionsRequest()).getStreamingDistributionList().getItems()) { final S3Origin config = d.getS3Origin(); if(config != null) { final URI origin = getOrigin(container, method); if(config.getDomainName().equals(origin.getHost())) { return readStreamingDistribution(client, d, container, method); } } } } else if(method.equals(Distribution.DOWNLOAD)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final S3OriginConfig config = o.getS3OriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } else if(method.equals(Distribution.CUSTOM) || method.equals(Distribution.WEBSITE_CDN)) { for(DistributionSummary d : client.listDistributions( new ListDistributionsRequest()).getDistributionList().getItems()) { for(Origin o : d.getOrigins().getItems()) { final CustomOriginConfig config = o.getCustomOriginConfig(); if(config != null) { final URI origin = getOrigin(container, method); if(o.getDomainName().equals(origin.getHost())) { return readDownloadDistribution(client, d, container, method); } } } } } final URI origin = getOrigin(container, method); return new Distribution(origin, method, false); } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e); } } }, prompt); } CloudFrontDistributionConfiguration(final S3Session session, final X509TrustManager trust, final X509KeyManager key,
                                               final Map<Path, Distribution> distributions); @Override String getName(); @Override String getName(final Distribution.Method method); @Override String getHostname(); @Override DescriptiveUrlBag toUrl(final Path file); @Override List<Distribution.Method> getMethods(final Path container); @Override Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt); @Override void write(final Path file, final Distribution distribution, final LoginCallback prompt); @Override @SuppressWarnings("unchecked") T getFeature(final Class<T> type, final Distribution.Method method); @Override void invalidate(final Path container, final Distribution.Method method, final List<Path> files, final LoginCallback prompt);  }