给定一个特定目录角色成员的查询,我想返回一个相应用户的列表.我所拥有的是:
IDirectoryObjectCollectionWithReferencesRequest request = graphServiceClient.directoryRoles(roleId).members().buildRequest();
IDirectoryObjectCollectionWithReferencesPage page = request.select(USER_FIELDS_TO_RETURN).get();
List<DirectoryObject> objects = page.getCurrentPage();
IDirectoryObjectCollectionWithReferencesRequestBuilder builder = page.getNextPage();
while (builder != null) {
request = builder.buildRequest();
page = request.select(USER_FIELDS_TO_RETURN).get();
objects.addAll(page.getCurrentPage());
builder = page.getNextPage();
}
return objects.stream().filter(o -> o.oDataType.equals("#microsoft.graph.user")).map(o -> new User()).collect(Collectors.toList());
问题在于return语句.仅对用户对象进行过滤(与比较oDataType相比,找不到比这更优雅的方法),并返回带有o内容的用户对象:
objects.stream().filter(o -> o.oDataType.equals("#microsoft.graph.user")).map(o -> {
// the only thing that I could think of is to do some weird
// serialization/deserialization logic here which is a bad solution
// for anything other than a small number of elements
}).collect(Collectors.toList());
将DirectoryObject转换为User的正确方法是什么
最佳答案
Microsoft Graph当前不支持此要求.
如果要检查特定的directoryRole,则可以从另一个方向进行检查. / members端点确实支持按成员ID进行过滤:
v1.0/directoryRoles/{role-id}/members?$filter=id eq '{user-id}'
请检查此线程中提供的答案和解决方法. How to get admin roles that I am a member of,from Microsoft Graph using .Net Client SDK?