Skip to content

Commit 3631158

Browse files
authored
Merge pull request #286282 from pauljewellmsft/java-sas
[Dev guide] Combine SAS articles for containers and blobs - Java
2 parents 92dd56a + 02cc41d commit 3631158

6 files changed

+109
-172
lines changed

articles/storage/.openpublishing.redirection.storage.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,16 @@
500500
"redirect_url": "/azure/storage/blobs/storage-blob-user-delegation-sas-create-dotnet",
501501
"redirect_document_id": false
502502
},
503+
{
504+
"source_path_from_root": "/articles/storage/blobs/sas-service-create-java-container.md",
505+
"redirect_url": "/azure/storage/blobs/sas-service-create-java",
506+
"redirect_document_id": false
507+
},
508+
{
509+
"source_path_from_root": "/articles/storage/blobs/storage-blob-container-user-delegation-sas-create-java.md",
510+
"redirect_url": "/azure/storage/blobs/storage-blob-user-delegation-sas-create-java",
511+
"redirect_document_id": false
512+
},
503513
{
504514
"source_path_from_root": "/articles/storage/common/authorize-active-directory-cli.md",
505515
"redirect_url": "/azure/storage/common/authorize-data-operations-cli",

articles/storage/blobs/TOC.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,14 @@ items:
671671
href: /azure/developer/java/sdk/identity-service-principal-auth?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
672672
- name: Auth in Azure hosted applications
673673
href: /azure/developer/java/sdk/identity-azure-hosted-auth?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
674+
- name: Shared access signature (SAS)
675+
items:
676+
- name: Authorize using a user delegation SAS
677+
href: storage-blob-user-delegation-sas-create-java.md
678+
- name: Authorize using a service SAS
679+
href: sas-service-create-java.md
680+
- name: Authorize using an account SAS
681+
href: ../common/storage-account-sas-create-java.md?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
674682
- name: Container actions
675683
items:
676684
- name: Create a container
@@ -683,14 +691,6 @@ items:
683691
href: storage-blob-container-lease-java.md
684692
- name: Manage properties and metadata
685693
href: storage-blob-container-properties-metadata-java.md
686-
- name: Generate a shared access signature (SAS)
687-
items:
688-
- name: Create a user delegation SAS for a container
689-
href: storage-blob-container-user-delegation-sas-create-java.md
690-
- name: Create a service SAS for a container
691-
href: sas-service-create-java-container.md
692-
- name: Create an account SAS
693-
href: ../common/storage-account-sas-create-java.md?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
694694
- name: Blob actions
695695
items:
696696
- name: Upload blobs
@@ -717,14 +717,6 @@ items:
717717
href: storage-blob-properties-metadata-java.md
718718
- name: Set or change a blob's access tier
719719
href: storage-blob-use-access-tier-java.md
720-
- name: Generate a shared access signature (SAS)
721-
items:
722-
- name: Create a user delegation SAS for a blob
723-
href: storage-blob-user-delegation-sas-create-java.md
724-
- name: Create a service SAS for a blob
725-
href: sas-service-create-java.md
726-
- name: Create an account SAS
727-
href: ../common/storage-account-sas-create-java.md?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
728720
- name: Client library configuration options
729721
items:
730722
- name: Performance tuning for uploads and downloads

articles/storage/blobs/sas-service-create-java-container.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

articles/storage/blobs/sas-service-create-java.md

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
---
22
title: Create a service SAS for a blob with Java
33
titleSuffix: Azure Storage
4-
description: Learn how to create a service shared access signature (SAS) for a blob using the Azure Blob Storage client library for Java.
4+
description: Learn how to create a service shared access signature (SAS) for a container or blob using the Azure Blob Storage client library for Java.
55
author: pauljewellmsft
66

77
ms.service: azure-blob-storage
88
ms.topic: how-to
9-
ms.date: 08/05/2024
9+
ms.date: 09/06/2024
1010
ms.author: pauljewell
1111
ms.reviewer: nachakra
1212
ms.devlang: java
1313
ms.custom: devx-track-java, devguide-java, engagement-fy23, devx-track-java, devx-track-extended-java
1414
---
1515

16-
# Create a service SAS for a blob with Java
16+
# Create a service SAS for a container or blob with Java
1717

1818
[!INCLUDE [storage-dev-guide-selector-service-sas](../../../includes/storage-dev-guides/storage-dev-guide-selector-service-sas.md)]
1919

2020
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
2121

22-
This article shows how to use the storage account key to create a service SAS for a blob with the Blob Storage client library for Java.
22+
This article shows how to use the storage account key to create a service SAS for a container or blob with the Blob Storage client library for Java.
2323

2424
## About the service SAS
2525

2626
A service SAS is signed with the account access key. You can use the [StorageSharedKeyCredential](/java/api/com.azure.storage.common.storagesharedkeycredential) class to create the credential that is used to sign the service SAS.
2727

2828
You can also use a stored access policy to define the permissions and duration of the SAS. If the name of an existing stored access policy is provided, that policy is associated with the SAS. To learn more about stored access policies, see [Define a stored access policy](/rest/api/storageservices/define-stored-access-policy). If no stored access policy is provided, the code examples in this article show how to define permissions and duration for the SAS.
2929

30-
## Create a service SAS for a blob
30+
## Create a service SAS
31+
32+
You can create a service SAS for a container or blob, based on the needs of your app.
33+
34+
### [Container](#tab/container)
35+
36+
You can create a service SAS to delegate limited access to a container resource using the following method:
37+
38+
- [generateSas](/java/api/com.azure.storage.blob.specialized.blobclientbase#method-details)
39+
40+
SAS signature values, such as expiry time and signed permissions, are passed to the method as part of a [BlobServiceSasSignatureValues](/java/api/com.azure.storage.blob.sas.blobservicesassignaturevalues) instance. Permissions are specified as a [BlobContainerSasPermission](/java/api/com.azure.storage.blob.sas.blobcontainersaspermission) instance.
41+
42+
The following code example shows how to create a service SAS with read permissions for a container resource:
43+
44+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobSAS.java" id="Snippet_CreateServiceSASContainer":::
45+
46+
### [Blob](#tab/blob)
3147

3248
You can create a service SAS to delegate limited access to a blob resource using the following method:
3349

@@ -39,8 +55,35 @@ The following code example shows how to create a service SAS with read permissio
3955

4056
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobSAS.java" id="Snippet_CreateServiceSASBlob":::
4157

58+
---
59+
4260
## Use a service SAS to authorize a client object
4361

62+
You can use a service SAS to authorize a client object to perform operations on a container or blob based on the permissions granted by the SAS.
63+
64+
### [Container](#tab/container)
65+
66+
The following code examples show how to use the service SAS to authorize a [BlobContainerClient](/java/api/com.azure.storage.blob.blobcontainerclient) object. This client object can be used to perform operations on the container resource based on the permissions granted by the SAS.
67+
68+
First, create a [BlobServiceClient](/java/api/com.azure.storage.blob.blobserviceclient) object signed with the account access key:
69+
70+
```java
71+
String accountName = "<account-name>";
72+
String accountKey = "<account-key>";
73+
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
74+
75+
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
76+
.endpoint(String.format("https://%s.blob.core.windows.net/", accountName))
77+
.credential(credential)
78+
.buildClient();
79+
```
80+
81+
Then, generate the service SAS as shown in the earlier example and use the SAS to authorize a [BlobContainerClient](/java/api/com.azure.storage.blob.blobcontainerclient) object:
82+
83+
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobSAS.java" id="Snippet_UseServiceSASContainer":::
84+
85+
### [Blob](#tab/blob)
86+
4487
The following code example shows how to use the service SAS created in the earlier example to authorize a [BlobClient](/java/api/com.azure.storage.blob.blobclient) object. This client object can be used to perform operations on the blob resource based on the permissions granted by the SAS.
4588

4689
First, create a [BlobServiceClient](/java/api/com.azure.storage.blob.blobserviceclient) object signed with the account access key:
@@ -60,10 +103,16 @@ Then, generate the service SAS as shown in the earlier example and use the SAS t
60103

61104
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobSAS.java" id="Snippet_UseServiceSASBlob":::
62105

106+
---
107+
63108
## Resources
64109

65110
To learn more about using the Azure Blob Storage client library for Java, see the following resources.
66111

112+
### Code samples
113+
114+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobSAS.java)
115+
67116
[!INCLUDE [storage-dev-guide-resources-java](../../../includes/storage-dev-guides/storage-dev-guide-resources-java.md)]
68117

69118
### See also

articles/storage/blobs/storage-blob-container-user-delegation-sas-create-java.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)