|
19 | 19 | import com.microsoft.graph.models.AssignedLicense; |
20 | 20 | import com.microsoft.graph.models.AssignedPlan; |
21 | 21 | import com.microsoft.graph.models.DirectoryObject; |
| 22 | +import com.microsoft.graph.models.DirectoryObjectCollectionResponse; |
22 | 23 | import com.microsoft.graph.models.Group; |
23 | 24 | import com.microsoft.graph.models.GroupCollectionResponse; |
24 | 25 | import com.microsoft.graph.models.ProvisionedPlan; |
@@ -609,8 +610,21 @@ public void delete(final ObjectClass objectClass, final Uid uid, final Operation |
609 | 610 |
|
610 | 611 | if (ObjectClass.ACCOUNT.equals(objectClass)) { |
611 | 612 | try { |
612 | | - for (Group group : client.getAuthenticated().getAllGroupsForUser(uid.getUidValue())) { |
613 | | - client.getAuthenticated().deleteUserFromGroup(uid.getUidValue(), group.getId()); |
| 613 | + DirectoryObjectCollectionResponse groups = |
| 614 | + client.getAuthenticated().getAllGroupsForUser(uid.getUidValue()); |
| 615 | + |
| 616 | + while (groups != null) { |
| 617 | + groups.getValue().stream().filter(Group.class::isInstance).map(Group.class::cast). |
| 618 | + forEach(group -> client.getAuthenticated(). |
| 619 | + deleteUserFromGroup(uid.getUidValue(), group.getId())); |
| 620 | + |
| 621 | + // Get the next page |
| 622 | + String odataNextLink = groups.getOdataNextLink(); |
| 623 | + if (odataNextLink == null || odataNextLink.isEmpty()) { |
| 624 | + break; |
| 625 | + } else { |
| 626 | + groups = client.getAuthenticated().getAllGroupsForUser(uid.getUidValue(), odataNextLink); |
| 627 | + } |
614 | 628 | } |
615 | 629 | } catch (Exception e) { |
616 | 630 | LOG.error("Could not delete User {0} from Groups", uid.getUidValue()); |
@@ -695,10 +709,21 @@ public Uid update( |
695 | 709 | // memberships |
696 | 710 | Set<String> ownGroups = new HashSet<>(); |
697 | 711 | try { |
698 | | - List<Group> ownGroupsResults = |
699 | | - client.getAuthenticated().getAllGroupsForUser(returnUid.getUidValue()); |
700 | | - for (Group group : ownGroupsResults) { |
701 | | - ownGroups.add(group.getId()); |
| 712 | + DirectoryObjectCollectionResponse groups = |
| 713 | + client.getAuthenticated().getAllGroupsForUser(uid.getUidValue()); |
| 714 | + |
| 715 | + while (groups != null) { |
| 716 | + groups.getValue().stream().filter(Group.class::isInstance).map(Group.class::cast). |
| 717 | + forEach(group -> client.getAuthenticated(). |
| 718 | + deleteUserFromGroup(uid.getUidValue(), group.getId())); |
| 719 | + |
| 720 | + // Get the next page |
| 721 | + String odataNextLink = groups.getOdataNextLink(); |
| 722 | + if (odataNextLink == null || odataNextLink.isEmpty()) { |
| 723 | + break; |
| 724 | + } else { |
| 725 | + groups = client.getAuthenticated().getAllGroupsForUser(uid.getUidValue(), odataNextLink); |
| 726 | + } |
702 | 727 | } |
703 | 728 | } catch (Exception ex) { |
704 | 729 | LOG.error(ex, "Could not list groups for User {0}", uid.getUidValue()); |
@@ -1027,10 +1052,20 @@ private ConnectorObject fromUser(final User user, final Set<String> attributesTo |
1027 | 1052 | } |
1028 | 1053 |
|
1029 | 1054 | if (attributesToGet.contains(PredefinedAttributes.GROUPS_NAME)) { |
| 1055 | + DirectoryObjectCollectionResponse groups = client.getAuthenticated().getAllGroupsForUser(user.getId()); |
| 1056 | + |
1030 | 1057 | List<String> groupNames = new ArrayList<>(); |
1031 | | - List<Group> groups = client.getAuthenticated().getAllGroupsForUser(user.getId()); |
1032 | | - for (Group group : groups) { |
1033 | | - groupNames.add(group.getMailNickname()); |
| 1058 | + while (groups != null) { |
| 1059 | + groups.getValue().stream().filter(Group.class::isInstance).map(Group.class::cast). |
| 1060 | + forEach(group -> groupNames.add(group.getMailNickname())); |
| 1061 | + |
| 1062 | + // Get the next page |
| 1063 | + String odataNextLink = groups.getOdataNextLink(); |
| 1064 | + if (odataNextLink == null || odataNextLink.isEmpty()) { |
| 1065 | + break; |
| 1066 | + } else { |
| 1067 | + groups = client.getAuthenticated().getAllGroupsForUser(user.getId(), odataNextLink); |
| 1068 | + } |
1034 | 1069 | } |
1035 | 1070 | builder.addAttribute(AttributeBuilder.build(PredefinedAttributes.GROUPS_NAME, groupNames)); |
1036 | 1071 | } |
|
0 commit comments