首页 > 解决方案 > How properly test credentials used by Azure SDK client are valid

问题描述

I'm trying to create a function that given Azure credentials check if they are valid.

In this case, I'm taking ADLS account name and account key credentails.

The Azure Java SDK does not provide an API for this, os I'm doing the following manually

def testConnection(account: String, accountKey: String): Boolean = {
  val storageConnectionString = s"DefaultEndpointsProtocol=https;AccountName=${accountName};AccountKey=${accountKey}"
  val storageAccount = CloudStorageAccount.parse(storageConnectionString)
  val client = storageAccount.createCloudBlobClient()
  Try{ client.downloadServiceProperties() }.isSuccess
}

the problem is downloadServiceProperties() is relatively slow, it may take a minute or so. Are they other faster options to check if the user ADLS credentials are valid ones?

标签: azureazure-blob-storageazure-java-sdk

解决方案


尝试DefaultAzureCredential 类,然后调用getToken以获取连接令牌。如果未检索到令牌,则用户未通过身份验证。

考虑到用户可能已登录但无权执行操作。


推荐阅读