'MSAL Exchange Roles Group

I am trying to retrieve the "Members)" information from Exchange "Role assignments" (eg. Compliance Management, Discovery Management, ExchangeServiceAdmins_xx, etc) using the following code but am not able to find them. It is only able to list the "Assigned Roles" in the Azure Active Directory.

Any idea what I have doing wrong here?

DirectoryObjectCollectionWithReferencesPage roles = gGraphClient.users(username).memberOf().buildRequest().get();
  
DirectoryObject r;
DirectoryRole role;
Group g;
if (roles == null)
{
  throw new Exception("Bye");
}
List<DirectoryObject> currentPageGroup = roles.getCurrentPage();
Iterator itr = currentPageGroup.iterator();
while (itr.hasNext())
{
  r = (DirectoryObject) itr.next();
  if (r.oDataType.endsWith("group"))
  {
    g = (Group) r;
    System.out.println(g.displayName);
  }
  else
  {
    role = (DirectoryRole) r;
    System.out.println(role.displayName);
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source