0

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?

bachr
  • 5,780
  • 12
  • 57
  • 92

1 Answers1

0

Try DefaultAzureCredential Class and then call getToken to get the connection token. If no token is retrieved, user is not authenticated.

Take into account, that the user may be logged but does not have rights to perform the operation.

Daniel Argüelles
  • 2,229
  • 1
  • 33
  • 56