diff --git a/pom.xml b/pom.xml index cbd5dda..16b6a47 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ net.tirasa.connid.bundles net.tirasa.connid.bundles.azure - 2.0.3-SNAPSHOT + 3.0.0-SNAPSHOT ConnId Bundles: Azure @@ -78,7 +78,7 @@ 1.5.2.0 - 5.51.0 + 6.19.0 1.14.1 1.17.2 @@ -98,12 +98,12 @@ azure-identity ${azure.identity.version} - com.microsoft.azure msal4j ${azure.msal4j.version} + net.tirasa.connid connector-framework diff --git a/src/main/java/net/tirasa/connid/bundles/azure/AzureConnector.java b/src/main/java/net/tirasa/connid/bundles/azure/AzureConnector.java index fd2e5e6..38d5bb8 100644 --- a/src/main/java/net/tirasa/connid/bundles/azure/AzureConnector.java +++ b/src/main/java/net/tirasa/connid/bundles/azure/AzureConnector.java @@ -16,25 +16,21 @@ package net.tirasa.connid.bundles.azure; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.microsoft.graph.http.BaseCollectionRequestBuilder; import com.microsoft.graph.models.AssignedLicense; import com.microsoft.graph.models.AssignedPlan; import com.microsoft.graph.models.DirectoryObject; import com.microsoft.graph.models.Group; -import com.microsoft.graph.models.PasswordProfile; +import com.microsoft.graph.models.GroupCollectionResponse; import com.microsoft.graph.models.ProvisionedPlan; import com.microsoft.graph.models.SubscribedSku; import com.microsoft.graph.models.User; -import com.microsoft.graph.models.UserAssignLicenseParameterSet; -import com.microsoft.graph.requests.GroupCollectionPage; -import com.microsoft.graph.requests.GroupCollectionRequestBuilder; -import com.microsoft.graph.requests.UserCollectionPage; -import com.microsoft.graph.requests.UserCollectionRequestBuilder; +import com.microsoft.graph.models.UserCollectionResponse; +import com.microsoft.graph.users.item.assignlicense.AssignLicensePostRequestBody; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.UUID; @@ -81,10 +77,174 @@ public class AzureConnector implements Connector, CreateOp, DeleteOp, SchemaOp, SearchOp, TestOp, UpdateOp { - public static final String SKIP_TOKEN_ID = "$skiptoken="; - private static final Log LOG = Log.getLog(AzureConnector.class); + @SuppressWarnings("unchecked") + private static void doUserSetAttribute(final String name, final List values, final User user) { + Object value = values.isEmpty() ? null : values.get(0); + switch (name) { + case "displayName": + user.setDisplayName((String) value); + break; + case "id": + user.setId((String) value); + break; + case "city": + user.setCity((String) value); + break; + case "country": + user.setCountry((String) value); + break; + case "department": + user.setDepartment((String) value); + break; + case "businessPhones": + user.setBusinessPhones(new ArrayList<>((List) (List) values)); + break; + case "givenName": + user.setGivenName((String) value); + break; + case "onPremisesImmutableId": + user.setOnPremisesImmutableId((String) value); + break; + case "jobTitle": + user.setJobTitle((String) value); + break; + case "mail": + user.setMail((String) value); + break; + case "mobilePhone": + user.setMobilePhone((String) value); + break; + case "passwordPolicies": + user.setPasswordPolicies((String) value); + break; + case "preferredLanguage": + user.setPreferredLanguage((String) value); + break; + case "officeLocation": + user.setOfficeLocation((String) value); + break; + case "postalCode": + user.setPostalCode((String) value); + break; + case "state": + user.setState((String) value); + break; + case "streetAddress": + user.setStreetAddress((String) value); + break; + case "surname": + user.setSurname((String) value); + break; + case "usageLocation": + user.setUsageLocation((String) value); + break; + case "userPrincipalName": + user.setUserPrincipalName((String) value); + break; + case "companyName": + user.setCompanyName((String) value); + break; + case "creationType": + user.setCreationType((String) value); + break; + case "employeeId": + user.setEmployeeId((String) value); + break; + case "onPremisesDistinguishedName": + user.setOnPremisesDistinguishedName((String) value); + break; + case "onPremisesSecurityIdentifier": + user.setOnPremisesSecurityIdentifier((String) value); + break; + case "showInAddressList": + user.setShowInAddressList((Boolean) value); + break; + case "proxyAddresses": + user.setProxyAddresses(new ArrayList<>((List) (List) values)); + break; + case "userType": + user.setUserType((String) value); + break; + case "otherMails": + user.setOtherMails(new ArrayList<>((List) (List) values)); + break; + case "provisionedPlans": + user.setProvisionedPlans(new ArrayList<>((List) (List) values)); + break; + case "assignedLicenses": + user.setAssignedLicenses(new ArrayList<>((List) (List) values)); + break; + case "assignedPlans": + user.setAssignedPlans(new ArrayList<>((List) (List) values)); + break; + default: + } + } + + @SuppressWarnings("unchecked") + private static void doGroupSetAttribute(final String name, final List values, final Group group) { + Object value = values.isEmpty() ? null : values.get(0); + switch (name) { + case "id": + group.setId((String) value); + break; + case "mail": + group.setMail((String) value); + break; + case "mailEnabled": + group.setMailEnabled((Boolean) value); + break; + case "onPremisesSecurityIdentifier": + group.setOnPremisesSecurityIdentifier((String) value); + break; + case "proxyAddresses": + group.setProxyAddresses(new ArrayList<>((List) (List) values)); + break; + case "description": + group.setDescription((String) value); + break; + case "securityEnabled": + group.setSecurityEnabled((Boolean) value); + break; + case "classification": + group.setClassification((String) value); + break; + case "groupTypes": + group.setGroupTypes(new ArrayList<>((List) (List) values)); + break; + case "preferredLanguage": + group.setPreferredLanguage((String) value); + break; + case "securityIdentifier": + group.setSecurityIdentifier((String) value); + break; + case "theme": + group.setTheme((String) value); + break; + case "visibility": + group.setVisibility((String) value); + break; + case AzureAttributes.GROUP_MAIL_NICKNAME: + group.setMailNickname((String) value); + break; + case AzureAttributes.GROUP_DISPLAY_NAME: + group.setDisplayName((String) value); + break; + case "allowExternalSenders": + group.setAllowExternalSenders((Boolean) value); + break; + case "autoSubscribeNewMembers": + group.setAutoSubscribeNewMembers((Boolean) value); + break; + case "preferredDataLocation": + group.setPreferredDataLocation((String) value); + break; + default: + } + } + private AzureConnectorConfiguration configuration; private Schema schema; @@ -192,18 +352,14 @@ public void executeQuery( try { if (pagesSize != -1) { + UserCollectionResponse response; if (StringUtil.isNotBlank(cookie)) { - UserCollectionPage request = - client.getAuthenticated().getAllUsersNextPage(pagesSize, cookie); - users = request.getCurrentPage(); - cookie = request.getNextPage() != null ? getSkipToken(request.getNextPage()) : null; + response = client.getAuthenticated().getAllUsersNextPage(cookie); } else { - users = client.getAuthenticated().getAllUsers(pagesSize); - - UserCollectionRequestBuilder nextPageRequest = - client.getAuthenticated().getAllUsersNextPage(pagesSize, "").getNextPage(); - cookie = nextPageRequest != null ? getSkipToken(nextPageRequest) : null; + response = client.getAuthenticated().getAllUsers(pagesSize); } + users = response.getValue(); + cookie = response.getOdataNextLink(); } else { users = client.getAuthenticated().getAllUsers(); } @@ -256,18 +412,14 @@ public void executeQuery( try { if (pagesSize != -1) { + GroupCollectionResponse response; if (StringUtil.isNotBlank(cookie)) { - GroupCollectionPage request = - client.getAuthenticated().getAllGroupsNextPage(pagesSize, cookie); - groups = request.getCurrentPage(); - cookie = request != null ? getSkipToken(request.getNextPage()) : null; + response = client.getAuthenticated().getAllGroupsNextPage(cookie); } else { - groups = client.getAuthenticated().getAllGroups(pagesSize); - - GroupCollectionRequestBuilder nextPageRequest = - client.getAuthenticated().getAllGroupsNextPage(pagesSize, "").getNextPage(); - cookie = nextPageRequest != null ? getSkipToken(nextPageRequest) : null; + response = client.getAuthenticated().getAllGroups(pagesSize); } + groups = response.getValue(); + cookie = response.getOdataNextLink(); } else { groups = client.getAuthenticated().getAllGroups(); } @@ -352,34 +504,31 @@ public Uid create( String id = accessor.findString(AzureAttributes.USER_ID); if (configuration.getRestoreItems() && id != null && client.getDeletedDirectoryObject(id) != null) { DirectoryObject directoryObject = client.restoreDirectoryObject(id); - return new Uid(directoryObject.id); - } else if (ObjectClass.ACCOUNT.equals(objectClass)) { + return new Uid(directoryObject.getId()); + } + + if (ObjectClass.ACCOUNT.equals(objectClass)) { User user = new User(); User createdUser = new User(); String username = accessor.findString(AzureAttributes.USER_MAIL_NICKNAME); if (username == null) { username = accessor.findString(Name.NAME); } - GuardedString password = accessor.getPassword(); - String displayName = accessor.findString(AzureAttributes.USER_DISPLAY_NAME); - boolean status = accessor.getEnabled(true); + List licenses = accessor.findList(AzureAttributes.AZURE_LICENSE_NAME); - try { - // handle mandatory attributes (some attributes are handled by Service class) - user.displayName = displayName; - user.mailNickname = username; + // handle mandatory attributes (some attributes are handled by Service class) + user.setDisplayName(accessor.findString(AzureAttributes.USER_DISPLAY_NAME)); + user.setMailNickname(username); - PasswordProfile passwordProfile = new PasswordProfile(); - passwordProfile.password = String.valueOf(password); - user.passwordProfile = passwordProfile; + accessor.getPassword().access(pwd -> user.setPasswordProfile(AzureUtils.createPassword(new String(pwd)))); - user.accountEnabled = status; - - createAttributes.stream(). - filter(attribute -> attribute.getValue() != null). - forEach(attribute -> doUserSetAttribute(attribute.getName(), attribute.getValue(), user)); + user.setAccountEnabled(accessor.getEnabled(true)); + createAttributes.stream(). + filter(attribute -> attribute.getValue() != null). + forEach(attribute -> doUserSetAttribute(attribute.getName(), attribute.getValue(), user)); + try { createdUser = client.getAuthenticated().createUser(user); } catch (Exception e) { AzureUtils.wrapGeneralError("Could not create User : " + username, e); @@ -390,9 +539,9 @@ public Uid create( if (!CollectionUtil.isEmpty(groups)) { for (Object group : groups) { try { - client.getAuthenticated().addUserToGroup(createdUser.id, group.toString()); + client.getAuthenticated().addUserToGroup(createdUser.getId(), group.toString()); } catch (Exception e) { - LOG.error("Could not add User {0} to Group {1} ", createdUser.id, group, e); + LOG.error("Could not add User {0} to Group {1} ", createdUser.getId(), group, e); } } } @@ -401,26 +550,23 @@ public Uid create( if (!CollectionUtil.isEmpty(licenses)) { for (Object license : licenses) { // executing an assignment per single license in order to skip errors from invalid licenses + AssignedLicense assignedLicense = new AssignedLicense(); + assignedLicense.setSkuId(UUID.fromString(license.toString())); + AssignLicensePostRequestBody body = new AssignLicensePostRequestBody(); + body.setAddLicenses(Collections.singletonList(assignedLicense)); + try { - UserAssignLicenseParameterSet userAssignLicenseParameterSet = - new UserAssignLicenseParameterSet(); - AssignedLicense assignedLicense = new AssignedLicense(); - assignedLicense.skuId = (UUID.fromString(license.toString())); - LinkedList assignedLicenses = new LinkedList<>(); - assignedLicenses.add(assignedLicense); - List removedLicenses = new ArrayList<>(); - userAssignLicenseParameterSet.addLicenses = assignedLicenses; - userAssignLicenseParameterSet.removeLicenses = removedLicenses; - client.getAuthenticated().assignLicense(createdUser.id, userAssignLicenseParameterSet); + client.getAuthenticated().assignLicense(createdUser.getId(), body); } catch (RuntimeException ex) { LOG.error("While assigning license {0} to user {1}", license, createdUser, ex); } } } - return new Uid(createdUser.id); + return new Uid(createdUser.getId()); + } - } else if (ObjectClass.GROUP.equals(objectClass)) { + if (ObjectClass.GROUP.equals(objectClass)) { String groupName = accessor.findString(AzureAttributes.GROUP_MAIL_NICKNAME); if (groupName == null) { groupName = accessor.findString(Name.NAME); @@ -428,26 +574,23 @@ public Uid create( String displayName = accessor.findString(AzureAttributes.GROUP_DISPLAY_NAME); Group group = new Group(); - Group createdGroup = new Group(); - try { - // handle mandatory attributes (some attributes are handled by Service class) - group.displayName = displayName; - group.mailNickname = groupName; + // handle mandatory attributes (some attributes are handled by Service class) + group.setDisplayName(displayName); + group.setMailNickname(groupName); - createAttributes.stream().filter(attribute -> attribute.getValue() != null). - forEach(attribute -> doGroupSetAttribute(attribute.getName(), attribute.getValue(), group)); - createdGroup = client.getAuthenticated().createGroup(group); + createAttributes.stream().filter(attribute -> attribute.getValue() != null). + forEach(attribute -> doGroupSetAttribute(attribute.getName(), attribute.getValue(), group)); + + try { + return new Uid(client.getAuthenticated().createGroup(group).getId()); } catch (Exception e) { AzureUtils.wrapGeneralError("Could not create Group : " + groupName, e); } - - return new Uid(createdGroup.id); - - } else { - LOG.warn("Create of type " + objectClass.getObjectClassValue() + " is not supported"); - throw new UnsupportedOperationException("Create of type" - + objectClass.getObjectClassValue() + " is not supported"); } + + LOG.warn("Create of type " + objectClass.getObjectClassValue() + " is not supported"); + throw new UnsupportedOperationException("Create of type" + + objectClass.getObjectClassValue() + " is not supported"); } @Override @@ -467,7 +610,7 @@ public void delete(final ObjectClass objectClass, final Uid uid, final Operation if (ObjectClass.ACCOUNT.equals(objectClass)) { try { for (Group group : client.getAuthenticated().getAllGroupsForUser(uid.getUidValue())) { - client.getAuthenticated().deleteUserFromGroup(uid.getUidValue(), group.id); + client.getAuthenticated().deleteUserFromGroup(uid.getUidValue(), group.getId()); } } catch (Exception e) { LOG.error("Could not delete User {0} from Groups", uid.getUidValue()); @@ -521,7 +664,7 @@ public Uid update( } User user = new User(); - user.id = uid.getUidValue(); + user.setId(uid.getUidValue()); if (status == null || status.getValue() == null @@ -529,7 +672,7 @@ public Uid update( LOG.warn("{0} attribute value not correct, can't handle User status update", OperationalAttributes.ENABLE_NAME); } else { - user.accountEnabled = Boolean.valueOf(status.getValue().get(0).toString()); + user.setAccountEnabled(Boolean.valueOf(status.getValue().get(0).toString())); } try { @@ -537,26 +680,16 @@ public Uid update( forEach(attribute -> doUserSetAttribute(attribute.getName(), attribute.getValue(), user)); // password - GuardedString password = accessor.getPassword(); - if (password != null) { - try { - if (user.passwordProfile != null) { - PasswordProfile passwordProfile = new PasswordProfile(); - passwordProfile.password = String.valueOf(password); - user.passwordProfile = passwordProfile; - } - } catch (Exception e) { - AzureUtils.wrapGeneralError( - "Could not update password for User " + uid.getUidValue(), e); - } + if (accessor.getPassword() != null) { + accessor.getPassword(). + access(pwd -> user.setPasswordProfile(AzureUtils.createPassword(new String(pwd)))); } client.getAuthenticated().updateUser(user); - returnUid = new Uid(user.id); + returnUid = new Uid(user.getId()); } catch (Exception e) { - AzureUtils.wrapGeneralError( - "Could not update User " + uid.getUidValue() + " from attributes ", e); + AzureUtils.wrapGeneralError("Could not update User " + uid.getUidValue() + " from attributes ", e); } // memberships @@ -565,7 +698,7 @@ public Uid update( List ownGroupsResults = client.getAuthenticated().getAllGroupsForUser(returnUid.getUidValue()); for (Group group : ownGroupsResults) { - ownGroups.add(group.id); + ownGroups.add(group.getId()); } } catch (Exception ex) { LOG.error(ex, "Could not list groups for User {0}", uid.getUidValue()); @@ -600,24 +733,22 @@ public Uid update( returnUid.getUidValue()); } else { List assignedSkuIds = new ArrayList<>(); - if (updatedUser.assignedLicenses != null) { - for (AssignedLicense assignedLicense : updatedUser.assignedLicenses) { - assignedSkuIds.add(assignedLicense.skuId); + if (updatedUser.getAssignedLicenses() != null) { + for (AssignedLicense assignedLicense : updatedUser.getAssignedLicenses()) { + assignedSkuIds.add(assignedLicense.getSkuId()); } } if (CollectionUtil.isEmpty(licenses)) { if (!assignedSkuIds.isEmpty()) { - assignedSkuIds.forEach(uuid -> { - UserAssignLicenseParameterSet userAssignLicenseParameterSet = - new UserAssignLicenseParameterSet(); - LinkedList assignedLicenses = new LinkedList<>(); - List removedLicenses = new ArrayList<>(); - removedLicenses.add(uuid); - userAssignLicenseParameterSet.addLicenses = assignedLicenses; - userAssignLicenseParameterSet.removeLicenses = removedLicenses; - client.getAuthenticated().assignLicense(user.id, userAssignLicenseParameterSet); - }); + AssignLicensePostRequestBody body = new AssignLicensePostRequestBody(); + body.setRemoveLicenses(assignedSkuIds); + + try { + client.getAuthenticated().assignLicense(user.getId(), body); + } catch (RuntimeException ex) { + LOG.error(ex, "While removing licenses from user {0}", user); + } } } else { List toRemove = new ArrayList<>(); @@ -632,18 +763,14 @@ public Uid update( } for (UUID newLicense : newLicenses) { if (!assignedSkuIds.contains(newLicense)) { + AssignedLicense assignedLicense = new AssignedLicense(); + assignedLicense.setSkuId(newLicense); + AssignLicensePostRequestBody body = new AssignLicensePostRequestBody(); + body.setAddLicenses(Collections.singletonList(assignedLicense)); + // executing an assignment per single license in order to skip errors from invalid licenses try { - UserAssignLicenseParameterSet userAssignLicenseParameterSet = - new UserAssignLicenseParameterSet(); - AssignedLicense assignedLicense = new AssignedLicense(); - assignedLicense.skuId = newLicense; - LinkedList assignedLicenses = new LinkedList<>(); - assignedLicenses.add(assignedLicense); - List removedLicenses = new ArrayList<>(); - userAssignLicenseParameterSet.addLicenses = assignedLicenses; - userAssignLicenseParameterSet.removeLicenses = removedLicenses; - client.getAuthenticated().assignLicense(user.id, userAssignLicenseParameterSet); + client.getAuthenticated().assignLicense(user.getId(), body); } catch (RuntimeException ex) { LOG.error(ex, "While assigning license {0} to user {1}", newLicense, user); } @@ -651,19 +778,16 @@ public Uid update( } if (!toRemove.isEmpty()) { + AssignLicensePostRequestBody body = new AssignLicensePostRequestBody(); + body.setRemoveLicenses(toRemove); + try { - UserAssignLicenseParameterSet userAssignLicenseParameterSet = - new UserAssignLicenseParameterSet(); - LinkedList assignedLicenses = new LinkedList<>(); - userAssignLicenseParameterSet.removeLicenses = toRemove; - userAssignLicenseParameterSet.addLicenses = assignedLicenses; - client.getAuthenticated().assignLicense(user.id, userAssignLicenseParameterSet); + client.getAuthenticated().assignLicense(user.getId(), body); } catch (RuntimeException ex) { - LOG.error(ex, "While removing licenses from user {1}", user); + LOG.error(ex, "While removing licenses from user {0}", user); } } } - } return returnUid; @@ -679,13 +803,13 @@ public Uid update( String displayName = accessor.findString(AzureAttributes.GROUP_DISPLAY_NAME); Group group = new Group(); - group.id = uid.getUidValue(); + group.setId(uid.getUidValue()); if (!uid.getUidValue().equals(groupID)) { LOG.info("Update - uid value different from Group ID"); - group.mailNickname = mailNickname; - group.displayName = displayName; + group.setMailNickname(mailNickname); + group.setDisplayName(displayName); } try { @@ -693,7 +817,7 @@ public Uid update( forEach(attribute -> doGroupSetAttribute(attribute.getName(), attribute.getValue(), group)); client.getAuthenticated().updateGroup(group); - returnUid = new Uid(group.id); + returnUid = new Uid(group.getId()); } catch (Exception e) { AzureUtils.wrapGeneralError("Could not update Group " + uid.getUidValue() + " from attributes ", e); } @@ -714,8 +838,8 @@ public AzureClient getClient() { private ConnectorObject fromUser(final User user, final Set attributesToGet) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setObjectClass(ObjectClass.ACCOUNT); - builder.setUid(user.id); - builder.setName(user.userPrincipalName); + builder.setUid(user.getId()); + builder.setName(user.getUserPrincipalName()); try { Set attrs = new HashSet<>(); @@ -724,158 +848,159 @@ private ConnectorObject fromUser(final User user, final Set attributesTo for (Field field : fields) { if (field.getAnnotation(JsonIgnore.class) == null) { field.setAccessible(true); - if (field.getName().equals(AzureAttributes.USER_PASSWORD_PROFILE) && user.passwordProfile != null) { + if (field.getName().equals(AzureAttributes.USER_PASSWORD_PROFILE) + && user.getPasswordProfile() != null && user.getPasswordProfile().getPassword() != null) { + attrs.add(AttributeBuilder.build(AzureAttributes.USER_PASSWORD_PROFILE, - user.passwordProfile.password == null - ? null - : new GuardedString(user.passwordProfile.password.toCharArray()))); + new GuardedString(user.getPasswordProfile().getPassword().toCharArray()))); } else if (field.getName().equals(AzureAttributes.USER_ACCOUNT_ENABLED) - && user.accountEnabled != null) { - attrs.add(AttributeBuilder.build(AzureAttributes.USER_ACCOUNT_ENABLED, user.accountEnabled)); + && user.getAccountEnabled() != null) { + attrs.add(AttributeBuilder.build( + AzureAttributes.USER_ACCOUNT_ENABLED, user.getAccountEnabled())); } else { switch (field.getName()) { case "displayName": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.displayName, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getDisplayName(), field.getName(), field.getType()).build()); break; case "id": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.id, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getId(), field.getName(), field.getType()).build()); break; case "userPrincipalName": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.userPrincipalName, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getUserPrincipalName(), field.getName(), field.getType()).build()); break; case "city": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.city, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getCity(), field.getName(), field.getType()).build()); break; case "country": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.country, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getCountry(), field.getName(), field.getType()).build()); break; case "department": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.department, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getDepartment(), field.getName(), field.getType()).build()); break; case "businessPhones": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.businessPhones, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getBusinessPhones(), field.getName(), field.getType()).build()); break; case "givenName": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.givenName, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getGivenName(), field.getName(), field.getType()).build()); break; case "onPremisesImmutableId": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.onPremisesImmutableId, - field.getName(), field.getType()).build()); + attrs.add(AzureAttributes.doBuildAttributeFromClassField( + user.getOnPremisesImmutableId(), field.getName(), field.getType()).build()); break; case "jobTitle": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.jobTitle, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getJobTitle(), field.getName(), field.getType()).build()); break; case "mail": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.mail, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getMail(), field.getName(), field.getType()).build()); break; case "mobilePhone": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.mobilePhone, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getMobilePhone(), field.getName(), field.getType()).build()); break; case "preferredLanguage": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.preferredLanguage, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getPreferredLanguage(), field.getName(), field.getType()).build()); break; case "officeLocation": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.officeLocation, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getOfficeLocation(), field.getName(), field.getType()).build()); break; case "postalCode": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.postalCode, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getPostalCode(), field.getName(), field.getType()).build()); break; case "state": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.state, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getState(), field.getName(), field.getType()).build()); break; case "streetAddress": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.streetAddress, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getStreetAddress(), field.getName(), field.getType()).build()); break; case "surname": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.surname, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getSurname(), field.getName(), field.getType()).build()); break; case "usageLocation": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.usageLocation, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getUsageLocation(), field.getName(), field.getType()).build()); break; case "companyName": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.companyName, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getCompanyName(), field.getName(), field.getType()).build()); break; case "creationType": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.creationType, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getCreationType(), field.getName(), field.getType()).build()); break; case "employeeId": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.employeeId, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getEmployeeId(), field.getName(), field.getType()).build()); break; case "onPremisesDistinguishedName": attrs.add(AzureAttributes. - doBuildAttributeFromClassField(user.onPremisesDistinguishedName, + doBuildAttributeFromClassField(user.getOnPremisesDistinguishedName(), field.getName(), field.getType()).build()); break; case "onPremisesSecurityIdentifier": attrs.add(AzureAttributes. - doBuildAttributeFromClassField(user.onPremisesSecurityIdentifier, + doBuildAttributeFromClassField(user.getOnPremisesSecurityIdentifier(), field.getName(), field.getType()).build()); break; case "showInAddressList": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.showInAddressList, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getShowInAddressList(), field.getName(), field.getType()).build()); break; case "proxyAddresses": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.proxyAddresses, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getProxyAddresses(), field.getName(), field.getType()).build()); break; case "userType": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.userType, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getUserType(), field.getName(), field.getType()).build()); break; case "otherMails": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.otherMails, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(user.getOtherMails(), field.getName(), field.getType()).build()); break; case "provisionedPlans": - List provisionedPlans = user.provisionedPlans == null + List provisionedPlans = user.getProvisionedPlans() == null ? null - : user.provisionedPlans.stream() - .map(provisionedPlan -> provisionedPlan.service) - .collect(Collectors.toList()); + : user.getProvisionedPlans().stream() + .map(ProvisionedPlan::getService) + .collect(Collectors.toList()); attrs.add(new AttributeBuilder().build(field.getName(), provisionedPlans)); break; case "assignedLicenses": - List assignedLicenses = user.assignedLicenses == null + List assignedLicenses = user.getAssignedLicenses() == null ? null - : user.assignedLicenses.stream() - .map(assignedLicense -> - assignedLicense.skuId == null - ? "" - : assignedLicense.skuId.toString()) - .collect(Collectors.toList()); + : user.getAssignedLicenses().stream() + .map(assignedLicense + -> assignedLicense.getSkuId() == null + ? "" + : assignedLicense.getSkuId().toString()) + .collect(Collectors.toList()); attrs.add(new AttributeBuilder().build(field.getName(), assignedLicenses)); break; case "assignedPlans": - List assignedPlans = user.assignedPlans == null + List assignedPlans = user.getAssignedPlans() == null ? null - : user.assignedPlans.stream() - .map(assignedPlan -> - assignedPlan.servicePlanId == null - ? "" - : assignedPlan.servicePlanId.toString()) - .collect(Collectors.toList()); + : user.getAssignedPlans().stream() + .map(assignedPlan + -> assignedPlan.getServicePlanId() == null + ? "" + : assignedPlan.getServicePlanId().toString()) + .collect(Collectors.toList()); attrs.add(new AttributeBuilder().build(field.getName(), assignedPlans)); break; default: @@ -903,9 +1028,9 @@ private ConnectorObject fromUser(final User user, final Set attributesTo if (attributesToGet.contains(PredefinedAttributes.GROUPS_NAME)) { List groupNames = new ArrayList<>(); - List groups = client.getAuthenticated().getAllGroupsForUser(user.id); + List groups = client.getAuthenticated().getAllGroupsForUser(user.getId()); for (Group group : groups) { - groupNames.add(group.mailNickname); + groupNames.add(group.getMailNickname()); } builder.addAttribute(AttributeBuilder.build(PredefinedAttributes.GROUPS_NAME, groupNames)); } @@ -916,8 +1041,8 @@ private ConnectorObject fromUser(final User user, final Set attributesTo private ConnectorObject fromGroup(final Group group, final Set attributesToGet) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setObjectClass(ObjectClass.GROUP); - builder.setUid(group.id); - builder.setName(group.mailNickname); + builder.setUid(group.getId()); + builder.setName(group.getMailNickname()); try { Set attrs = new HashSet<>(); @@ -927,75 +1052,75 @@ private ConnectorObject fromGroup(final Group group, final Set attribute field.setAccessible(true); switch (field.getName()) { case "id": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.id, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getId(), field.getName(), field.getType()).build()); break; case "mail": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.mail, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getMail(), field.getName(), field.getType()).build()); break; case "mailEnabled": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.mailEnabled, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getMailEnabled(), field.getName(), field.getType()).build()); break; case "onPremisesSecurityIdentifier": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.onPremisesSecurityIdentifier, - field.getName(), field.getType()).build()); + attrs.add(AzureAttributes.doBuildAttributeFromClassField( + group.getOnPremisesSecurityIdentifier(), field.getName(), field.getType()).build()); break; case "proxyAddresses": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.proxyAddresses, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getProxyAddresses(), field.getName(), field.getType()).build()); break; case "description": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.description, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getDescription(), field.getName(), field.getType()).build()); break; case "securityEnabled": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.securityEnabled, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getSecurityEnabled(), field.getName(), field.getType()).build()); break; case "classification": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.classification, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getClassification(), field.getName(), field.getType()).build()); break; case "groupTypes": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.groupTypes, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getGroupTypes(), field.getName(), field.getType()).build()); break; case "preferredLanguage": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.preferredLanguage, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getPreferredLanguage(), field.getName(), field.getType()).build()); break; case "securityIdentifier": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.securityIdentifier, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getSecurityIdentifier(), field.getName(), field.getType()).build()); break; case "theme": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.theme, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getTheme(), field.getName(), field.getType()).build()); break; case "visibility": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.visibility, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getVisibility(), field.getName(), field.getType()).build()); break; case AzureAttributes.GROUP_MAIL_NICKNAME: - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.mailNickname, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getMailNickname(), field.getName(), field.getType()).build()); break; case AzureAttributes.GROUP_DISPLAY_NAME: - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.displayName, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getDisplayName(), field.getName(), field.getType()).build()); break; case "allowExternalSenders": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.allowExternalSenders, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getAllowExternalSenders(), field.getName(), field.getType()).build()); break; case "autoSubscribeNewMembers": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.autoSubscribeNewMembers, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getAutoSubscribeNewMembers(), field.getName(), field.getType()).build()); break; case "preferredDataLocation": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.preferredDataLocation, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(group.getPreferredDataLocation(), field.getName(), field.getType()).build()); break; default: @@ -1015,24 +1140,24 @@ private ConnectorObject fromGroup(final Group group, final Set attribute } if (attributesToGet.contains(AzureAttributes.GROUP_ID)) { - builder.addAttribute(AttributeBuilder.build(AzureAttributes.GROUP_ID, group.id)); + builder.addAttribute(AttributeBuilder.build(AzureAttributes.GROUP_ID, group.getId())); } if (attributesToGet.contains(PredefinedAttributes.GROUPS_NAME)) { - List groupNames = client.getAuthenticated().getAllGroupsForGroup(group.id). - stream().map(g -> g.mailNickname). + List groupNames = client.getAuthenticated().getAllGroupsForGroup(group.getId()). + stream().map(Group::getMailNickname). collect(Collectors.toList()); builder.addAttribute(AttributeBuilder.build(PredefinedAttributes.GROUPS_NAME, groupNames)); } - + return builder.build(); } private ConnectorObject fromLicense(final SubscribedSku subscribedSku, final Set attributesToGet) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setObjectClass(new ObjectClass(AzureAttributes.AZURE_LICENSE_NAME)); - builder.setUid(subscribedSku.id); - builder.setName(String.valueOf(subscribedSku.skuId)); + builder.setUid(subscribedSku.getId()); + builder.setName(String.valueOf(subscribedSku.getSkuId())); try { Set attrs = new HashSet<>(); @@ -1042,35 +1167,35 @@ private ConnectorObject fromLicense(final SubscribedSku subscribedSku, final Set field.setAccessible(true); switch (field.getName()) { case "id": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.id, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getId(), field.getName(), field.getType()).build()); break; case "appliesTo": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.appliesTo, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getAppliesTo(), field.getName(), field.getType()).build()); break; case "capabilityStatus": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.capabilityStatus, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getCapabilityStatus(), field.getName(), field.getType()).build()); break; case "consumedUnits": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.consumedUnits, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getConsumedUnits(), field.getName(), field.getType()).build()); break; case "prepaidUnits": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.prepaidUnits, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getPrepaidUnits(), field.getName(), field.getType()).build()); break; case "servicePlans": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.servicePlans, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getServicePlans(), field.getName(), field.getType()).build()); break; case "skuPartNumber": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.skuPartNumber, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getSkuPartNumber(), field.getName(), field.getType()).build()); break; case "oDataType": - attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.oDataType, + attrs.add(AzureAttributes.doBuildAttributeFromClassField(subscribedSku.getOdataType(), field.getName(), field.getType()).build()); break; default: @@ -1090,185 +1215,9 @@ private ConnectorObject fromLicense(final SubscribedSku subscribedSku, final Set } if (attributesToGet.contains(AzureAttributes.AZURE_LICENSE_NAME)) { - builder.addAttribute(AttributeBuilder.build(AzureAttributes.AZURE_LICENSE_NAME, subscribedSku.id)); + builder.addAttribute(AttributeBuilder.build(AzureAttributes.AZURE_LICENSE_NAME, subscribedSku.getId())); } return builder.build(); } - - private String getSkipToken(final BaseCollectionRequestBuilder request) { - String token = null; - // set token only if the request is not null (not in the last page) - if (request != null) { - token = request.getRequestUrl() - .substring(request.getRequestUrl().indexOf(SKIP_TOKEN_ID) + SKIP_TOKEN_ID.length()); - } - return StringUtil.isNotBlank(token) ? token.substring(0, token.indexOf("&")) : null; - } - - @SuppressWarnings("unchecked") - private void doUserSetAttribute(final String name, final List values, final User user) { - Object value = values.isEmpty() ? null : values.get(0); - switch (name) { - case "displayName": - user.displayName = (String) value; - break; - case "id": - user.id = (String) value; - break; - case "city": - user.city = (String) value; - break; - case "country": - user.country = (String) value; - break; - case "department": - user.department = (String) value; - break; - case "businessPhones": - user.businessPhones = new ArrayList<>((List) (List) values); - break; - case "givenName": - user.givenName = (String) value; - break; - case "onPremisesImmutableId": - user.onPremisesImmutableId = (String) value; - break; - case "jobTitle": - user.jobTitle = (String) value; - break; - case "mail": - user.mail = (String) value; - break; - case "mobilePhone": - user.mobilePhone = (String) value; - break; - case "passwordPolicies": - user.passwordPolicies = (String) value; - break; - case "preferredLanguage": - user.preferredLanguage = (String) value; - break; - case "officeLocation": - user.officeLocation = (String) value; - break; - case "postalCode": - user.postalCode = (String) value; - break; - case "state": - user.state = (String) value; - break; - case "streetAddress": - user.streetAddress = (String) value; - break; - case "surname": - user.surname = (String) value; - break; - case "usageLocation": - user.usageLocation = (String) value; - break; - case "userPrincipalName": - user.userPrincipalName = (String) value; - break; - case "companyName": - user.companyName = (String) value; - break; - case "creationType": - user.creationType = (String) value; - break; - case "employeeId": - user.employeeId = (String) value; - break; - case "onPremisesDistinguishedName": - user.onPremisesDistinguishedName = (String) value; - break; - case "onPremisesSecurityIdentifier": - user.onPremisesSecurityIdentifier = (String) value; - break; - case "showInAddressList": - user.showInAddressList = (Boolean) value; - break; - case "proxyAddresses": - user.proxyAddresses = new ArrayList<>((List) (List) values); - break; - case "userType": - user.userType = (String) value; - break; - case "otherMails": - user.otherMails = new ArrayList<>((List) (List) values); - break; - case "provisionedPlans": - user.provisionedPlans = new ArrayList<>((List) (List) values); - break; - case "assignedLicenses": - user.assignedLicenses = new ArrayList<>((List) (List) values); - break; - case "assignedPlans": - user.assignedPlans = new ArrayList<>((List) (List) values); - break; - default: - } - } - - @SuppressWarnings("unchecked") - private void doGroupSetAttribute(final String name, final List values, final Group group) { - Object value = values.isEmpty() ? null : values.get(0); - switch (name) { - case "id": - group.id = (String) value; - break; - case "mail": - group.mail = (String) value; - break; - case "mailEnabled": - group.mailEnabled = (Boolean) value; - break; - case "onPremisesSecurityIdentifier": - group.onPremisesSecurityIdentifier = (String) value; - break; - case "proxyAddresses": - group.proxyAddresses = new ArrayList<>((List) (List) values); - break; - case "description": - group.description = (String) value; - break; - case "securityEnabled": - group.securityEnabled = (Boolean) value; - break; - case "classification": - group.classification = (String) value; - break; - case "groupTypes": - group.groupTypes = new ArrayList<>((List) (List) values); - break; - case "preferredLanguage": - group.preferredLanguage = (String) value; - break; - case "securityIdentifier": - group.securityIdentifier = (String) value; - break; - case "theme": - group.theme = (String) value; - break; - case "visibility": - group.visibility = (String) value; - break; - case AzureAttributes.GROUP_MAIL_NICKNAME: - group.mailNickname = (String) value; - break; - case AzureAttributes.GROUP_DISPLAY_NAME: - group.displayName = (String) value; - break; - case "allowExternalSenders": - group.allowExternalSenders = (Boolean) value; - break; - case "autoSubscribeNewMembers": - group.autoSubscribeNewMembers = (Boolean) value; - break; - case "preferredDataLocation": - group.preferredDataLocation = (String) value; - break; - default: - } - } } diff --git a/src/main/java/net/tirasa/connid/bundles/azure/service/AzureClient.java b/src/main/java/net/tirasa/connid/bundles/azure/service/AzureClient.java index 31153c9..59a71ce 100644 --- a/src/main/java/net/tirasa/connid/bundles/azure/service/AzureClient.java +++ b/src/main/java/net/tirasa/connid/bundles/azure/service/AzureClient.java @@ -15,25 +15,23 @@ */ package net.tirasa.connid.bundles.azure.service; -import com.microsoft.graph.http.GraphServiceException; +import com.microsoft.graph.directoryobjects.item.getmembergroups.GetMemberGroupsPostRequestBody; +import com.microsoft.graph.directoryobjects.item.getmemberobjects.GetMemberObjectsPostRequestBody; import com.microsoft.graph.models.DirectoryObject; -import com.microsoft.graph.models.DirectoryObjectGetMemberGroupsParameterSet; -import com.microsoft.graph.models.DirectoryObjectGetMemberObjectsParameterSet; +import com.microsoft.graph.models.DirectoryObjectCollectionResponse; import com.microsoft.graph.models.Group; +import com.microsoft.graph.models.GroupCollectionResponse; +import com.microsoft.graph.models.ReferenceCreate; import com.microsoft.graph.models.SubscribedSku; +import com.microsoft.graph.models.SubscribedSkuCollectionResponse; import com.microsoft.graph.models.User; -import com.microsoft.graph.models.UserAssignLicenseParameterSet; -import com.microsoft.graph.options.HeaderOption; -import com.microsoft.graph.options.Option; -import com.microsoft.graph.options.QueryOption; -import com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage; -import com.microsoft.graph.requests.GraphServiceClient; -import com.microsoft.graph.requests.GroupCollectionPage; -import com.microsoft.graph.requests.SubscribedSkuCollectionPage; -import com.microsoft.graph.requests.UserCollectionPage; +import com.microsoft.graph.models.UserCollectionResponse; +import com.microsoft.graph.users.item.assignlicense.AssignLicensePostRequestBody; import java.util.ArrayList; -import java.util.LinkedList; +import java.util.Collections; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import net.tirasa.connid.bundles.azure.AzureConnectorConfiguration; import net.tirasa.connid.bundles.azure.utils.AzureAttributes; import net.tirasa.connid.bundles.azure.utils.AzureFilter; @@ -60,15 +58,13 @@ public AzureClient getAuthenticated() { */ public List getAllUsers() { LOG.ok("Get all users"); - GraphServiceClient graphClient = getGraphServiceClient(); - UserCollectionPage userCollectionPage = graphClient.users().buildRequest(). - select(String.join(",", config.getUserAttributesToGet())). - orderBy(AzureAttributes.USER_DISPLAY_NAME).get(); - List users = new ArrayList<>(); - if (userCollectionPage != null) { - users = userCollectionPage.getCurrentPage(); - } - return users; + + UserCollectionResponse result = getGraphServiceClient().users().get(req -> { + req.queryParameters.select = config.getUserAttributesToGet(); + req.queryParameters.orderby = new String[] { AzureAttributes.USER_DISPLAY_NAME }; + }); + + return Optional.ofNullable(result).map(UserCollectionResponse::getValue).orElse(Collections.emptyList()); } /** @@ -76,31 +72,20 @@ public List getAllUsers() { * @param pageSize * @return paged list of Users */ - public List getAllUsers(final int pageSize) { + public UserCollectionResponse getAllUsers(final int pageSize) { LOG.ok("Get all users with page size {0}", pageSize); - GraphServiceClient graphClient = getGraphServiceClient(); - UserCollectionPage userCollectionPage = graphClient.users().buildRequest(). - select(String.join(",", config.getUserAttributesToGet())). - top(pageSize).orderBy(AzureAttributes.USER_DISPLAY_NAME).get(); - List users = new ArrayList<>(); - if (userCollectionPage != null) { - users = userCollectionPage.getCurrentPage(); - } - return users; + + return getGraphServiceClient().users().get(req -> { + req.queryParameters.select = config.getUserAttributesToGet(); + req.queryParameters.orderby = new String[] { AzureAttributes.USER_DISPLAY_NAME }; + req.queryParameters.top = pageSize; + }); } - /** - * - * @param pageSize - * @param skipToken - * @return paged list of Users - */ - public UserCollectionPage getAllUsersNextPage(final int pageSize, final String skipToken) { - LOG.ok("Get all users next page with page size {0}", pageSize); - GraphServiceClient graphClient = getGraphServiceClient(); - return graphClient.users().buildRequest(). - select(String.join(",", config.getUserAttributesToGet())). - top(pageSize).skipToken(skipToken).orderBy(AzureAttributes.USER_DISPLAY_NAME).get(); + public UserCollectionResponse getAllUsersNextPage(final String odataNextLink) { + LOG.ok("Get all users next page {0}", odataNextLink); + + return getGraphServiceClient().users().withUrl(odataNextLink).get(); } /** @@ -110,9 +95,10 @@ public UserCollectionPage getAllUsersNextPage(final int pageSize, final String s */ public User getUser(final String userId) { LOG.ok("Getting user {0}", userId); - GraphServiceClient graphClient = getGraphServiceClient(); - return graphClient.users(userId).buildRequest(). - select(String.join(",", config.getUserAttributesToGet())).get(); + + return getGraphServiceClient().users().byUserId(userId).get(req -> { + req.queryParameters.select = config.getUserAttributesToGet(); + }); } /** @@ -121,25 +107,20 @@ public User getUser(final String userId) { * @return List of Users with specified filters values */ public List getUsersFilteredBy(final AzureFilter filters) { - GraphServiceClient graphClient = getGraphServiceClient(); - - //This request requires the ConsistencyLevel header set to eventual - //because the request has both the $orderBy and $filter query parameters - LinkedList