We have a requirement to check the Authorization permissions of an User before executing business logic. I am not able to find an example or tutorial to retrieve the Roles of an User, using Azure Java SDK.
Asked
Active
Viewed 225 times
1 Answers
0
We have Rest API by which we can retrieve all roles assigned to a subscription. Using HTTP request we can retrieve all the role assignments and then we can search for user
Code:
String api = "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleAssignments?api-version=2015-07-01" ;
// Here substitute the SubstriptionID
System._out_.println( "Hello World!" );
HttpClient client = HttpClient._newHttpClient_();
HttpRequest request = HttpRequest._newBuilder_()
.GET()
.uri(URI._create_(api))
.build();
HttpResponse<String> response = client.send(request , HttpResponse.BodyHandlers._ofString_());
System._out_.print(response.body());
// The following the has to parsed to find whether the user is present or not
Here are the few related Microsoft Documents for complete information.
Role Assignments - List - REST API (Azure Authorization) | Microsoft Docs

SaiSakethGuduru
- 2,218
- 1
- 5
- 15
-
Powershell command 'az role assignment list --assignee user@company.com --all' is giving result in powershell but no results for below code snippet. TokenCredential azureCliCredential = new AzureCliCredentialBuilder().build(); GraphServiceClient
graphClient = GraphServiceClient.builder().authenticationProvider(new TokenCredentialAuthProvider(azureCliCredential)).buildClient(); AppRoleAssignmentCollectionPage appRoleAssignments = graphClient.users("objectid of user@company.com").appRoleAssignments().buildRequest().filter().get(); System.out.println(appRoleAssignments.getCount()); – dev4java Feb 28 '22 at 08:18 -
Opened another question to reach more people, https://stackoverflow.com/questions/71376890/any-permissions-are-missing-azure-rbac-vs-power-shell – dev4java Mar 07 '22 at 05:50