mirror of
https://github.com/bitwarden/server.git
synced 2025-02-16 01:51:21 +01:00
Updated claim types to use string constants
This commit is contained in:
parent
8cd040641f
commit
d56de0715b
58
src/Core/Billing/Licenses/LicenseConstants.cs
Normal file
58
src/Core/Billing/Licenses/LicenseConstants.cs
Normal file
@ -0,0 +1,58 @@
|
||||
namespace Bit.Core.Billing.Licenses;
|
||||
|
||||
public static class OrganizationLicenseConstants
|
||||
{
|
||||
public const string LicenseType = nameof(LicenseType);
|
||||
public const string LicenseKey = nameof(LicenseKey);
|
||||
public const string InstallationId = nameof(InstallationId);
|
||||
public const string Id = nameof(Id);
|
||||
public const string Name = nameof(Name);
|
||||
public const string BusinessName = nameof(BusinessName);
|
||||
public const string BillingEmail = nameof(BillingEmail);
|
||||
public const string Enabled = nameof(Enabled);
|
||||
public const string Plan = nameof(Plan);
|
||||
public const string PlanType = nameof(PlanType);
|
||||
public const string Seats = nameof(Seats);
|
||||
public const string MaxCollections = nameof(MaxCollections);
|
||||
public const string UsePolicies = nameof(UsePolicies);
|
||||
public const string UseSso = nameof(UseSso);
|
||||
public const string UseKeyConnector = nameof(UseKeyConnector);
|
||||
public const string UseScim = nameof(UseScim);
|
||||
public const string UseGroups = nameof(UseGroups);
|
||||
public const string UseEvents = nameof(UseEvents);
|
||||
public const string UseDirectory = nameof(UseDirectory);
|
||||
public const string UseTotp = nameof(UseTotp);
|
||||
public const string Use2fa = nameof(Use2fa);
|
||||
public const string UseApi = nameof(UseApi);
|
||||
public const string UseResetPassword = nameof(UseResetPassword);
|
||||
public const string MaxStorageGb = nameof(MaxStorageGb);
|
||||
public const string SelfHost = nameof(SelfHost);
|
||||
public const string UsersGetPremium = nameof(UsersGetPremium);
|
||||
public const string UseCustomPermissions = nameof(UseCustomPermissions);
|
||||
public const string Issued = nameof(Issued);
|
||||
public const string UsePasswordManager = nameof(UsePasswordManager);
|
||||
public const string UseSecretsManager = nameof(UseSecretsManager);
|
||||
public const string SmSeats = nameof(SmSeats);
|
||||
public const string SmServiceAccounts = nameof(SmServiceAccounts);
|
||||
public const string LimitCollectionCreationDeletion = nameof(LimitCollectionCreationDeletion);
|
||||
public const string AllowAdminAccessToAllCollectionItems = nameof(AllowAdminAccessToAllCollectionItems);
|
||||
public const string Expires = nameof(Expires);
|
||||
public const string Refresh = nameof(Refresh);
|
||||
public const string ExpirationWithoutGracePeriod = nameof(ExpirationWithoutGracePeriod);
|
||||
public const string Trial = nameof(Trial);
|
||||
}
|
||||
|
||||
public static class UserLicenseConstants
|
||||
{
|
||||
public const string LicenseType = nameof(LicenseType);
|
||||
public const string LicenseKey = nameof(LicenseKey);
|
||||
public const string Id = nameof(Id);
|
||||
public const string Name = nameof(Name);
|
||||
public const string Email = nameof(Email);
|
||||
public const string Premium = nameof(Premium);
|
||||
public const string MaxStorageGb = nameof(MaxStorageGb);
|
||||
public const string Issued = nameof(Issued);
|
||||
public const string Expires = nameof(Expires);
|
||||
public const string Refresh = nameof(Refresh);
|
||||
public const string Trial = nameof(Trial);
|
||||
}
|
@ -21,52 +21,48 @@ public class OrganizationLicenseClaimsFactory : ILicenseClaimsFactory<Organizati
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new(nameof(OrganizationLicense.LicenseType), LicenseType.Organization.ToString()),
|
||||
new(nameof(OrganizationLicense.InstallationId), licenseContext.InstallationId.ToString()),
|
||||
new(nameof(OrganizationLicense.Id), entity.Id.ToString()),
|
||||
new(nameof(OrganizationLicense.Name), entity.Name),
|
||||
new(nameof(OrganizationLicense.BillingEmail), entity.BillingEmail),
|
||||
new(nameof(OrganizationLicense.Enabled), entity.Enabled.ToString()),
|
||||
new(nameof(OrganizationLicense.Plan), entity.Plan),
|
||||
new(nameof(OrganizationLicense.PlanType), entity.PlanType.ToString()),
|
||||
new(nameof(OrganizationLicense.Seats), entity.Seats.ToString()),
|
||||
new(nameof(OrganizationLicense.MaxCollections), entity.MaxCollections.ToString()),
|
||||
new(nameof(OrganizationLicense.UsePolicies), entity.UsePolicies.ToString()),
|
||||
new(nameof(OrganizationLicense.UseSso), entity.UseSso.ToString()),
|
||||
new(nameof(OrganizationLicense.UseKeyConnector), entity.UseKeyConnector.ToString()),
|
||||
new(nameof(OrganizationLicense.UseScim), entity.UseScim.ToString()),
|
||||
new(nameof(OrganizationLicense.UseGroups), entity.UseGroups.ToString()),
|
||||
new(nameof(OrganizationLicense.UseEvents), entity.UseEvents.ToString()),
|
||||
new(nameof(OrganizationLicense.UseDirectory), entity.UseDirectory.ToString()),
|
||||
new(nameof(OrganizationLicense.UseTotp), entity.UseTotp.ToString()),
|
||||
new(nameof(OrganizationLicense.Use2fa), entity.Use2fa.ToString()),
|
||||
new(nameof(OrganizationLicense.UseApi), entity.UseApi.ToString()),
|
||||
new(nameof(OrganizationLicense.UseResetPassword), entity.UseResetPassword.ToString()),
|
||||
new(nameof(OrganizationLicense.MaxStorageGb), entity.MaxStorageGb.ToString()),
|
||||
new(nameof(OrganizationLicense.SelfHost), entity.SelfHost.ToString()),
|
||||
new(nameof(OrganizationLicense.UsersGetPremium), entity.UsersGetPremium.ToString()),
|
||||
new(nameof(OrganizationLicense.UseCustomPermissions), entity.UseCustomPermissions.ToString()),
|
||||
new(nameof(OrganizationLicense.Issued), DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicense.UsePasswordManager), entity.UsePasswordManager.ToString()),
|
||||
new(nameof(OrganizationLicense.UseSecretsManager), entity.UseSecretsManager.ToString()),
|
||||
new(nameof(OrganizationLicense.SmSeats), entity.SmSeats.ToString()),
|
||||
new(nameof(OrganizationLicense.SmServiceAccounts), entity.SmServiceAccounts.ToString()),
|
||||
new(nameof(OrganizationLicense.LimitCollectionCreationDeletion), entity.LimitCollectionCreationDeletion.ToString()),
|
||||
new(nameof(OrganizationLicense.AllowAdminAccessToAllCollectionItems), entity.AllowAdminAccessToAllCollectionItems.ToString()),
|
||||
new(nameof(OrganizationLicense.Expires), expires.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicense.Refresh), refresh.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicense.ExpirationWithoutGracePeriod), expirationWithoutGracePeriod.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicense.Trial), trial.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.LicenseType), LicenseType.Organization.ToString()),
|
||||
new Claim(nameof(OrganizationLicenseConstants.LicenseKey), entity.LicenseKey),
|
||||
new(nameof(OrganizationLicenseConstants.InstallationId), licenseContext.InstallationId.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Id), entity.Id.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Name), entity.Name),
|
||||
new(nameof(OrganizationLicenseConstants.BillingEmail), entity.BillingEmail),
|
||||
new(nameof(OrganizationLicenseConstants.Enabled), entity.Enabled.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Plan), entity.Plan),
|
||||
new(nameof(OrganizationLicenseConstants.PlanType), entity.PlanType.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Seats), entity.Seats.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.MaxCollections), entity.MaxCollections.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UsePolicies), entity.UsePolicies.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseSso), entity.UseSso.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseKeyConnector), entity.UseKeyConnector.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseScim), entity.UseScim.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseGroups), entity.UseGroups.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseEvents), entity.UseEvents.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseDirectory), entity.UseDirectory.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseTotp), entity.UseTotp.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Use2fa), entity.Use2fa.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseApi), entity.UseApi.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseResetPassword), entity.UseResetPassword.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.MaxStorageGb), entity.MaxStorageGb.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.SelfHost), entity.SelfHost.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UsersGetPremium), entity.UsersGetPremium.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseCustomPermissions), entity.UseCustomPermissions.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Issued), DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicenseConstants.UsePasswordManager), entity.UsePasswordManager.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.UseSecretsManager), entity.UseSecretsManager.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.SmSeats), entity.SmSeats.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.SmServiceAccounts), entity.SmServiceAccounts.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.LimitCollectionCreationDeletion), entity.LimitCollectionCreationDeletion.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.AllowAdminAccessToAllCollectionItems), entity.AllowAdminAccessToAllCollectionItems.ToString()),
|
||||
new(nameof(OrganizationLicenseConstants.Expires), expires.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicenseConstants.Refresh), refresh.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicenseConstants.ExpirationWithoutGracePeriod), expirationWithoutGracePeriod.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(OrganizationLicenseConstants.Trial), trial.ToString()),
|
||||
};
|
||||
|
||||
if (entity.LicenseKey is not null)
|
||||
{
|
||||
claims.Add(new Claim(nameof(OrganizationLicense.LicenseKey), entity.LicenseKey));
|
||||
}
|
||||
|
||||
if (entity.BusinessName is not null)
|
||||
{
|
||||
claims.Add(new Claim(nameof(OrganizationLicense.BusinessName), entity.BusinessName));
|
||||
claims.Add(new Claim(nameof(OrganizationLicenseConstants.BusinessName), entity.BusinessName));
|
||||
}
|
||||
|
||||
return Task.FromResult(claims);
|
||||
|
@ -3,7 +3,6 @@ using System.Security.Claims;
|
||||
using Bit.Core.Billing.Licenses.Models;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Business;
|
||||
|
||||
namespace Bit.Core.Billing.Licenses.Services.Implementations;
|
||||
|
||||
@ -20,17 +19,17 @@ public class UserLicenseClaimsFactory : ILicenseClaimsFactory<User>
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new(nameof(UserLicense.LicenseType), LicenseType.User.ToString()),
|
||||
new(nameof(UserLicense.LicenseKey), entity.LicenseKey),
|
||||
new(nameof(UserLicense.Id), entity.Id.ToString()),
|
||||
new(nameof(UserLicense.Name), entity.Name),
|
||||
new(nameof(UserLicense.Email), entity.Email),
|
||||
new(nameof(UserLicense.Premium), entity.Premium.ToString()),
|
||||
new(nameof(UserLicense.MaxStorageGb), entity.MaxStorageGb.ToString()),
|
||||
new(nameof(UserLicense.Issued), DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(UserLicense.Expires), expires.ToString()),
|
||||
new(nameof(UserLicense.Refresh), refresh.ToString()),
|
||||
new(nameof(UserLicense.Trial), trial.ToString()),
|
||||
new(nameof(UserLicenseConstants.LicenseType), LicenseType.User.ToString()),
|
||||
new(nameof(UserLicenseConstants.LicenseKey), entity.LicenseKey),
|
||||
new(nameof(UserLicenseConstants.Id), entity.Id.ToString()),
|
||||
new(nameof(UserLicenseConstants.Name), entity.Name),
|
||||
new(nameof(UserLicenseConstants.Email), entity.Email),
|
||||
new(nameof(UserLicenseConstants.Premium), entity.Premium.ToString()),
|
||||
new(nameof(UserLicenseConstants.MaxStorageGb), entity.MaxStorageGb.ToString()),
|
||||
new(nameof(UserLicenseConstants.Issued), DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
|
||||
new(nameof(UserLicenseConstants.Expires), expires.ToString()),
|
||||
new(nameof(UserLicenseConstants.Refresh), refresh.ToString()),
|
||||
new(nameof(UserLicenseConstants.Trial), trial.ToString()),
|
||||
};
|
||||
|
||||
return Task.FromResult(claims);
|
||||
|
Loading…
Reference in New Issue
Block a user