/** * Returns a shared access signature for the blob using the specified group policy identifier and operation context. * Note this does not contain the leading "?". * * @param policy * A <code>SharedAccessPolicy</code> object that represents the access policy for the shared access * signature. * @param groupPolicyIdentifier * A <code>String</code> that represents the container-level access policy. * * @return A <code>String</code> that represents the shared access signature. * * @throws IllegalArgumentException * If the credentials are invalid or the blob is a snapshot. * @throws InvalidKeyException * If the credentials are invalid. * @throws StorageException * If a storage service error occurred. */ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, null /* headers */, groupPolicyIdentifier); }
/** * Returns a shared access signature for the blob using the specified group policy identifier and operation context. * Note this does not contain the leading "?". * * @param policy * A <code>SharedAccessPolicy</code> object that represents the access policy for the shared access * signature. * @param groupPolicyIdentifier * A <code>String</code> that represents the container-level access policy. * * @return A <code>String</code> that represents the shared access signature. * * @throws IllegalArgumentException * If the credentials are invalid or the blob is a snapshot. * @throws InvalidKeyException * If the credentials are invalid. * @throws StorageException * If a storage service error occurred. */ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, null /* headers */, groupPolicyIdentifier); }
/** * Returns a shared access signature for the blob using the specified group policy identifier and operation context. * Note this does not contain the leading "?". * * @param policy * A <code>SharedAccessPolicy</code> object that represents the access policy for the shared access * signature. * @param headers * A <code>{@link SharedAccessBlobHeaders}</code> object that represents the optional header values to * set for a blob accessed with this shared access signature. * @param groupPolicyIdentifier * A <code>String</code> that represents the container-level access policy. * * @return A <code>String</code> that represents the shared access signature. * * @throws IllegalArgumentException * If the credentials are invalid or the blob is a snapshot. * @throws InvalidKeyException * If the credentials are invalid. * @throws StorageException * If a storage service error occurred. */ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy, final SharedAccessBlobHeaders headers, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, headers, groupPolicyIdentifier, null /* IP range */, null /* protocols */); }
/** * Returns a shared access signature for the blob using the specified group policy identifier and operation context. * Note this does not contain the leading "?". * * @param policy * A <code>SharedAccessPolicy</code> object that represents the access policy for the shared access * signature. * @param headers * A <code>{@link SharedAccessBlobHeaders}</code> object that represents the optional header values to * set for a blob accessed with this shared access signature. * @param groupPolicyIdentifier * A <code>String</code> that represents the container-level access policy. * * @return A <code>String</code> that represents the shared access signature. * * @throws IllegalArgumentException * If the credentials are invalid or the blob is a snapshot. * @throws InvalidKeyException * If the credentials are invalid. * @throws StorageException * If a storage service error occurred. */ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy, final SharedAccessBlobHeaders headers, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, headers, groupPolicyIdentifier, null /* IP range */, null /* protocols */); }
private static void testBlobAccess(CloudBlobContainer container, BlobType type, EnumSet<SharedAccessBlobPermissions> permissions, SharedAccessBlobHeaders headers) throws StorageException, IOException, URISyntaxException, InvalidKeyException { CloudBlob blob = BlobTestHelper.uploadNewBlob(container, type, SR.BLOB, 512, null); SharedAccessBlobPolicy policy = createSharedAccessPolicy(permissions, 3600); String sasToken = blob.generateSharedAccessSignature(policy, headers, null); testAccess(sasToken, permissions, headers, null, blob); }
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)))); }
policy.setSharedAccessExpiryTime(cal.getTime()); String sasToken = source.generateSharedAccessSignature(policy, null, null);