-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summarize needed license on shutdown
- Loading branch information
1 parent
d685b97
commit 444a2ac
Showing
22 changed files
with
305 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Duende.IdentityServer.Licensing.v2; | ||
|
||
/// <summary> | ||
/// Tracks the usage of the license. | ||
/// </summary> | ||
public interface ILicenseUsageService | ||
{ | ||
/// <summary> | ||
/// Gets the licensed features that have been used. | ||
/// </summary> | ||
HashSet<LicenseFeature> UsedFeatures { get; } | ||
/// <summary> | ||
/// Indicates that a licensed feature has been used. | ||
/// </summary> | ||
void UseFeature(LicenseFeature feature); | ||
|
||
/// <summary> | ||
/// Gets the client ids that have been used. | ||
/// </summary> | ||
HashSet<string> UsedClients { get; } | ||
/// <summary> | ||
/// Indicates that a client id has been used. | ||
/// </summary> | ||
void UseClient(string clientId); | ||
|
||
|
||
/// <summary> | ||
/// Gets the issuers that have been used. | ||
/// </summary> | ||
HashSet<string> UsedIssuers { get; } | ||
/// <summary> | ||
/// Indicates that an issuer has been used. | ||
/// </summary> | ||
void UseIssuer(string issuer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Duende.IdentityServer.Licensing.v2; | ||
|
||
internal class LicenseUsageService : ILicenseUsageService | ||
{ | ||
private void EnsureAdded<T>(ref HashSet<T> hashSet, object lockObject, T key) | ||
{ | ||
// Lock free test first. | ||
if (!hashSet.Contains(key)) | ||
{ | ||
lock (lockObject) | ||
{ | ||
// Check again after lock, to quit early if another thread | ||
// already did the job. | ||
if (!hashSet.Contains(key)) | ||
{ | ||
// The HashSet is not thread safe. And we don't want to lock for every single | ||
// time we use it. Our access pattern should be a lot of reads and a few writes | ||
// so better to create a new copy every time we need to add a value. | ||
var newSet = new HashSet<T>(hashSet) | ||
{ | ||
key | ||
}; | ||
|
||
// Reference assignment is atomic so non-locked readers will handle this. | ||
hashSet = newSet; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Features | ||
private readonly object _featureLock = new(); | ||
private HashSet<LicenseFeature> _features = new(); | ||
public HashSet<LicenseFeature> UsedFeatures => _features; | ||
public void UseFeature(LicenseFeature feature) => EnsureAdded(ref _features, _featureLock, feature); | ||
|
||
// Clients | ||
private readonly object _clientLock = new(); | ||
private HashSet<string> _clients = new(); | ||
public HashSet<string> UsedClients => _clients; | ||
public void UseClient(string clientId) => EnsureAdded(ref _clients, _clientLock, clientId); | ||
|
||
// Issuers | ||
private readonly object _issuerLock = new(); | ||
private HashSet<string> _issuers = new(); | ||
public HashSet<string> UsedIssuers => _issuers; | ||
public void UseIssuer(string issuer) => EnsureAdded(ref _issuers, _issuerLock, issuer); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/IdentityServer/Licensing/v2/LicenseUsageServiceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Duende.IdentityServer.Licensing.v2; | ||
|
||
internal static class LicenseUsageServiceExtensions | ||
{ | ||
internal static void UseResourceIndicator(this ILicenseUsageService licenseUsage, string? resourceIndicator) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(resourceIndicator)) | ||
{ | ||
licenseUsage.UseFeature(LicenseFeature.ResourceIsolation); | ||
} | ||
} | ||
|
||
internal static void UseResourceIndicators(this ILicenseUsageService licenseUsage, IEnumerable<string> resourceIndicators) | ||
{ | ||
if (resourceIndicators.Any()) | ||
{ | ||
licenseUsage.UseFeature(LicenseFeature.ResourceIsolation); | ||
} | ||
} | ||
} |
Oops, something went wrong.