Azure-sdk-for-java: [QUERY] Anonymous requests to storage blobs

Created on 27 Nov 2019  路  11Comments  路  Source: Azure/azure-sdk-for-java

Query/Question
How do I make anonymous requests to Azure Storage? When I don't provide any credentials to service client builder, it throws:

BlobServiceClient client = new BlobServiceClientBuilder()
    .endpoint("https://<account_name>.blob.core.windows.net")
    .buildClient();

Error:

java.lang.IllegalArgumentException: Authorization credentials must be set.
at com.azure.storage.blob.BlobServiceClientBuilder.lambda$buildAsyncClient$0(BlobServiceClientBuilder.java:98)
at com.azure.storage.blob.implementation.util.BuilderHelper.buildPipeline(BuilderHelper.java:61)
at com.azure.storage.blob.BlobServiceClientBuilder.buildAsyncClient(BlobServiceClientBuilder.java:90)
at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:82)

The below code works with version 8 of the SDK:

CloudBlobClient client = new CloudBlobClient(<endpoint>, StorageCredentialsAnonymous.ANONYMOUS);

Why is this not a Bug or a feature Request?
NA

Setup (please complete the following information if applicable):

  • OS: Linux
  • IDE : IntelliJ
  • Version of the Library used: 12.0.0

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [x] Query Added
  • [x] Setup information Added
Client Storage customer-reported question

All 11 comments

Hi @SukruthKS,

Only Blobs and Containers are able to allow public access to your so to make an anonymous request to Blob Storage you'll want to use the BlobClientBuilder/ContainerClientBuilder depending on your needs.

Feel free to close this issue if this helps unblock you.

Thanks @gapra-msft ! We always construct container and blob clients from BlobServiceClient and as soon as I build the service client (before making any requests), it fails with the above error. Any possibility of changing the behavior of construction of BlobServiceClient to not throw for anonymous access?

Hi, @SukruthKS. Sorry for not following up on this sooner. We have been discussing the possibility of adding this functionality, and then we will have the service client throw before issuing any requests if it sees there are no credentials with an error message that makes it clear anonymous service clients should only be used to conveniently create anonymous blob and container clients but do not support operations in and of themselves.

@rickle-msft that's exactly the behavior I was looking for. Please keep me posted on what you decide. Thanks!

Hi, I've resolved the issue with the 8 SDK version for JAVA. I've got the issue with 11 SDK. (https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-java-legacy)

_Try this one. Maven dependency:_

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.0</version>
</dependency>

_Code:_
CloudBlockBlob blob = new CloudBlockBlob(new URI("https://<account_name>.blob.core.windows.net/container/blob/SAS-token"))

blob.uploadFromFile('absolute path to file')

Note: URI should contain endpoint, container name, blob name, SAS token.

The following piece of code that uses BlobClientBuilder doesn't work too:

BlobClient blobClient = new BlobClientBuilder() .endpoint('https://acountname.blob.core.usgovcloudapi.net/videos/video.mp4?SasToken') .buildClient(); blobClient.uploadFromFile('path/video.mp4');

Error:
java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule

Setup:
OS: Mac OS 10.14.6
IDE : IDE IntelliJ 2019.3
Platform: Java8
Version of the Library used: 12.0.0

@shuk Can you share why you believe this error is coming from this particular usage of the builder? Typically when we see these sorts of errors coming from Jackson, its because of dependency conflicts. I'm not exactly sure what role you think the builder has to play in this.

@SeverinetsDenis Thank you for sharing that information. It will be helpful for someone that is fine using v8. We still need to address this in v12, however.

@rickle-msft, you are right, the mentioned error is connected to Jackson (ackson-databind-2.3.1-sources.jar) library that was used with SDK v12.0.

The exception stack trace:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.<init>(JavaTimeModule.java:144) at com.azure.core.implementation.serializer.jackson.JacksonAdapter.initializeObjectMapper(JacksonAdapter.java:258) at com.azure.core.implementation.serializer.jackson.JacksonAdapter.<init>(JacksonAdapter.java:74) at com.azure.core.implementation.serializer.jackson.JacksonAdapter.createDefaultSerializerAdapter(JacksonAdapter.java:108) at com.azure.core.implementation.RestProxy.createDefaultSerializer(RestProxy.java:629) at com.azure.core.implementation.RestProxy.create(RestProxy.java:691) at com.azure.storage.blob.implementation.ServicesImpl.<init>(ServicesImpl.java:58) at com.azure.storage.blob.implementation.AzureBlobStorageImpl.<init>(AzureBlobStorageImpl.java:213) at com.azure.storage.blob.implementation.AzureBlobStorageBuilder.build(AzureBlobStorageBuilder.java:90) at com.azure.storage.blob.specialized.BlobAsyncClientBase.<init>(BlobAsyncClientBase.java:113) at com.azure.storage.blob.BlobAsyncClient.<init>(BlobAsyncClient.java:102) at com.azure.storage.blob.BlobClientBuilder.buildAsyncClient(BlobClientBuilder.java:137) at com.azure.storage.blob.BlobClientBuilder.buildClient(BlobClientBuilder.java:96) at com.azure.storage.blob.BlobClientBuilder$buildClient$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)

After some experiments, I've found out that I used v12.0 instead of the last one and finally realized that my code works perfectly with v12.1 . As far as I understand the issue is already fixed by specifying Jackson dependencies explicitly (https://github.com/Azure/azure-sdk-for-java/commit/0ad7b6c2c32ef23fdd16ee9a19181ec2b9aa477d#diff-79be8518bf311112368782f9251d7480).

@rickle-msft what's the ETA for addressing this issue in v12?

@SukruthKS We should have a PR out for this by end of day and it should go out at latest with our February release.

Was this page helpful?
0 / 5 - 0 ratings