Skip to content

Commit aa65728

Browse files
committed
Upgrading MS Graph API
1 parent 5dd6e83 commit aa65728

File tree

2 files changed

+54
-50
lines changed

2 files changed

+54
-50
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<properties>
7979
<connid.version>1.5.2.0</connid.version>
8080

81-
<microsoft.graph.version>5.51.0</microsoft.graph.version>
81+
<microsoft.graph.version>5.80.0</microsoft.graph.version>
8282
<azure.identity.version>1.14.1</azure.identity.version>
8383
<azure.msal4j.version>1.17.2</azure.msal4j.version>
8484

@@ -98,12 +98,12 @@
9898
<artifactId>azure-identity</artifactId>
9999
<version>${azure.identity.version}</version>
100100
</dependency>
101-
102101
<dependency>
103102
<groupId>com.microsoft.azure</groupId>
104103
<artifactId>msal4j</artifactId>
105104
<version>${azure.msal4j.version}</version>
106105
</dependency>
106+
107107
<dependency>
108108
<groupId>net.tirasa.connid</groupId>
109109
<artifactId>connector-framework</artifactId>

src/main/java/net/tirasa/connid/bundles/azure/service/AzureClient.java

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package net.tirasa.connid.bundles.azure.service;
1717

18+
import com.google.gson.JsonObject;
1819
import com.microsoft.graph.http.GraphServiceException;
1920
import com.microsoft.graph.models.DirectoryObject;
2021
import com.microsoft.graph.models.DirectoryObjectGetMemberGroupsParameterSet;
@@ -60,7 +61,7 @@ public AzureClient getAuthenticated() {
6061
*/
6162
public List<User> getAllUsers() {
6263
LOG.ok("Get all users");
63-
GraphServiceClient graphClient = getGraphServiceClient();
64+
GraphServiceClient<?> graphClient = getGraphServiceClient();
6465
UserCollectionPage userCollectionPage = graphClient.users().buildRequest().
6566
select(String.join(",", config.getUserAttributesToGet())).
6667
orderBy(AzureAttributes.USER_DISPLAY_NAME).get();
@@ -78,7 +79,7 @@ public List<User> getAllUsers() {
7879
*/
7980
public List<User> getAllUsers(final int pageSize) {
8081
LOG.ok("Get all users with page size {0}", pageSize);
81-
GraphServiceClient graphClient = getGraphServiceClient();
82+
GraphServiceClient<?> graphClient = getGraphServiceClient();
8283
UserCollectionPage userCollectionPage = graphClient.users().buildRequest().
8384
select(String.join(",", config.getUserAttributesToGet())).
8485
top(pageSize).orderBy(AzureAttributes.USER_DISPLAY_NAME).get();
@@ -97,7 +98,7 @@ public List<User> getAllUsers(final int pageSize) {
9798
*/
9899
public UserCollectionPage getAllUsersNextPage(final int pageSize, final String skipToken) {
99100
LOG.ok("Get all users next page with page size {0}", pageSize);
100-
GraphServiceClient graphClient = getGraphServiceClient();
101+
GraphServiceClient<?> graphClient = getGraphServiceClient();
101102
return graphClient.users().buildRequest().
102103
select(String.join(",", config.getUserAttributesToGet())).
103104
top(pageSize).skipToken(skipToken).orderBy(AzureAttributes.USER_DISPLAY_NAME).get();
@@ -110,7 +111,7 @@ public UserCollectionPage getAllUsersNextPage(final int pageSize, final String s
110111
*/
111112
public User getUser(final String userId) {
112113
LOG.ok("Getting user {0}", userId);
113-
GraphServiceClient graphClient = getGraphServiceClient();
114+
GraphServiceClient<?> graphClient = getGraphServiceClient();
114115
return graphClient.users(userId).buildRequest().
115116
select(String.join(",", config.getUserAttributesToGet())).get();
116117
}
@@ -121,7 +122,7 @@ public User getUser(final String userId) {
121122
* @return List of Users with specified filters values
122123
*/
123124
public List<User> getUsersFilteredBy(final AzureFilter filters) {
124-
GraphServiceClient graphClient = getGraphServiceClient();
125+
GraphServiceClient<?> graphClient = getGraphServiceClient();
125126

126127
//This request requires the ConsistencyLevel header set to eventual
127128
//because the request has both the $orderBy and $filter query parameters
@@ -149,7 +150,7 @@ public List<User> getUsersFilteredBy(final AzureFilter filters) {
149150
*/
150151
public List<User> getAllMembersOfGroup(final String groupId) {
151152
LOG.ok("Get all members of group {0}", groupId);
152-
GraphServiceClient graphClient = getGraphServiceClient();
153+
GraphServiceClient<?> graphClient = getGraphServiceClient();
153154
DirectoryObjectCollectionWithReferencesPage group = graphClient.groups(groupId).members().buildRequest().get();
154155

155156
List<User> users = new ArrayList<>();
@@ -168,7 +169,7 @@ public List<User> getAllMembersOfGroup(final String groupId) {
168169
*/
169170
public void addUserToGroup(final String userId, final String groupId) {
170171
LOG.ok("Adding user {0} to group {1}", userId, groupId);
171-
GraphServiceClient graphClient = getGraphServiceClient();
172+
GraphServiceClient<?> graphClient = getGraphServiceClient();
172173
try {
173174
graphClient.groups(groupId).members().references()
174175
.buildRequest()
@@ -185,7 +186,7 @@ public void addUserToGroup(final String userId, final String groupId) {
185186
*/
186187
public void deleteUserFromGroup(final String userId, final String groupId) {
187188
LOG.ok("Deleting user {0} from group {1}", userId, groupId);
188-
GraphServiceClient graphClient = getGraphServiceClient();
189+
GraphServiceClient<?> graphClient = getGraphServiceClient();
189190
DirectoryObject deletedObject = null;
190191
try {
191192
deletedObject = graphClient.groups(groupId).members(userId).reference()
@@ -206,7 +207,7 @@ public void deleteUserFromGroup(final String userId, final String groupId) {
206207
*/
207208
public List<Group> getAllGroups() {
208209
LOG.ok("Get all groups");
209-
GraphServiceClient graphClient = getGraphServiceClient();
210+
GraphServiceClient<?> graphClient = getGraphServiceClient();
210211
GroupCollectionPage groupCollectionPage = graphClient.groups()
211212
.buildRequest()
212213
.get();
@@ -224,7 +225,7 @@ public List<Group> getAllGroups() {
224225
*/
225226
public List<Group> getAllGroups(final int pageSize) {
226227
LOG.ok("Get all groups with page size {0}", pageSize);
227-
GraphServiceClient graphClient = getGraphServiceClient();
228+
GraphServiceClient<?> graphClient = getGraphServiceClient();
228229
GroupCollectionPage groupCollectionPage = graphClient.groups().buildRequest().
229230
top(pageSize).orderBy(AzureAttributes.GROUP_DISPLAY_NAME).get();
230231
List<Group> groups = new ArrayList<>();
@@ -242,7 +243,7 @@ public List<Group> getAllGroups(final int pageSize) {
242243
*/
243244
public GroupCollectionPage getAllGroupsNextPage(final int pageSize, final String skipToken) {
244245
LOG.ok("Get all groups next page with page size {0}", pageSize);
245-
GraphServiceClient graphClient = getGraphServiceClient();
246+
GraphServiceClient<?> graphClient = getGraphServiceClient();
246247
return graphClient.groups().buildRequest().
247248
top(pageSize).skipToken(skipToken).orderBy(AzureAttributes.GROUP_DISPLAY_NAME).get();
248249
}
@@ -254,7 +255,7 @@ public GroupCollectionPage getAllGroupsNextPage(final int pageSize, final String
254255
*/
255256
public List<Group> getAllGroupsForUser(final String userId) {
256257
LOG.ok("Get all groups user {0} is member", userId);
257-
GraphServiceClient graphClient = getGraphServiceClient();
258+
GraphServiceClient<?> graphClient = getGraphServiceClient();
258259
List<Group> groups = new ArrayList<>();
259260
try {
260261
graphClient.users(userId).memberOf().buildRequest().get().getCurrentPage().stream().
@@ -267,26 +268,26 @@ public List<Group> getAllGroupsForUser(final String userId) {
267268
return groups;
268269
}
269270

270-
/**
271-
*
272-
* @param groupId
273-
* @return List of Groups for specified Group
274-
*/
275-
public List<Group> getAllGroupsForGroup(final String groupId) {
276-
LOG.ok("Get all groups group {0} is member", groupId);
277-
GraphServiceClient graphClient = getGraphServiceClient();
278-
List<Group> groups = new ArrayList<>();
279-
try {
280-
graphClient.groups(groupId).memberOf().buildRequest().get().getCurrentPage().stream().
281-
filter(Group.class::isInstance).
282-
map(Group.class::cast).
283-
forEach(groups::add);
284-
} catch (Exception ex) {
285-
AzureUtils.handleGeneralError("While getting groups for Group " + groupId, ex);
286-
}
287-
288-
return groups;
289-
}
271+
/**
272+
*
273+
* @param groupId
274+
* @return List of Groups for specified Group
275+
*/
276+
public List<Group> getAllGroupsForGroup(final String groupId) {
277+
LOG.ok("Get all groups group {0} is member", groupId);
278+
GraphServiceClient<?> graphClient = getGraphServiceClient();
279+
List<Group> groups = new ArrayList<>();
280+
try {
281+
graphClient.groups(groupId).memberOf().buildRequest().get().getCurrentPage().stream().
282+
filter(Group.class::isInstance).
283+
map(Group.class::cast).
284+
forEach(groups::add);
285+
} catch (Exception ex) {
286+
AzureUtils.handleGeneralError("While getting groups for Group " + groupId, ex);
287+
}
288+
289+
return groups;
290+
}
290291

291292
/**
292293
*
@@ -295,7 +296,7 @@ public List<Group> getAllGroupsForGroup(final String groupId) {
295296
*/
296297
public Group getGroup(final String groupId) {
297298
LOG.ok("Getting group {0}", groupId);
298-
GraphServiceClient graphClient = getGraphServiceClient();
299+
GraphServiceClient<?> graphClient = getGraphServiceClient();
299300
return graphClient.groups(groupId).buildRequest().
300301
select(String.join(",", config.getGroupAttributesToGet())).get();
301302
}
@@ -306,7 +307,7 @@ public Group getGroup(final String groupId) {
306307
* @return List of Groups with specified filters values
307308
*/
308309
public List<Group> getGroupsFilteredBy(final AzureFilter filters) {
309-
GraphServiceClient graphClient = getGraphServiceClient();
310+
GraphServiceClient<?> graphClient = getGraphServiceClient();
310311

311312
//This request requires the ConsistencyLevel header set to eventual
312313
//because the request has both the $orderBy and $filter query parameters
@@ -334,7 +335,7 @@ public List<Group> getGroupsFilteredBy(final AzureFilter filters) {
334335
*/
335336
public DirectoryObject getDeletedDirectoryObject(final String id) {
336337
LOG.ok("Get deleted directory object {0} if exists", id);
337-
GraphServiceClient graphClient = getGraphServiceClient();
338+
GraphServiceClient<?> graphClient = getGraphServiceClient();
338339
return graphClient.directory().deletedItems(id).buildRequest().get();
339340
}
340341

@@ -344,7 +345,7 @@ public DirectoryObject getDeletedDirectoryObject(final String id) {
344345
* @return created User
345346
*/
346347
public User createUser(final User user) {
347-
GraphServiceClient graphClient = getGraphServiceClient();
348+
GraphServiceClient<?> graphClient = getGraphServiceClient();
348349
return graphClient.users().buildRequest().post(user);
349350
}
350351

@@ -354,7 +355,7 @@ public User createUser(final User user) {
354355
* @return created Group
355356
*/
356357
public Group createGroup(final Group group) {
357-
GraphServiceClient graphClient = getGraphServiceClient();
358+
GraphServiceClient<?> graphClient = getGraphServiceClient();
358359
return graphClient.groups().buildRequest().post(group);
359360
}
360361

@@ -364,7 +365,7 @@ public Group createGroup(final Group group) {
364365
* @return updated User
365366
*/
366367
public User updateUser(final User user) {
367-
GraphServiceClient graphClient = getGraphServiceClient();
368+
GraphServiceClient<?> graphClient = getGraphServiceClient();
368369
graphClient.users(user.id).buildRequest().patch(user);
369370
return getUser(user.id);
370371
}
@@ -375,7 +376,7 @@ public User updateUser(final User user) {
375376
* @return updated Group
376377
*/
377378
public Group updateGroup(final Group group) {
378-
GraphServiceClient graphClient = getGraphServiceClient();
379+
GraphServiceClient<?> graphClient = getGraphServiceClient();
379380
return graphClient.groups(group.id).buildRequest().patch(group);
380381
}
381382

@@ -384,7 +385,7 @@ public Group updateGroup(final Group group) {
384385
* @param userId
385386
*/
386387
public void deleteUser(final String userId) {
387-
GraphServiceClient graphClient = getGraphServiceClient();
388+
GraphServiceClient<?> graphClient = getGraphServiceClient();
388389
graphClient.users(userId).buildRequest().delete();
389390
}
390391

@@ -393,7 +394,7 @@ public void deleteUser(final String userId) {
393394
* @param groupId
394395
*/
395396
public void deleteGroup(final String groupId) {
396-
GraphServiceClient graphClient = getGraphServiceClient();
397+
GraphServiceClient<?> graphClient = getGraphServiceClient();
397398
graphClient.groups(groupId).buildRequest().delete();
398399
}
399400

@@ -403,8 +404,11 @@ public void deleteGroup(final String groupId) {
403404
* @return restored DirectoryObject
404405
*/
405406
public DirectoryObject restoreDirectoryObject(final String id) {
406-
GraphServiceClient graphClient = getGraphServiceClient();
407-
return graphClient.directory().deletedItems(id).restore().buildRequest().post();
407+
GraphServiceClient<?> graphClient = getGraphServiceClient();
408+
409+
graphClient.customRequest("/directory/deletedItems/" + id + "/restore").buildRequest().post(new JsonObject());
410+
411+
return graphClient.directoryObjects(id).buildRequest().get();
408412
}
409413

410414
/**
@@ -414,7 +418,7 @@ public DirectoryObject restoreDirectoryObject(final String id) {
414418
*/
415419
public List<SubscribedSku> getCurrentTenantSubscriptions() {
416420
LOG.ok("Get all subscriptions");
417-
GraphServiceClient graphClient = getGraphServiceClient();
421+
GraphServiceClient<?> graphClient = getGraphServiceClient();
418422

419423
SubscribedSkuCollectionPage subscribedSkuCollectionPage = graphClient.subscribedSkus().buildRequest().get();
420424
List<SubscribedSku> results = null;
@@ -459,7 +463,7 @@ public List<String> getCurrentTenantSkuIds(final boolean onlyEnabled) {
459463
*/
460464
public void assignLicense(final String userId, final UserAssignLicenseParameterSet assignedLicense) {
461465
LOG.ok("Assigning licenses to user {0}", userId);
462-
GraphServiceClient graphClient = getGraphServiceClient();
466+
GraphServiceClient<?> graphClient = getGraphServiceClient();
463467
graphClient.users(userId).assignLicense(assignedLicense).buildRequest().post();
464468
}
465469

@@ -471,7 +475,7 @@ public void assignLicense(final String userId, final UserAssignLicenseParameterS
471475
* @return whether a specified user, group, contact, or service principal is a member of a specified group
472476
*/
473477
public Boolean isMemberOf(final String memberId, final String groupId) {
474-
GraphServiceClient graphClient = getGraphServiceClient();
478+
GraphServiceClient<?> graphClient = getGraphServiceClient();
475479

476480
List<QueryOption> queryOptions = new ArrayList<>();
477481
queryOptions.add(new QueryOption("$filter", "id eq '" + memberId + "'"));
@@ -494,7 +498,7 @@ public Boolean isMemberOf(final String memberId, final String groupId) {
494498
* groups that it is a member of
495499
*/
496500
public List<String> getMemberGroups(final String resourceId, final boolean securityEnabledOnly) {
497-
GraphServiceClient graphClient = getGraphServiceClient();
501+
GraphServiceClient<?> graphClient = getGraphServiceClient();
498502
DirectoryObjectGetMemberGroupsParameterSet securityEnabled = new DirectoryObjectGetMemberGroupsParameterSet();
499503
securityEnabled.securityEnabledOnly = securityEnabledOnly;
500504

@@ -511,7 +515,7 @@ public List<String> getMemberGroups(final String resourceId, final boolean secur
511515
* groups and directory roles that it is a member of
512516
*/
513517
public List<String> getMemberObjects(final String resourceId, final boolean securityEnabledOnly) {
514-
GraphServiceClient graphClient = getGraphServiceClient();
518+
GraphServiceClient<?> graphClient = getGraphServiceClient();
515519
DirectoryObjectGetMemberObjectsParameterSet securityEnabled = new DirectoryObjectGetMemberObjectsParameterSet();
516520
securityEnabled.securityEnabledOnly = securityEnabledOnly;
517521

0 commit comments

Comments
 (0)