@Override public DescriptiveUrl getSetup(final String hostname, final Scheme method, final Path container, final Credentials credentials) { final String setup = String.format("provider=%s,protocol=%s,endpoint=%s,key=%s,secret=%s", hostname, method.name(), containerService.getContainer(container).getName(), credentials.getUsername(), credentials.getPassword()); final String encoded; encoded = this.encode(new String(Base64.encodeBase64(setup.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); final String formatted = String.format("%s?setup=%s", target, encoded); if(log.isInfoEnabled()) { log.info(String.format("Setup URL %s", formatted)); } return new DescriptiveUrl(URI.create(formatted), DescriptiveUrl.Type.analytics); }
/** * @param file File in origin container * @return CNAME to distribution */ private List<DescriptiveUrl> toCnameUrl(final Path file) { final List<DescriptiveUrl> urls = new ArrayList<DescriptiveUrl>(); for(String cname : distribution.getCNAMEs()) { final StringBuilder b = new StringBuilder(); b.append(String.format("%s://%s", distribution.getMethod().getScheme(), cname)).append(distribution.getMethod().getContext()); if(StringUtils.isNotEmpty(containerService.getKey(file))) { b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file))); } urls.add(new DescriptiveUrl(URI.create(b.toString()).normalize(), DescriptiveUrl.Type.cname, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))); } return urls; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.isFile()) { try { // This link will expire in four hours and afterwards you will get 410 Gone. final String link = new DbxUserFilesRequests(session.getClient()).getTemporaryLink(file.getAbsolute()).getLink(); // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.HOUR, 4); list.add(new DescriptiveUrl(URI.create(link), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Temporary", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) )); } catch(DbxException e) { log.warn(String.format("Failure retrieving shared link. %s", e.getMessage())); } } return list; } }
/** * 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))); }
return DescriptiveUrl.EMPTY; return new DescriptiveUrl(uri, DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), StringUtils.upperCase(uri.getScheme())));
@Override public DescriptiveUrlBag toUrl(final Path file) { final String nodeid = file.isDirectory() ? file.attributes().getVersionId() : file.getParent().attributes().getVersionId(); if(StringUtils.isBlank(nodeid)) { return DescriptiveUrlBag.empty(); } return new DescriptiveUrlBag(Collections.singletonList( new DescriptiveUrl(URI.create(String.format("%s/#/node/%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode( nodeid ))), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))) )); } }
for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s://%s%s%s?temp_url_sig=%s&temp_url_expires=%d", scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port),
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); final DescriptiveUrl base = this.toUrl(); list.add(new DescriptiveUrl(URI.create(String.format("%s%s", base.getUrl(), URIEncoder.encode( PathNormalizer.normalize(PathRelativizer.relativize(PathNormalizer.normalize(host.getDefaultPath(), true), file.getAbsolute())) ))).normalize(), base.getType(), base.getHelp()) ); return list; }
/** * This creates an URL that uses Cookie-based Authentication. The ACLs for the given Google user account * has to be setup first. * <p> * Google Storage lets you provide browser-based authenticated downloads to users who do not have * Google Storage accounts. To do this, you apply Google account-based ACLs to the object and then * you provide users with a URL that is scoped to the object. */ @Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DefaultUrlProvider(session.getHost()).toUrl(file); if(file.isFile()) { // Authenticated browser download using cookie-based Google account authentication in conjunction with ACL list.add(new DescriptiveUrl(URI.create(String.format("https://storage.cloud.google.com%s", URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.authenticated, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Authenticated")))); } return list; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { try { final DescriptiveUrlBag set = delegate.toUrl(file); final Path encrypt = vault.encrypt(session, file); set.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode(encrypt.getAbsolute()))), DescriptiveUrl.Type.encrypted, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Encrypted", "Cryptomator"))) ); return set; } catch(BackgroundException e) { log.warn(String.format("Failure encrypting filename. %s", e.getMessage())); return DescriptiveUrlBag.empty(); } }
@Override public DescriptiveUrlBag toUrl(final Path file) { if(file.isVolume()) { return DescriptiveUrlBag.empty(); } final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); list.add(new DescriptiveUrl(URI.create(download), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT)))); } return list; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); list.add(new DescriptiveUrl(this.toUrl(file, distribution.getOrigin()), DescriptiveUrl.Type.origin, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Origin", "Info")))); if(distribution.getUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getUrl()), DescriptiveUrl.Type.cdn, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))); } if(distribution.getSslUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getSslUrl()), DescriptiveUrl.Type.cdn, String.format("%s (SSL)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } if(distribution.getStreamingUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getStreamingUrl()), DescriptiveUrl.Type.cdn, String.format("%s (Streaming)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } if(distribution.getiOSstreamingUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getiOSstreamingUrl()), DescriptiveUrl.Type.cdn, String.format("%s (iOS Streaming)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } list.addAll(this.toCnameUrl(file)); return list; }
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException { if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); try { final int seconds = 604800; // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String token = session.getClient().getDownloadAuthorization(fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds); return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), 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())) ); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } return DescriptiveUrl.EMPTY; }
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Object o, final PasswordCallback callback) throws BackgroundException { try { final OneDriveItem item = session.toItem(file); if(null == item) { throw new NotfoundException(file.getAbsolute()); } return new DescriptiveUrl(URI.create(item.createSharedLink(OneDriveSharingLink.Type.VIEW).getLink().getWebUrl()), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3"))); } catch(OneDriveAPIException e) { throw new GraphExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.attributes().getLink() != null) { list.add(file.attributes().getLink()); } list.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(host), URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), host.getProtocol().getScheme().toString().toUpperCase(Locale.ROOT)))); list.addAll(new WebUrlProvider(host).toUrl(file)); return list; } }
attributes.setLink(new DescriptiveUrl(URI.create(f.getWebViewLink()), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "HTTP"))); if(!DRIVE_FOLDER.equals(f.getMimeType()) && StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) { attributes.setSize(UrlFileWriterFactory.get().write(new DescriptiveUrl(URI.create(f.getWebViewLink()))) .getBytes(Charset.defaultCharset()).length);
@Override public DescriptiveUrl toUploadUrl(final Path file, final CreateUploadShareRequest options, final PasswordCallback callback) throws BackgroundException { try { final UploadShare share = new SharesApi(session.getClient()).createUploadShare( options.targetId(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))), StringUtils.EMPTY, null); final String help; if(null == share.getExpireAt()) { help = MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")); } else { final long expiry = share.getExpireAt().getMillis(); help = MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000) ); } return new DescriptiveUrl( URI.create(String.format("%s://%s/#/public/shares-uploads/%s", session.getHost().getProtocol().getScheme(), session.getHost().getHostname(), share.getAccessKey()) ), DescriptiveUrl.Type.signed, help); } catch(ApiException e) { throw new SDSExceptionMappingService().map(e); } } }
return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create( session.getHost(), session.getHost().getCredentials().getUsername(), secret,
private DescriptiveUrl createSignedUrl(final Path file, int seconds) { final CloudBlob blob; try { if(!session.isConnected()) { return DescriptiveUrl.EMPTY; } blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); } catch(URISyntaxException | StorageException e) { return DescriptiveUrl.EMPTY; } final String token; try { token = blob.generateSharedAccessSignature(this.getPolicy(seconds), null); } catch(InvalidKeyException | StorageException e) { return DescriptiveUrl.EMPTY; } return new DescriptiveUrl(URI.create(String.format("%s://%s%s?%s", Scheme.https.name(), session.getHost().getHostname(), URIEncoder.encode(file.getAbsolute()), token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(this.getExpiry(seconds)))); }
try { final URI link = new URI(joinedPath); attributes.setLink(new DescriptiveUrl(link, DescriptiveUrl.Type.http));