using System; using xCommons.Extensions; using xExceptions.Constants; using xIdentityService.Interfaces; using Microsoft.Extensions.Logging; using System.Collections.Concurrent; using Microsoft.AspNetCore.Authorization; namespace xIdentityService.Models { public class XAuthorizationCache : IXAuthorizationCache { private readonly ILogger logger; private readonly ConcurrentDictionary policies; public XAuthorizationCache( ILogger logger ) { // this.logger = logger; policies = new ConcurrentDictionary(StringComparer.Ordinal); } public void Clear() { policies.Clear(); } public void SetPolicy( string name, AuthorizationPolicy policy ) { // if (name.IsNullOrEmpty() || policy.IsNullOrDefault()) { XException.InvalidArgs.Throw(); } // policies.AddOrUpdate(name, policy, (_, __) => policy); } public bool TryGetPolicy( string name, out AuthorizationPolicy policy ) { // if (name.IsNullOrEmpty()) { // policy = null!; return false; } // var result = policies.TryGetValue(name, out policy!); return result; } public void RemovePolicy(string name) { // if (name.IsNullOrEmpty()) { return; } // if (policies.TryRemove(name, out _)) { } } } }