From d685b970aaef6ef293f58ef7add9595a8fa147ec Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Tue, 3 Dec 2024 14:47:27 -0600 Subject: [PATCH] Embed feature mask value into LicenseFeatures --- .../Licensing/v2/FeatureManager.cs | 5 ++-- src/IdentityServer/Licensing/v2/License.cs | 6 ++--- .../Licensing/v2/LicenseFeature.cs | 27 ++++++++----------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/IdentityServer/Licensing/v2/FeatureManager.cs b/src/IdentityServer/Licensing/v2/FeatureManager.cs index 9ea7fb8fe..7594f4743 100644 --- a/src/IdentityServer/Licensing/v2/FeatureManager.cs +++ b/src/IdentityServer/Licensing/v2/FeatureManager.cs @@ -28,7 +28,7 @@ public IEnumerable UsedFeatures() { foreach (LicenseFeature feature in Enum.GetValues()) { - if ((_usedFeatures & feature.ToFeatureMask()) != 0) + if ((_usedFeatures & (ulong) feature) != 0) { yield return feature; } @@ -52,8 +52,7 @@ public void UseFeature(LicenseFeature feature) } } } - // TODO - refactor the feature so that its value is already the feature mask - var featureMask = feature.ToFeatureMask(); + var featureMask = (ulong) feature; Interlocked.Or(ref _usedFeatures, featureMask); } diff --git a/src/IdentityServer/Licensing/v2/License.cs b/src/IdentityServer/Licensing/v2/License.cs index e606180c2..07802b2d8 100644 --- a/src/IdentityServer/Licensing/v2/License.cs +++ b/src/IdentityServer/Licensing/v2/License.cs @@ -121,7 +121,7 @@ internal License(ClaimsPrincipal claims) /// public bool IsEnabled(LicenseFeature feature) { - return !IsConfigured || (AllowedFeatureMask & feature.ToFeatureMask()) != 0; + return !IsConfigured || (AllowedFeatureMask & (ulong) feature) != 0; } @@ -136,7 +136,7 @@ private ulong AllowedFeatureMask foreach (var featureClaim in Features) { var feature = ToFeatureEnum(featureClaim); - features |= feature.ToFeatureMask(); + features |= (ulong) feature; } _allowedFeatureMask = features; @@ -202,7 +202,7 @@ private ulong FeatureMaskForFeatures(params LicenseFeature[] licenseFeatures) var result = 0UL; foreach(var feature in licenseFeatures) { - result |= feature.ToFeatureMask(); + result |= (ulong) feature; } return result; } diff --git a/src/IdentityServer/Licensing/v2/LicenseFeature.cs b/src/IdentityServer/Licensing/v2/LicenseFeature.cs index 491da6867..5ad734161 100644 --- a/src/IdentityServer/Licensing/v2/LicenseFeature.cs +++ b/src/IdentityServer/Licensing/v2/LicenseFeature.cs @@ -9,70 +9,65 @@ namespace Duende.IdentityServer.Licensing.v2; /// /// The features of IdentityServer that can be enabled or disabled through the License. /// -public enum LicenseFeature +public enum LicenseFeature : ulong { /// /// Automatic Key Management /// [Description("key_management")] - KeyManagement, + KeyManagement = 1, /// /// Pushed Authorization Requests /// [Description("par")] - PAR, + PAR = 2, /// /// Resource Isolation /// [Description("resource_isolation")] - ResourceIsolation, + ResourceIsolation = 4, /// /// Dyanmic External Providers /// [Description("dynamic_providers")] - DynamicProviders, + DynamicProviders = 8, /// /// Client Initiated Backchannel Authorization /// [Description("ciba")] - CIBA, + CIBA = 16, /// /// Server-Side Sessions /// [Description("server_side_sessions")] - ServerSideSessions, + ServerSideSessions = 32, /// /// Demonstrating Proof of Possesion /// [Description("dpop")] - DPoP, + DPoP = 64, /// /// Configuration API /// [Description("config_api")] - DCR, + DCR = 128, /// /// ISV (same as Redistribution) /// [Description("isv")] - ISV, + ISV = 256, /// /// Dedistribution /// [Description("redistribution")] - Redistribution, + Redistribution = 512, } - -internal static class LicenseFeatureExtensions -{ - internal static ulong ToFeatureMask(this LicenseFeature feature) => 1UL << (int) feature; -} \ No newline at end of file