mirror of
https://github.com/bitwarden/server.git
synced 2025-06-13 06:20:48 -05:00
Removed constructors from OrganizationLicense
This commit is contained in:
parent
a7c532171b
commit
9721d4bfb3
@ -1,78 +1,12 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Bit.Core.AdminConsole.Entities;
|
|
||||||
using Bit.Core.Billing.Enums;
|
using Bit.Core.Billing.Enums;
|
||||||
using Bit.Core.Billing.Licenses.Attributes;
|
using Bit.Core.Billing.Licenses.Attributes;
|
||||||
using Bit.Core.Billing.Licenses.Extensions;
|
|
||||||
using Bit.Core.Services;
|
|
||||||
|
|
||||||
namespace Bit.Core.Models.Business;
|
namespace Bit.Core.Models.Business;
|
||||||
|
|
||||||
public class OrganizationLicense : BaseLicense
|
public class OrganizationLicense : BaseLicense
|
||||||
{
|
{
|
||||||
public OrganizationLicense()
|
[Obsolete("No longer used in the JWT based license format")]
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId,
|
|
||||||
ILicensingService licenseService, int? version = null)
|
|
||||||
{
|
|
||||||
Version = version.GetValueOrDefault(CurrentLicenseFileVersion); // TODO: Remember to change the constant
|
|
||||||
LicenseType = Enums.LicenseType.Organization;
|
|
||||||
LicenseKey = org.LicenseKey;
|
|
||||||
InstallationId = installationId;
|
|
||||||
Id = org.Id;
|
|
||||||
Name = org.Name;
|
|
||||||
BillingEmail = org.BillingEmail;
|
|
||||||
BusinessName = org.BusinessName;
|
|
||||||
Enabled = org.Enabled;
|
|
||||||
Plan = org.Plan;
|
|
||||||
PlanType = org.PlanType;
|
|
||||||
Seats = org.Seats;
|
|
||||||
MaxCollections = org.MaxCollections;
|
|
||||||
UsePolicies = org.UsePolicies;
|
|
||||||
UseSso = org.UseSso;
|
|
||||||
UseKeyConnector = org.UseKeyConnector;
|
|
||||||
UseScim = org.UseScim;
|
|
||||||
UseGroups = org.UseGroups;
|
|
||||||
UseEvents = org.UseEvents;
|
|
||||||
UseDirectory = org.UseDirectory;
|
|
||||||
UseTotp = org.UseTotp;
|
|
||||||
Use2fa = org.Use2fa;
|
|
||||||
UseApi = org.UseApi;
|
|
||||||
UseResetPassword = org.UseResetPassword;
|
|
||||||
MaxStorageGb = org.MaxStorageGb;
|
|
||||||
SelfHost = org.SelfHost;
|
|
||||||
UsersGetPremium = org.UsersGetPremium;
|
|
||||||
UseCustomPermissions = org.UseCustomPermissions;
|
|
||||||
Issued = DateTime.UtcNow;
|
|
||||||
UsePasswordManager = org.UsePasswordManager;
|
|
||||||
UseSecretsManager = org.UseSecretsManager;
|
|
||||||
SmSeats = org.SmSeats;
|
|
||||||
SmServiceAccounts = org.SmServiceAccounts;
|
|
||||||
UseRiskInsights = org.UseRiskInsights;
|
|
||||||
UseOrganizationDomains = org.UseOrganizationDomains;
|
|
||||||
|
|
||||||
// Deprecated. Left for backwards compatibility with old license versions.
|
|
||||||
LimitCollectionCreationDeletion = org.LimitCollectionCreation || org.LimitCollectionDeletion;
|
|
||||||
AllowAdminAccessToAllCollectionItems = org.AllowAdminAccessToAllCollectionItems;
|
|
||||||
//
|
|
||||||
|
|
||||||
Expires = org.CalculateFreshExpirationDate(subscriptionInfo, Issued);
|
|
||||||
Refresh = org.CalculateFreshRefreshDate(subscriptionInfo, Expires, Issued);
|
|
||||||
ExpirationWithoutGracePeriod = org.CalculateFreshExpirationDateWithoutGracePeriod(subscriptionInfo);
|
|
||||||
Trial = org.IsTrialing(subscriptionInfo);
|
|
||||||
|
|
||||||
UseAdminSponsoredFamilies = org.UseAdminSponsoredFamilies;
|
|
||||||
Hash = Convert.ToBase64String(this.ComputeHash());
|
|
||||||
Signature = Convert.ToBase64String(licenseService.SignLicense(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents the current version of the license format. Should be updated whenever new fields are added.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>Intentionally set one version behind to allow self hosted users some time to update before
|
|
||||||
/// getting out of date license errors
|
|
||||||
/// </remarks>
|
|
||||||
public const int CurrentLicenseFileVersion = 15;
|
public const int CurrentLicenseFileVersion = 15;
|
||||||
|
|
||||||
[LicenseVersion(1)]
|
[LicenseVersion(1)]
|
||||||
@ -182,8 +116,4 @@ public class OrganizationLicense : BaseLicense
|
|||||||
{
|
{
|
||||||
get => Version is >= 1 and <= CurrentLicenseFileVersion + 1;
|
get => Version is >= 1 and <= CurrentLicenseFileVersion + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
|
using Bit.Core.Billing.Licenses.Extensions;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.Business;
|
using Bit.Core.Models.Business;
|
||||||
@ -15,20 +16,17 @@ public class CloudGetOrganizationLicenseQuery : ICloudGetOrganizationLicenseQuer
|
|||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
private readonly ILicensingService _licensingService;
|
private readonly ILicensingService _licensingService;
|
||||||
private readonly IProviderRepository _providerRepository;
|
private readonly IProviderRepository _providerRepository;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
public CloudGetOrganizationLicenseQuery(
|
public CloudGetOrganizationLicenseQuery(
|
||||||
IInstallationRepository installationRepository,
|
IInstallationRepository installationRepository,
|
||||||
IPaymentService paymentService,
|
IPaymentService paymentService,
|
||||||
ILicensingService licensingService,
|
ILicensingService licensingService,
|
||||||
IProviderRepository providerRepository,
|
IProviderRepository providerRepository)
|
||||||
IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_installationRepository = installationRepository;
|
_installationRepository = installationRepository;
|
||||||
_paymentService = paymentService;
|
_paymentService = paymentService;
|
||||||
_licensingService = licensingService;
|
_licensingService = licensingService;
|
||||||
_providerRepository = providerRepository;
|
_providerRepository = providerRepository;
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<OrganizationLicense> GetLicenseAsync(Organization organization, Guid installationId,
|
public async Task<OrganizationLicense> GetLicenseAsync(Organization organization, Guid installationId,
|
||||||
@ -41,7 +39,60 @@ public class CloudGetOrganizationLicenseQuery : ICloudGetOrganizationLicenseQuer
|
|||||||
}
|
}
|
||||||
|
|
||||||
var subscriptionInfo = await GetSubscriptionAsync(organization);
|
var subscriptionInfo = await GetSubscriptionAsync(organization);
|
||||||
var license = new OrganizationLicense(organization, subscriptionInfo, installationId, _licensingService, version);
|
var issued = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var license = new OrganizationLicense
|
||||||
|
{
|
||||||
|
Version = version.GetValueOrDefault(OrganizationLicense.CurrentLicenseFileVersion),
|
||||||
|
LicenseType = LicenseType.Organization,
|
||||||
|
LicenseKey = organization.LicenseKey,
|
||||||
|
InstallationId = installationId,
|
||||||
|
Id = organization.Id,
|
||||||
|
Name = organization.Name,
|
||||||
|
BillingEmail = organization.BillingEmail,
|
||||||
|
BusinessName = organization.BusinessName,
|
||||||
|
Enabled = organization.Enabled,
|
||||||
|
Plan = organization.Plan,
|
||||||
|
PlanType = organization.PlanType,
|
||||||
|
Seats = organization.Seats,
|
||||||
|
MaxCollections = organization.MaxCollections,
|
||||||
|
UsePolicies = organization.UsePolicies,
|
||||||
|
UseSso = organization.UseSso,
|
||||||
|
UseKeyConnector = organization.UseKeyConnector,
|
||||||
|
UseScim = organization.UseScim,
|
||||||
|
UseGroups = organization.UseGroups,
|
||||||
|
UseEvents = organization.UseEvents,
|
||||||
|
UseDirectory = organization.UseDirectory,
|
||||||
|
UseTotp = organization.UseTotp,
|
||||||
|
Use2fa = organization.Use2fa,
|
||||||
|
UseApi = organization.UseApi,
|
||||||
|
UseResetPassword = organization.UseResetPassword,
|
||||||
|
MaxStorageGb = organization.MaxStorageGb,
|
||||||
|
SelfHost = organization.SelfHost,
|
||||||
|
UsersGetPremium = organization.UsersGetPremium,
|
||||||
|
UseCustomPermissions = organization.UseCustomPermissions,
|
||||||
|
Issued = issued,
|
||||||
|
UsePasswordManager = organization.UsePasswordManager,
|
||||||
|
UseSecretsManager = organization.UseSecretsManager,
|
||||||
|
SmSeats = organization.SmSeats,
|
||||||
|
SmServiceAccounts = organization.SmServiceAccounts,
|
||||||
|
UseRiskInsights = organization.UseRiskInsights,
|
||||||
|
UseOrganizationDomains = organization.UseOrganizationDomains,
|
||||||
|
|
||||||
|
// Deprecated. Left for backwards compatibility with old license versions.
|
||||||
|
LimitCollectionCreationDeletion = organization.LimitCollectionCreation || organization.LimitCollectionDeletion,
|
||||||
|
AllowAdminAccessToAllCollectionItems = organization.AllowAdminAccessToAllCollectionItems,
|
||||||
|
|
||||||
|
Expires = organization.CalculateFreshExpirationDate(subscriptionInfo, issued),
|
||||||
|
Refresh = organization.CalculateFreshRefreshDate(subscriptionInfo, organization.CalculateFreshExpirationDate(subscriptionInfo, issued), issued),
|
||||||
|
ExpirationWithoutGracePeriod = organization.CalculateFreshExpirationDateWithoutGracePeriod(subscriptionInfo),
|
||||||
|
Trial = organization.IsTrialing(subscriptionInfo),
|
||||||
|
UseAdminSponsoredFamilies = organization.UseAdminSponsoredFamilies
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hash is included in Signature, and so must be initialized before signing
|
||||||
|
license.Hash = Convert.ToBase64String(license.ComputeHash());
|
||||||
|
license.Signature = Convert.ToBase64String(_licensingService.SignLicense(license));
|
||||||
license.Token = await _licensingService.CreateOrganizationTokenAsync(organization, installationId, subscriptionInfo);
|
license.Token = await _licensingService.CreateOrganizationTokenAsync(organization, installationId, subscriptionInfo);
|
||||||
|
|
||||||
return license;
|
return license;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user