Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
35eb6c0
Remove SAS generation methods from Azure Blob clients
alzimmermsft Oct 1, 2019
6baef0a
Add some resource type logic to BlobServiceSASSignatureValues
alzimmermsft Oct 1, 2019
c046ba2
Fix failing test
alzimmermsft Oct 1, 2019
50766c6
Removed SAS token method in File clients
alzimmermsft Oct 1, 2019
7da16db
Removed SAS token methods in Queue clients
alzimmermsft Oct 1, 2019
7cdf2bf
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 1, 2019
b66fd2a
Fixing some more tests
alzimmermsft Oct 2, 2019
8071857
Merged in master
alzimmermsft Oct 2, 2019
4019a46
Fix Javadoc links
alzimmermsft Oct 2, 2019
f50ccee
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 2, 2019
f8fade5
Fixing linting issues, prototyping BlobSasConstructor
alzimmermsft Oct 2, 2019
9b7362c
Minor refactoring in new class
alzimmermsft Oct 2, 2019
c0f968c
Merged in master
alzimmermsft Oct 3, 2019
861abef
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 3, 2019
3736fb0
Re-record failing tests
alzimmermsft Oct 3, 2019
db93d7b
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 3, 2019
d865559
Fix checkstyle issues
alzimmermsft Oct 3, 2019
e8e5e2e
Fix accidentally method name change
alzimmermsft Oct 3, 2019
1708e54
Fix javadoc issue
alzimmermsft Oct 3, 2019
17839e3
Merged in master
alzimmermsft Oct 3, 2019
63f2ad8
Cleanup checkstyle issues
alzimmermsft Oct 3, 2019
879172b
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 4, 2019
f6eb821
Merged in master, fixed unit test
alzimmermsft Oct 4, 2019
63050e0
Make SAS generation classes public API
alzimmermsft Oct 4, 2019
83e6185
Merge branch 'master' into AzStorage_RemoveClientSasMethods
alzimmermsft Oct 4, 2019
6b1755a
Fixing checkstyle issues
alzimmermsft Oct 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@
import com.azure.storage.blob.models.SignedIdentifier;
import com.azure.storage.blob.models.StorageAccountInfo;
import com.azure.storage.blob.models.StorageException;
import com.azure.storage.blob.models.UserDelegationKey;
import com.azure.storage.blob.specialized.BlobServiceSasQueryParameters;
import com.azure.storage.blob.specialized.BlobServiceSasSignatureValues;
import com.azure.storage.common.Constants;
import com.azure.storage.common.IpRange;
import com.azure.storage.common.SASProtocol;
import com.azure.storage.common.Utility;
import com.azure.storage.common.credentials.SharedKeyCredential;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -290,7 +282,7 @@ public Mono<Response<Void>> deleteWithResponse(BlobContainerAccessConditions acc
Mono<Response<Void>> deleteWithResponse(BlobContainerAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? new BlobContainerAccessConditions() : accessConditions;

if (!validateNoEtag(accessConditions.getModifiedAccessConditions())) {
if (!validateNoETag(accessConditions.getModifiedAccessConditions())) {
// Throwing is preferred to Single.error because this will error out immediately instead of waiting until
// subscription.
throw logger.logExceptionAsError(
Expand Down Expand Up @@ -379,7 +371,7 @@ public Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata
Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata,
BlobContainerAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? new BlobContainerAccessConditions() : accessConditions;
if (!validateNoEtag(accessConditions.getModifiedAccessConditions())
if (!validateNoETag(accessConditions.getModifiedAccessConditions())
|| accessConditions.getModifiedAccessConditions().getIfUnmodifiedSince() != null) {
// Throwing is preferred to Single.error because this will error out immediately instead of waiting until
// subscription.
Expand Down Expand Up @@ -486,7 +478,7 @@ Mono<Response<Void>> setAccessPolicyWithResponse(PublicAccessType accessType, Li
BlobContainerAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? new BlobContainerAccessConditions() : accessConditions;

if (!validateNoEtag(accessConditions.getModifiedAccessConditions())) {
if (!validateNoETag(accessConditions.getModifiedAccessConditions())) {
// Throwing is preferred to Single.error because this will error out immediately instead of waiting until
// subscription.
throw logger.logExceptionAsError(
Expand Down Expand Up @@ -785,194 +777,10 @@ Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse(Context context) {
}


private boolean validateNoEtag(ModifiedAccessConditions modifiedAccessConditions) {
private boolean validateNoETag(ModifiedAccessConditions modifiedAccessConditions) {
if (modifiedAccessConditions == null) {
return true;
}
return modifiedAccessConditions.getIfMatch() == null && modifiedAccessConditions.getIfNoneMatch() == null;
}

/**
* Generates a user delegation SAS with the specified parameters
*
* @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS
* @param accountName The {@code String} account name for the SAS
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @return A string that represents the SAS token
*/
public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName,
BlobContainerSasPermission permissions, OffsetDateTime expiryTime) {
return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null, null,
null, null, null, null, null, null, null);
}

/**
* Generates a user delegation SAS token with the specified parameters
*
* @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS
* @param accountName The {@code String} account name for the SAS
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @param startTime An optional {@code OffsetDateTime} start time for the SAS
* @param version An optional {@code String} version for the SAS
* @param sasProtocol An optional {@code SASProtocol} protocol for the SAS
* @param ipRange An optional {@code IpRange} ip address range for the SAS
* @return A string that represents the SAS token
*/
public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName,
BlobContainerSasPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version,
SASProtocol sasProtocol, IpRange ipRange) {
return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime,
version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /*
contentEncoding */, null /* contentLanguage */, null /* contentType */);
}

/**
* Generates a user delegation SAS token with the specified parameters
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlobContainerAsyncClient.generateUserDelegationSAS#UserDelegationKey-String-BlobContainerSasPermission-OffsetDateTime-OffsetDateTime-String-SASProtocol-IpRange-String-String-String-String-String}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas">Azure
* Docs</a></p>
*
* @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS
* @param accountName The {@code String} account name for the SAS
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @param startTime An optional {@code OffsetDateTime} start time for the SAS
* @param version An optional {@code String} version for the SAS
* @param sasProtocol An optional {@code SASProtocol} protocol for the SAS
* @param ipRange An optional {@code IpRange} ip address range for the SAS
* @param cacheControl An optional {@code String} cache-control header for the SAS.
* @param contentDisposition An optional {@code String} content-disposition header for the SAS.
* @param contentEncoding An optional {@code String} content-encoding header for the SAS.
* @param contentLanguage An optional {@code String} content-language header for the SAS.
* @param contentType An optional {@code String} content-type header for the SAS.
* @return A string that represents the SAS token
*/
public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName,
BlobContainerSasPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version,
SASProtocol sasProtocol, IpRange ipRange, String cacheControl, String contentDisposition,
String contentEncoding, String contentLanguage, String contentType) {
BlobServiceSasSignatureValues blobServiceSASSignatureValues = new BlobServiceSasSignatureValues(version,
sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange,
null /* identifier*/, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType);

BlobServiceSasSignatureValues values =
configureServiceSASSignatureValues(blobServiceSASSignatureValues, accountName);

BlobServiceSasQueryParameters blobServiceSasQueryParameters =
values.generateSASQueryParameters(userDelegationKey);

return blobServiceSasQueryParameters.encode();
}

/**
* Generates a SAS token with the specified parameters
*
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @return A string that represents the SAS token
*/
public String generateSAS(BlobContainerSasPermission permissions, OffsetDateTime expiryTime) {
return this.generateSAS(null, permissions, /* identifier */ expiryTime, null /* startTime */, null /* version
*/, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /* contentDisposition */,
null /* contentEncoding */, null /* contentLanguage */, null /*contentType*/);
}

/**
* Generates a SAS token with the specified parameters
*
* @param identifier The {@code String} name of the access policy on the container this SAS references if any
* @return A string that represents the SAS token
*/
public String generateSAS(String identifier) {
return this.generateSAS(identifier, null /* permissions*/, null /* expiryTime */, null /* startTime */, null
/* version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /*
contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /*contentType*/);
}

/**
* Generates a SAS token with the specified parameters
*
* @param identifier The {@code String} name of the access policy on the container this SAS references if any
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @param startTime An optional {@code OffsetDateTime} start time for the SAS
* @param version An optional {@code String} version for the SAS
* @param sasProtocol An optional {@code SASProtocol} protocol for the SAS
* @param ipRange An optional {@code IpRange} ip address range for the SAS
* @return A string that represents the SAS token
*/
public String generateSAS(String identifier, BlobContainerSasPermission permissions, OffsetDateTime expiryTime,
OffsetDateTime startTime, String version, SASProtocol sasProtocol, IpRange ipRange) {
return this.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null
/* cacheControl */, null /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */,
null /*contentType*/);
}

/**
* Generates a SAS token with the specified parameters
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlobContainerAsyncClient.generateSAS#String-BlobContainerSasPermission-OffsetDateTime-OffsetDateTime-String-SASProtocol-IpRange-String-String-String-String-String}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/create-service-sas">Azure Docs</a></p>
*
* @param identifier The {@code String} name of the access policy on the container this SAS references if any
* @param permissions The {@code BlobContainerSasPermissions} permission for the SAS
* @param expiryTime The {@code OffsetDateTime} expiry time for the SAS
* @param startTime An optional {@code OffsetDateTime} start time for the SAS
* @param version An optional {@code String} version for the SAS
* @param sasProtocol An optional {@code SASProtocol} protocol for the SAS
* @param ipRange An optional {@code IpRange} ip address range for the SAS
* @param cacheControl An optional {@code String} cache-control header for the SAS.
* @param contentDisposition An optional {@code String} content-disposition header for the SAS.
* @param contentEncoding An optional {@code String} content-encoding header for the SAS.
* @param contentLanguage An optional {@code String} content-language header for the SAS.
* @param contentType An optional {@code String} content-type header for the SAS.
* @return A string that represents the SAS token
*/
public String generateSAS(String identifier, BlobContainerSasPermission permissions, OffsetDateTime expiryTime,
OffsetDateTime startTime, String version, SASProtocol sasProtocol, IpRange ipRange, String cacheControl,
String contentDisposition, String contentEncoding, String contentLanguage, String contentType) {
BlobServiceSasSignatureValues blobServiceSASSignatureValues = new BlobServiceSasSignatureValues(version,
sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange,
identifier, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType);

SharedKeyCredential sharedKeyCredential =
Utility.getSharedKeyCredential(this.azureBlobStorage.getHttpPipeline());

Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential);

BlobServiceSasSignatureValues values = configureServiceSASSignatureValues(blobServiceSASSignatureValues,
sharedKeyCredential.getAccountName());

BlobServiceSasQueryParameters blobServiceSasQueryParameters =
values.generateSASQueryParameters(sharedKeyCredential);

return blobServiceSasQueryParameters.encode();
}

/**
* Sets blobServiceSASSignatureValues parameters dependent on the current blob type
*/
private BlobServiceSasSignatureValues configureServiceSASSignatureValues(
BlobServiceSasSignatureValues blobServiceSASSignatureValues, String accountName) {
// Set canonical name
blobServiceSASSignatureValues.setCanonicalName(this.azureBlobStorage.getUrl(), accountName);

// Set snapshotId to null
blobServiceSASSignatureValues.setSnapshotId(null);

// Set resource
blobServiceSASSignatureValues.setResource(Constants.UrlConstants.SAS_CONTAINER_CONSTANT);
return blobServiceSASSignatureValues;
}
}
Loading