public async Task <HashSet <string> > DirectoryRoles() { try { var directoryRoles = await GraphServiceHelper.GetDirectoryRolesAsync(_graphClient, _httpContext); var userIds = await GraphServiceHelper.GetUsersAsync(_graphClient, _httpContext); var administrators = new HashSet <string>(); var directoryRolesNames = new HashSet <string>(); await directoryRoles.ForEachAsync(async _ => { var roleMembers = await GraphServiceHelper.GetDirectoryRoleMembers(_graphClient, _httpContext, _.Id); var members = Extensions.DirectoryRoleMembersResultsToList(roleMembers); BloodHoundHelper.DirectoryRoleMembership(_, members); if (Startup.IsCosmosDbGraphEnabled) { CosmosDbGraphHelper.DirectoryRoleMembership(_, members); GetDeviceAdministratorsIds(_.DisplayName, members, administrators); CosmosDbGraphHelper.DirectoryRolePermissions(_, userIds, administrators); } directoryRolesNames.Add(_.DisplayName); }); return(directoryRolesNames); } catch (Exception ex) { _logger.Error(ex, $"{nameof(DirectoryRoles)} {ex.Message} {ex.InnerException}"); return(null); } }
public async Task <HashSet <DirectoryObject> > DeviceOwners() { try { var directoryRoles = await GraphServiceHelper.GetDirectoryRolesAsync(_graphClient, _httpContext); var devices = await GraphServiceHelper.GetDevicesAsync(_graphClient, _httpContext); HashSet <DirectoryObject> ownersList = new HashSet <DirectoryObject>(); await devices. Where(_ => _.DisplayName != null). ForEachAsync(async _ => { _deviceObjectIdToDeviceId.Add(_.DeviceId, _.Id); var ownerList = (await GraphServiceHelper.GetDeviceOwners(_graphClient, _httpContext, _.Id)) .Where(__ => __ != null) .ToList(); BloodHoundHelper.DeviceOwners(_, ownerList); if (Startup.IsCosmosDbGraphEnabled) { CosmosDbGraphHelper.DeviceOwners(_, ownerList, directoryRoles); } ownersList.UnionWith(ownerList); }); return(ownersList); } catch (Exception ex) { _logger.Error(ex, $"{nameof(DeviceOwners)} {ex.Message} {ex.InnerException}"); return(null); } }