@Test public void testToSignedUrl() { final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( System.getProperties().getProperty("s3.key"), null ))); final S3UrlProvider provider = new S3UrlProvider(session, new DisabledPasswordStore() { @Override public String findLoginPassword(final Host bookmark) { return "k"; } }); assertTrue(provider.sign(new Path("/test-us-east-1-cyberduck/test", EnumSet.of(Path.Type.file)), 30).getUrl().startsWith( "https: }
protected DescriptiveUrl sign(final Path file, final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in password store 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())) { region = session.getClient().getRegionEndpointCache() .getRegionForBucketName(containerService.getContainer(file).getName()); } } return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), "GET", expiry.getTimeInMillis())), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); }
S3UrlProvider implements UrlProvider { protected DescriptiveUrl sign(final Path file, final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in password store 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())) { region = session.getClient().getRegionEndpointCache() .getRegionForBucketName(containerService.getContainer(file).getName()); } } return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), "GET", expiry.getTimeInMillis())), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } }
S3UrlProvider implements UrlProvider { protected DescriptiveUrl sign(final Path file, final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in password store 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())) { region = session.getClient().getRegionEndpointCache() .getRegionForBucketName(containerService.getContainer(file).getName()); } } return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), "GET", expiry.getTimeInMillis())), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } S3UrlProvider(final S3Session session);  S3UrlProvider(final S3Session session, final HostPasswordStore store); }
S3UrlProvider implements UrlProvider { protected DescriptiveUrl sign(final Path file, final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in password store 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())) { region = session.getClient().getRegionEndpointCache() .getRegionForBucketName(containerService.getContainer(file).getName()); } } return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), "GET", expiry.getTimeInMillis())), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } S3UrlProvider(final S3Session session);  S3UrlProvider(final S3Session session, final HostPasswordStore store); @Override DescriptiveUrlBag toUrl(final Path file); }
S3UrlProvider implements UrlProvider { protected DescriptiveUrl sign(final Path file, final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String secret = store.findLoginPassword(session.getHost()); if(StringUtils.isBlank(secret)) { log.warn("No secret found in password store 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())) { region = session.getClient().getRegionEndpointCache() .getRegionForBucketName(containerService.getContainer(file).getName()); } } return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret, containerService.getContainer(file).getName(), region, containerService.getKey(file), "GET", expiry.getTimeInMillis())), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } S3UrlProvider(final S3Session session);  S3UrlProvider(final S3Session session, final HostPasswordStore store); @Override DescriptiveUrlBag toUrl(final Path file);  }