Search in sources :

Example 1 with DirectoryObjectCollectionWithReferencesRequestBuilder

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;
}
Also used : Group(com.microsoft.graph.models.Group) ArrayList(java.util.ArrayList) DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) DirectoryObject(com.microsoft.graph.models.DirectoryObject) DirectoryObjectCollectionWithReferencesRequestBuilder(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesRequestBuilder)

Aggregations

DirectoryObject (com.microsoft.graph.models.DirectoryObject)1 Group (com.microsoft.graph.models.Group)1 DirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage)1 DirectoryObjectCollectionWithReferencesRequestBuilder (com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesRequestBuilder)1 ArrayList (java.util.ArrayList)1