遇到使用 Azure Java SDK 时的 Authorization_RequestDenied 异常。

huangapple go评论61阅读模式
英文:

Getting Authorization_RequestDenied Exception with Azure Java SDK

问题

"我已经编写了一个小片段,使用Azure Java SDK获取所有服务主体。遇到了这个异常。我需要为这个SDK调用提供什么权限?

"code":"Authorization_RequestDenied","message":{"lang":"en","value":"权限不足,无法完成操作。"}

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
"<CLIENT_ID>", "<TENANT_ID>",
"<CLIENT_SECRET>", AzureEnvironment.AZURE);
Authenticated authenticated = Azure.configure().withLogLevel(LogLevel.NONE)
.authenticate(credentials);
PagedList<ServicePrincipal> servicePrincipals = authenticated.servicePrincipals().list();
servicePrincipals.stream().forEach(principal -> System.out.println(principal.id()));
"

英文:

I have written a small snippet to fetch all the service principals using Azure Java SDK. Getting this exception. What privileges do i need to give for this sdk call?

"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
		&quot;&lt;CLIENT_ID&gt;&quot;, &quot;&lt;TENANT_ID&gt;&quot;,
		&quot;&lt;CLIENT_SECRET&gt;&quot;, AzureEnvironment.AZURE);
Authenticated authenticated = Azure.configure().withLogLevel(LogLevel.NONE)
		.authenticate(credentials);
PagedList&lt;ServicePrincipal&gt; servicePrincipals = authenticated.servicePrincipals().list();
servicePrincipals.stream().forEach(principal -&gt; System.out.println(principal.id()));

答案1

得分: 0

我找到了问题所在。

每当您尝试使用 ID 获取服务主体时,它会在内部获取所有服务主体,并返回具有该 ID 的特定服务主体。

我尝试使用 getByName 进行获取,效果很好。

authenticated.servicePrincipals().getByName("<MYAPP_NAME/MYAPP_ID>");

英文:

I found what the problem is.

Whenever you try to fetch Service Principal using id it internally fetches all service principals and returns the specific service principal with that id.

I tried to fetch using getByName and it worked fine.

authenticated.servicePrincipals().getByName(&quot;&lt;MYAPP_NAME/MYAPP_ID&gt;&quot;);

huangapple
  • 本文由 发表于 2020年9月30日 14:27:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64132003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定