英文:
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(
"<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()));
答案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("<MYAPP_NAME/MYAPP_ID>");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论