mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
[BEEEP] Add explicit error message when uploading the wrong license type (#1831)
This commit is contained in:
parent
240b6e7463
commit
cd61c826f9
8
src/Core/Enums/LicenseType.cs
Normal file
8
src/Core/Enums/LicenseType.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum LicenseType : byte
|
||||
{
|
||||
User = 0,
|
||||
Organization = 1,
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ namespace Bit.Core.Models.Business
|
||||
ILicensingService licenseService, int? version = null)
|
||||
{
|
||||
Version = version.GetValueOrDefault(CURRENT_LICENSE_FILE_VERSION); // TODO: Remember to change the constant
|
||||
LicenseType = Enums.LicenseType.Organization;
|
||||
LicenseKey = org.LicenseKey;
|
||||
InstallationId = installationId;
|
||||
Id = org.Id;
|
||||
@ -121,6 +122,7 @@ namespace Bit.Core.Models.Business
|
||||
public DateTime? Refresh { get; set; }
|
||||
public DateTime? Expires { get; set; }
|
||||
public bool Trial { get; set; }
|
||||
public LicenseType? LicenseType { get; set; }
|
||||
public string Hash { get; set; }
|
||||
public string Signature { get; set; }
|
||||
[JsonIgnore]
|
||||
|
@ -6,6 +6,7 @@ using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.Models.Business
|
||||
@ -18,6 +19,7 @@ namespace Bit.Core.Models.Business
|
||||
public UserLicense(User user, SubscriptionInfo subscriptionInfo, ILicensingService licenseService,
|
||||
int? version = null)
|
||||
{
|
||||
LicenseType = Enums.LicenseType.User;
|
||||
LicenseKey = user.LicenseKey;
|
||||
Id = user.Id;
|
||||
Name = user.Name;
|
||||
@ -39,6 +41,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public UserLicense(User user, ILicensingService licenseService, int? version = null)
|
||||
{
|
||||
LicenseType = Enums.LicenseType.User;
|
||||
LicenseKey = user.LicenseKey;
|
||||
Id = user.Id;
|
||||
Name = user.Name;
|
||||
@ -66,6 +69,7 @@ namespace Bit.Core.Models.Business
|
||||
public DateTime? Refresh { get; set; }
|
||||
public DateTime? Expires { get; set; }
|
||||
public bool Trial { get; set; }
|
||||
public LicenseType? LicenseType { get; set; }
|
||||
public string Hash { get; set; }
|
||||
public string Signature { get; set; }
|
||||
[JsonIgnore]
|
||||
|
@ -661,6 +661,12 @@ namespace Bit.Core.Services
|
||||
OrganizationLicense license, User owner, string ownerKey, string collectionName, string publicKey,
|
||||
string privateKey)
|
||||
{
|
||||
if (license?.LicenseType != null && license.LicenseType != LicenseType.Organization)
|
||||
{
|
||||
throw new BadRequestException("Premium licenses cannot be applied to an organization. "
|
||||
+ "Upload this license from your personal account settings page.");
|
||||
}
|
||||
|
||||
if (license == null || !_licensingService.VerifyLicense(license))
|
||||
{
|
||||
throw new BadRequestException("Invalid license.");
|
||||
@ -806,6 +812,12 @@ namespace Bit.Core.Services
|
||||
throw new InvalidOperationException("Licenses require self hosting.");
|
||||
}
|
||||
|
||||
if (license?.LicenseType != null && license.LicenseType != LicenseType.Organization)
|
||||
{
|
||||
throw new BadRequestException("Premium licenses cannot be applied to an organization. "
|
||||
+ "Upload this license from your personal account settings page.");
|
||||
}
|
||||
|
||||
if (license == null || !_licensingService.VerifyLicense(license))
|
||||
{
|
||||
throw new BadRequestException("Invalid license.");
|
||||
|
@ -1030,6 +1030,12 @@ namespace Bit.Core.Services
|
||||
throw new InvalidOperationException("Licenses require self hosting.");
|
||||
}
|
||||
|
||||
if (license?.LicenseType != null && license.LicenseType != LicenseType.User)
|
||||
{
|
||||
throw new BadRequestException("Organization licenses cannot be applied to a user. "
|
||||
+ "Upload this license from the Organization settings page.");
|
||||
}
|
||||
|
||||
if (license == null || !_licenseService.VerifyLicense(license))
|
||||
{
|
||||
throw new BadRequestException("Invalid license.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user