我们需要在执行业务逻辑之前检查用户的授权权限。我找不到使用 Azure Java SDK 检索用户角色的示例或教程。
问问题
33 次
1 回答
0
我们有 Rest API,我们可以通过它检索分配给订阅的所有角色。使用 HTTP 请求,我们可以检索所有角色分配,然后我们可以搜索用户
代码:
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
以下是一些相关的 Microsoft 文档以获取完整信息。
于 2022-02-11T12:27:16.750 回答