diff --git a/src/Core/Services/Implementations/LicensingService.cs b/src/Core/Services/Implementations/LicensingService.cs index 893ea22689..fc8cfe5737 100644 --- a/src/Core/Services/Implementations/LicensingService.cs +++ b/src/Core/Services/Implementations/LicensingService.cs @@ -81,35 +81,49 @@ public class LicensingService : ILicensingService var enabledOrgs = await _organizationRepository.GetManyByEnabledAsync(); _logger.LogInformation(Constants.BypassFiltersEventId, null, - "Validating licenses for {0} organizations.", enabledOrgs.Count); + "Validating licenses for {NumberOfOrganizations} organizations.", enabledOrgs.Count); + + var exceptions = new List(); foreach (var org in enabledOrgs) { - var license = await ReadOrganizationLicenseAsync(org); - if (license == null) + try { - await DisableOrganizationAsync(org, null, "No license file."); - continue; - } + var license = await ReadOrganizationLicenseAsync(org); + if (license == null) + { + await DisableOrganizationAsync(org, null, "No license file."); + continue; + } - var totalLicensedOrgs = enabledOrgs.Count(o => o.LicenseKey.Equals(license.LicenseKey)); - if (totalLicensedOrgs > 1) - { - await DisableOrganizationAsync(org, license, "Multiple organizations."); - continue; - } + var totalLicensedOrgs = enabledOrgs.Count(o => string.Equals(o.LicenseKey, license.LicenseKey)); + if (totalLicensedOrgs > 1) + { + await DisableOrganizationAsync(org, license, "Multiple organizations."); + continue; + } - if (!license.VerifyData(org, _globalSettings)) - { - await DisableOrganizationAsync(org, license, "Invalid data."); - continue; - } + if (!license.VerifyData(org, _globalSettings)) + { + await DisableOrganizationAsync(org, license, "Invalid data."); + continue; + } - if (!license.VerifySignature(_certificate)) - { - await DisableOrganizationAsync(org, license, "Invalid signature."); - continue; + if (!license.VerifySignature(_certificate)) + { + await DisableOrganizationAsync(org, license, "Invalid signature."); + continue; + } } + catch (Exception ex) + { + exceptions.Add(ex); + } + } + + if (exceptions.Any()) + { + throw new AggregateException("There were one or more exceptions while validating organizations.", exceptions); } } diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 5f38cc5207..d798a85ff8 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -700,7 +700,7 @@ public class OrganizationService : IOrganizationService } var enabledOrgs = await _organizationRepository.GetManyByEnabledAsync(); - if (enabledOrgs.Any(o => o.LicenseKey.Equals(license.LicenseKey))) + if (enabledOrgs.Any(o => string.Equals(o.LicenseKey, license.LicenseKey))) { throw new BadRequestException("License is already in use by another organization."); } @@ -852,7 +852,7 @@ public class OrganizationService : IOrganizationService } var enabledOrgs = await _organizationRepository.GetManyByEnabledAsync(); - if (enabledOrgs.Any(o => o.LicenseKey.Equals(license.LicenseKey) && o.Id != organizationId)) + if (enabledOrgs.Any(o => string.Equals(o.LicenseKey, license.LicenseKey) && o.Id != organizationId)) { throw new BadRequestException("License is already in use by another organization."); }