Skip to content
Advertisement

How can I generate a licensed download link in azure storage blob

I can get a link by those code, and it could download a file successfully.

BlobContainerSasPermission blobContainerSasPermission = new BlobContainerSasPermission()
                .setReadPermission(true)
                .setWritePermission(true)
                .setListPermission(true);
BlobServiceSasSignatureValues builder = new BlobServiceSasSignatureValues(OffsetDateTime.now().plusDays(1), blobContainerSasPermission)
                .setProtocol(SasProtocol.HTTPS_ONLY);
BlobClient client = new BlobClientBuilder()
                .connectionString("connection string")
                .blobName("")
                .buildClient();
String blobContainerName = "test";
return String.format("https://%s.blob.core.windows.net/%s?%s",client.getAccountName(), blobContainerName, client.generateSas(builder));

but everyone could download the file by this link, I want the file could be downloaded by the one who is authorized. Is there any code or azure’s setting(such as AD?) could implement this? Thanks

————————-update————————

I find a doc,and there gives a reason. Note: This method call is only valid when using TokenCredential in this object’s HttpPipeline. but there is only BasicAuthenticationCredential which implements TokenCredential in my imported package. This is my mvn.

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.11.0-beta.2</version>
</dependency>

And I tried this

String userName = "userName";
String password = "password";
BasicAuthenticationCredential basicAuthenticationCredential = new BasicAuthenticationCredential(userName,password);
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(basicAuthenticationCredential).buildClient();

then I got this Status code 401, (InvalidAuthenticationInfo)

Gods, help me!

Advertisement

Answer

It looks like there is no way to implement this.

This is the answer.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement