public final class BlobServiceSasSignatureValues extends Object
generateSasQueryParameters(StorageSharedKeyCredential)
or
generateSasQueryParameters(UserDelegationKey, String)
to obtain a representation of the SAS which can be applied to blob urls.
Generating SAS query parameters with StorageSharedKeyCredential
BlobSasPermission
blobPermission = newBlobSasPermission
().setReadPermission(true); // We are creating a SAS to a blob because we set both the container name and blob name.BlobServiceSasSignatureValues
builder = newBlobServiceSasSignatureValues
() .setProtocol(SasProtocol
.HTTPS_ONLY) // Users MUST use HTTPS (not HTTP). .setExpiryTime(OffsetDateTime
.now().plusDays(2)) .setContainerName("my-container") .setBlobName("HelloWorld.txt") .setPermissions(blobPermission);StorageSharedKeyCredential
credential = newStorageSharedKeyCredential
("account-name", "key");BlobServiceSasQueryParameters
sasQueryParameters = builder.generateSasQueryParameters(credential);
Generating SAS query parameters with UserDelegationKey
BlobSasPermission
blobPermission = newBlobSasPermission
() .setReadPermission(true) .setWritePermission(true); // We are creating a SAS to a container because only container name is set.BlobServiceSasSignatureValues
builder = newBlobServiceSasSignatureValues
() .setProtocol(SasProtocol
.HTTPS_ONLY) // Users MUST use HTTPS (not HTTP). .setExpiryTime(OffsetDateTime
.now().plusDays(2)) .setContainerName("my-container") .setPermissions(blobPermission); // Get a user delegation key after signing in with Azure ADUserDelegationKey
credential = newUserDelegationKey
();String
account = "my-blob-storage-account";BlobServiceSasQueryParameters
sasQueryParameters = builder.generateSasQueryParameters(credential, account);
Constructor and Description |
---|
BlobServiceSasSignatureValues()
Creates an object with empty values for all fields.
|
BlobServiceSasSignatureValues(String version,
SasProtocol sasProtocol,
OffsetDateTime startTime,
OffsetDateTime expiryTime,
String permission,
SasIpRange sasIpRange,
String identifier,
String cacheControl,
String contentDisposition,
String contentEncoding,
String contentLanguage,
String contentType) |
Modifier and Type | Method and Description |
---|---|
BlobServiceSasQueryParameters |
generateSasQueryParameters(StorageSharedKeyCredential storageSharedKeyCredentials)
Uses an account's shared key credential to sign these signature values to produce the proper SAS query
parameters.
|
BlobServiceSasQueryParameters |
generateSasQueryParameters(UserDelegationKey delegationKey,
String accountName)
Uses a user delegation key to sign these signature values to produce the proper SAS query parameters.
|
String |
getBlobName()
Decodes and gets the name of the blob the SAS user may access.
|
String |
getCacheControl() |
String |
getContainerName()
Gets the name of the container the SAS user may access.
|
String |
getContentDisposition() |
String |
getContentEncoding() |
String |
getContentLanguage() |
String |
getContentType() |
OffsetDateTime |
getExpiryTime() |
String |
getIdentifier() |
String |
getPermissions() |
SasProtocol |
getProtocol() |
SasIpRange |
getSasIpRange() |
String |
getSnapshotId() |
OffsetDateTime |
getStartTime() |
String |
getVersion() |
BlobServiceSasSignatureValues |
setBlobName(String blobName)
Sets the blob the SAS user may access.
|
BlobServiceSasSignatureValues |
setCacheControl(String cacheControl)
Sets the cache-control header for the SAS.
|
BlobServiceSasSignatureValues |
setContainerName(String containerName)
Sets the container the SAS user may access.
|
BlobServiceSasSignatureValues |
setContentDisposition(String contentDisposition)
Sets the content-disposition header for the SAS.
|
BlobServiceSasSignatureValues |
setContentEncoding(String contentEncoding)
Sets the content-encoding header for the SAS.
|
BlobServiceSasSignatureValues |
setContentLanguage(String contentLanguage)
Sets the content-language header for the SAS.
|
BlobServiceSasSignatureValues |
setContentType(String contentType)
Sets the content-type header for the SAS.
|
BlobServiceSasSignatureValues |
setExpiryTime(OffsetDateTime expiryTime)
Sets the time after which the SAS will no longer work.
|
BlobServiceSasSignatureValues |
setIdentifier(String identifier)
Sets the name of the access policy on the container this SAS references if any.
|
BlobServiceSasSignatureValues |
setPermissions(BlobContainerSasPermission permissions)
Sets the Container permissions allowed by the SAS.
|
BlobServiceSasSignatureValues |
setPermissions(BlobSasPermission permissions)
Sets the Blob permissions allowed by the SAS.
|
BlobServiceSasSignatureValues |
setProtocol(SasProtocol protocol)
Sets the
SasProtocol which determines the protocols allowed by the SAS. |
BlobServiceSasSignatureValues |
setSasIpRange(SasIpRange sasIpRange)
Sets the
SasIpRange which determines the IP ranges that are allowed to use the SAS. |
BlobServiceSasSignatureValues |
setSnapshotId(String snapshotId)
Sets the specific snapshot the SAS user may access.
|
BlobServiceSasSignatureValues |
setStartTime(OffsetDateTime startTime)
Sets when the SAS will take effect.
|
BlobServiceSasSignatureValues |
setVersion(String version)
Sets the version of the service this SAS will target.
|
public BlobServiceSasSignatureValues()
public BlobServiceSasSignatureValues(String version, SasProtocol sasProtocol, OffsetDateTime startTime, OffsetDateTime expiryTime, String permission, SasIpRange sasIpRange, String identifier, String cacheControl, String contentDisposition, String contentEncoding, String contentLanguage, String contentType)
public String getVersion()
public BlobServiceSasSignatureValues setVersion(String version)
version
- Version to targetpublic SasProtocol getProtocol()
SasProtocol
which determines the protocols allowed by the SAS.public BlobServiceSasSignatureValues setProtocol(SasProtocol protocol)
SasProtocol
which determines the protocols allowed by the SAS.protocol
- Protocol for the SASpublic OffsetDateTime getStartTime()
public BlobServiceSasSignatureValues setStartTime(OffsetDateTime startTime)
startTime
- When the SAS takes effectpublic OffsetDateTime getExpiryTime()
public BlobServiceSasSignatureValues setExpiryTime(OffsetDateTime expiryTime)
expiryTime
- When the SAS will no longer workpublic String getPermissions()
BlobContainerSasPermission
or
BlobSasPermission
depending on the resource being accessed for help determining the permissions allowed.public BlobServiceSasSignatureValues setPermissions(BlobSasPermission permissions)
permissions
- BlobSasPermission
NullPointerException
- if permissions
is null.public BlobServiceSasSignatureValues setPermissions(BlobContainerSasPermission permissions)
permissions
- BlobContainerSasPermission
NullPointerException
- if permissions
is null.public SasIpRange getSasIpRange()
SasIpRange
which determines the IP ranges that are allowed to use the SAS.public BlobServiceSasSignatureValues setSasIpRange(SasIpRange sasIpRange)
SasIpRange
which determines the IP ranges that are allowed to use the SAS.sasIpRange
- Allowed IP range to setpublic String getContainerName()
public BlobServiceSasSignatureValues setContainerName(String containerName)
containerName
- The name of the container.public String getBlobName()
null
or an empty string is returned when a
creating a container SAS.null
or an empty string is returned when a
creating a container SAS.public BlobServiceSasSignatureValues setBlobName(String blobName)
null
or an empty string to create a container SAS.blobName
- The name of the blob. Use null
or an empty string to create a container SAS.public String getSnapshotId()
public BlobServiceSasSignatureValues setSnapshotId(String snapshotId)
BlobServiceSasSignatureValues.resource
will be set to BlobServiceSasSignatureValues.SAS_BLOB_SNAPSHOT_CONSTANT
if the passed snapshotId
isn't
null
amd BlobServiceSasSignatureValues.resource
is set to BlobServiceSasSignatureValues.SAS_BLOB_CONSTANT
.
snapshotId
- Identifier of the snapshotpublic String getIdentifier()
public BlobServiceSasSignatureValues setIdentifier(String identifier)
identifier
- Name of the access policypublic String getCacheControl()
public BlobServiceSasSignatureValues setCacheControl(String cacheControl)
cacheControl
- Cache-Control header valuepublic String getContentDisposition()
public BlobServiceSasSignatureValues setContentDisposition(String contentDisposition)
contentDisposition
- Content-Disposition header valuepublic String getContentEncoding()
public BlobServiceSasSignatureValues setContentEncoding(String contentEncoding)
contentEncoding
- Content-Encoding header valuepublic String getContentLanguage()
public BlobServiceSasSignatureValues setContentLanguage(String contentLanguage)
contentLanguage
- Content-Language header valuepublic String getContentType()
public BlobServiceSasSignatureValues setContentType(String contentType)
contentType
- Content-Type header valuepublic BlobServiceSasQueryParameters generateSasQueryParameters(StorageSharedKeyCredential storageSharedKeyCredentials)
Notes on SAS generation
version
is not set, the latest service
version
is used.identifier
is set, expiryTime
and
permissions should not be set. These values are inherited from the stored access policy.expiryTime
and permissions
must
be set.The type of SAS query parameters returned depends on the following:
BlobServiceSasSignatureValues.getBlobName()
is not set, container SAS query parameters are returned.BlobServiceSasSignatureValues.getBlobName()
and BlobServiceSasSignatureValues.getSnapshotId()
are set, blob snapshot SAS query parameters
are returned.BlobServiceSasSignatureValues.getBlobName()
is set, blob SAS query parameters are returned.storageSharedKeyCredentials
- A StorageSharedKeyCredential
object used to sign the SAS values.BlobServiceSasQueryParameters
IllegalStateException
- If the HMAC-SHA256 algorithm isn't supported, if the key isn't a valid Base64
encoded string, or the UTF-8 charset isn't supported.IllegalArgumentException
- if BlobServiceSasSignatureValues.getPermissions()
contains an invalid character for the SAS resource.NullPointerException
- if storageSharedKeyCredentials
is null.public BlobServiceSasQueryParameters generateSasQueryParameters(UserDelegationKey delegationKey, String accountName)
Notes on SAS generation
version
is not set, the latest service
version
is used.identifier
is set, expiryTime
and
permissions should not be set. These values are inherited from the stored access policy.expiryTime
and permissions
must
be set.The type of SAS query parameters returned depends on the following:
BlobServiceSasSignatureValues.getBlobName()
is not set, container SAS query parameters are returned.BlobServiceSasSignatureValues.getBlobName()
and BlobServiceSasSignatureValues.getSnapshotId()
are set, blob snapshot SAS query parameters
are returned.BlobServiceSasSignatureValues.getBlobName()
is set, blob SAS query parameters are returned.delegationKey
- A UserDelegationKey
object used to sign the SAS values.accountName
- Azure Storage account name to generate SAS for.BlobServiceSasQueryParameters
IllegalStateException
- If the HMAC-SHA256 algorithm isn't supported, if the key isn't a valid Base64
encoded string, or the UTF-8 charset isn't supported.IllegalArgumentException
- if BlobServiceSasSignatureValues.getPermissions()
contains an invalid character for the SAS resource.NullPointerException
- if delegationKey
or account
is null.Copyright © 2019 Microsoft Corporation. All rights reserved.