如何将服务原则添加到 azure blob 容器以使用 java (azure sdk for java) 管理 ACL

问题描述 投票:0回答:1

使用 Azure SDK for Java,我在我的 Azure 存储帐户中创建了一个容器。要为新添加的容器控制 ACL,我现在必须添加服务原则。

有没有办法用Java来处理ACL并融入服务原则?

我试过 azure-document-to-manage-acl ,但需要更多帮助。

azure azure-blob-storage acl azure-service-principal azure-sdk-for-java
1个回答
0
投票

我尝试在我的环境中得到以下结果:

您可以按照此 github 链接 通过使用以下代码将服务主体添加到 Azure Blob 容器来实现您的要求。

代码:

@GetMapping("/call")
public  void  assignBlob()  throws  IOException  {
TokenCredential  credential  =  new  ClientSecretCredentialBuilder().clientId("client_id").clientSecret("client_secret").tenantId("tenant_id").build();

String  connectionString  =  "DefaultEndpointsProtocol=https;AccountName=<storage_account_name>;AccountKey=<storage_account_key>;EndpointSuffix=core.windows.net";

BlobContainerClient  containerClient  =  new  BlobContainerClientBuilder().credential(credential).connectionString(connectionString).containerName("<conatiner_name>").buildClient();

BlobSignedIdentifier  identifier  =  new  BlobSignedIdentifier().setId("<your_another_service_principal_id>").setAccessPolicy(new  BlobAccessPolicy().setStartsOn(OffsetDateTime.now()).setExpiresOn(OffsetDateTime.now().plusDays(7)).setPermissions("rw"));

// Set the access policy for the container
containerClient.setAccessPolicy(null,  Collections.singletonList(identifier));
}

我已经使用下面突出显示的服务主体 ID 来提供对我的容器的访问。

传送门: enter image description here

如下所示,我可以将服务主体添加到 Azure Blob 容器中。

传送门:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.