feat(IAsymmetricTokenDescriptor): Methode Validator.get mit Lazy Loading hinzugefügt.

This commit is contained in:
Developer 02 2025-01-10 23:32:53 +01:00
parent 39091ff5cf
commit b90a52412c
5 changed files with 27 additions and 6 deletions

View File

@ -7,6 +7,8 @@ namespace DigitalData.Core.Abstractions.Security
/// </summary> /// </summary>
public interface IAsymmetricTokenDescriptor : IAsymmetricPrivateKey, IUniqueSecurityContext public interface IAsymmetricTokenDescriptor : IAsymmetricPrivateKey, IUniqueSecurityContext
{ {
IAsymmetricTokenValidator Validator { get; }
string? ApiRoute { get; } string? ApiRoute { get; }
#region SecurityTokenDescriptor Map #region SecurityTokenDescriptor Map

View File

@ -0,0 +1,6 @@
namespace DigitalData.Core.Abstractions.Security
{
public interface IAsymmetricTokenValidator : IAsymmetricPublicKey
{
}
}

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions.Security; using DigitalData.Core.Abstractions.Security;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace DigitalData.Core.Security.RSAKey namespace DigitalData.Core.Security.RSAKey
@ -24,16 +23,16 @@ namespace DigitalData.Core.Security.RSAKey
public bool IsEncrypted { get; init; } public bool IsEncrypted { get; init; }
private readonly Lazy<IAsymmetricPublicKey> _lazyPublicKey; protected TPublicKey CreatePublicKey<TPublicKey>() where TPublicKey : RSAPublicKey, new()
=> new() { Content = RSA.ExportRSAPublicKeyPem() };
private readonly Lazy<RSAPublicKey> _lazyPublicKey;
public IAsymmetricPublicKey PublicKey => _lazyPublicKey.Value; public IAsymmetricPublicKey PublicKey => _lazyPublicKey.Value;
public RSAPrivateKey() public RSAPrivateKey()
{ {
_lazyPublicKey = new(() => new RSAPublicKey() _lazyPublicKey = new(CreatePublicKey<RSAPublicKey>);
{
Content = RSA.ExportRSAPublicKeyPem()
});
} }
internal void SetPem(string pem) internal void SetPem(string pem)

View File

@ -10,6 +10,10 @@ namespace DigitalData.Core.Security.RSAKey
{ {
public string? ApiRoute { get; init; } public string? ApiRoute { get; init; }
private readonly Lazy<RSATokenValidator> _lazyTokenValidator;
public IAsymmetricTokenValidator Validator => _lazyTokenValidator.Value;
#region SecurityTokenDescriptor Map #region SecurityTokenDescriptor Map
/// <summary> /// <summary>
/// Gets or sets the value of the 'audience' claim. /// Gets or sets the value of the 'audience' claim.
@ -102,6 +106,8 @@ namespace DigitalData.Core.Security.RSAKey
public RSATokenDescriptor() public RSATokenDescriptor()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{ {
_lazyTokenValidator = new(CreatePublicKey<RSATokenValidator>);
_lazyRsaSecurityKey = new(() => new RsaSecurityKey(RSA)); _lazyRsaSecurityKey = new(() => new RsaSecurityKey(RSA));
_lazySigningCredentials = new(() => SigningDigest is null _lazySigningCredentials = new(() => SigningDigest is null

View File

@ -0,0 +1,8 @@
using DigitalData.Core.Abstractions.Security;
namespace DigitalData.Core.Security.RSAKey
{
public class RSATokenValidator: RSAPublicKey, IAsymmetricTokenValidator
{
}
}