Search in sources :

Example 1 with DirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage in project msgraph-sdk-java by microsoftgraph.

the class UserTests method meMemberof.

@Test
public void meMemberof() {
    final DirectoryObjectCollectionWithReferencesPage page = graphServiceClient.me().memberOf().buildRequest().get();
    assertNotNull(page);
}
Also used : DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) Test(org.junit.jupiter.api.Test)

Example 2 with DirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage in project msgraph-beta-sdk-java by microsoftgraph.

the class UserTests method meMemberof.

@Test
public void meMemberof() {
    final DirectoryObjectCollectionWithReferencesPage page = graphServiceClient.me().memberOf().buildRequest().get();
    assertNotNull(page);
}
Also used : DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) Test(org.junit.jupiter.api.Test)

Example 3 with DirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage in project msgraph-beta-sdk-java by microsoftgraph.

the class UserTests method castTest.

@Test
public void castTest() {
    final GroupCollectionPage groups = graphServiceClient.groups().buildRequest().top(1).get();
    final Group group = groups.getCurrentPage().get(0);
    final UserCollectionPage usersPage = graphServiceClient.groups(group.id).membersAsUser().buildRequest().get();
    assertNotNull(usersPage);
    final DirectoryObjectCollectionWithReferencesPage testUserCollection = graphServiceClient.groups(group.id).members().buildRequest().top(1).get();
    final DirectoryObject testUser = testUserCollection.getCurrentPage().get(0);
    final User user = graphServiceClient.groups(group.id).membersAsUser(testUser.id).buildRequest().get();
    assertNotNull(user);
}
Also used : Group(com.microsoft.graph.models.Group) User(com.microsoft.graph.models.User) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) GroupCollectionPage(com.microsoft.graph.requests.GroupCollectionPage) DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) DirectoryObject(com.microsoft.graph.models.DirectoryObject) Test(org.junit.jupiter.api.Test)

Example 4 with DirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage 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)

Example 5 with DirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage in project msgraph-sdk-java by microsoftgraph.

the class UserTests method castTest.

@Test
public void castTest() {
    final GroupCollectionPage groups = graphServiceClient.groups().buildRequest().top(1).get();
    final Group group = groups.getCurrentPage().get(0);
    final UserCollectionPage usersPage = graphServiceClient.groups(group.id).membersAsUser().buildRequest().get();
    assertNotNull(usersPage);
    final DirectoryObjectCollectionWithReferencesPage testUserCollection = graphServiceClient.groups(group.id).members().buildRequest().top(1).get();
    final DirectoryObject testUser = testUserCollection.getCurrentPage().get(0);
    final User user = graphServiceClient.groups(group.id).membersAsUser(testUser.id).buildRequest().get();
    assertNotNull(user);
}
Also used : Group(com.microsoft.graph.models.Group) User(com.microsoft.graph.models.User) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) GroupCollectionPage(com.microsoft.graph.requests.GroupCollectionPage) DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) DirectoryObject(com.microsoft.graph.models.DirectoryObject) Test(org.junit.jupiter.api.Test)

Aggregations

DirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage)7 Test (org.junit.jupiter.api.Test)6 DirectoryObject (com.microsoft.graph.models.DirectoryObject)3 Group (com.microsoft.graph.models.Group)3 User (com.microsoft.graph.models.User)2 GroupCollectionPage (com.microsoft.graph.requests.GroupCollectionPage)2 UserCollectionPage (com.microsoft.graph.requests.UserCollectionPage)2 DirectoryObjectCollectionWithReferencesRequestBuilder (com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesRequestBuilder)1 ArrayList (java.util.ArrayList)1