use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesRequestBuilder in project azure-ad-plugin by jenkinsci.
the class AzureCachePool method getBelongingGroupsByOid.
public List<AzureAdGroup> getBelongingGroupsByOid(final String oid) {
List<AzureAdGroup> result = belongingGroupsByOid.get(oid, (cacheKey) -> {
try {
DirectoryObjectCollectionWithReferencesPage collection = azure.users(oid).transitiveMemberOf().buildRequest().get();
List<AzureAdGroup> groups = new ArrayList<>();
while (collection != null) {
final List<DirectoryObject> directoryObjects = collection.getCurrentPage();
List<AzureAdGroup> groupsFromPage = directoryObjects.stream().map(group -> {
if (group instanceof Group) {
return new AzureAdGroup(group.id, ((Group) group).displayName);
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
groups.addAll(groupsFromPage);
DirectoryObjectCollectionWithReferencesRequestBuilder nextPage = collection.getNextPage();
if (nextPage == null) {
break;
} else {
collection = nextPage.buildRequest().get();
}
}
return groups;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Do not have sufficient privileges to " + "fetch your belonging groups' authorities.", e);
return Collections.emptyList();
}
});
if (Constants.DEBUG) {
belongingGroupsByOid.invalidate(oid);
}
return result;
}
Aggregations