azure - 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?
解决方案
尝试DefaultAzureCredential 类,然后调用getToken
以获取连接令牌。如果未检索到令牌,则用户未通过身份验证。
考虑到用户可能已登录但无权执行操作。
推荐阅读
- pdf - 带有 .yml 主题的 Asciidoctor 样式有序列表
- c# - 如何检查 Blazor (C#) 中是否存在公司?
- gnuplot - 在 Gnuplot 中引入一个带有特殊符号的框
- javascript - 如何在搜索过滤器上添加去抖动(延迟)时间?Javascript
- amazon-web-services - SNS 中的订阅存在,需要使用 cloudformation 使用 1 个订阅
- mongodb - MongoDB 如果存在则更新,如果不存在则插入:从集合 A 到集合 B 的数组
- forms - FormSubmit - 每个表单的单独电子邮件
- android - Android 对讲未宣布自定义操作标签
- amazon-web-services - AWS - LAMBDA - CLI - 更新功能代码 - 在该区域无法访问
- wpf - 无法加载文件或程序集“system.diagnostics.diagnosticsource”