是否缺少Azure RBAC与Power外壳之间的任何权限?

人气:54 发布:2023-01-03 标签: azure java azure-rbac azure-powershell azure-java-sdk

问题描述

PowerShell命令‘az Role Assignment List--assignee User@Company.com--all’在PowerShell中提供结果,但对以下代码片段没有结果。

TokenCredential azureCliCredential = new AzureCliCredentialBuilder().build();
GraphServiceClient<Request> graphClient = GraphServiceClient.builder().authenticationProvider(new TokenCredentialAuthProvider(azureCliCredential)).buildClient();
AppRoleAssignmentCollectionPage appRoleAssignments = graphClient.users("objectid of user@company.com").appRoleAssignments().buildRequest().get();
System.out.println(appRoleAssignments);

推荐答案

它不起作用的原因是您正在尝试的两件事情在一起是为了不同的事情。

'az role assignment list --assignee user@company.com --all'将获取Azure RBAC角色分配,即分配给用户用于管理Azure订阅的角色。

但是,AppRoleAssignmentCollectionPage appRoleAssignments = graphClient.users("objectid of user@company.com").appRoleAssignments().buildRequest().get();获取为Azure AD中的应用程序分配给用户的角色。

若要使用代码获取Azure RBAC角色分配,您需要使用Azure SDK for Java

21