comment uncomplete authorization services ...

This commit is contained in:
2026-11-20 14:11:48 +03:30
parent c8669bf493
commit bc5efed076
4 changed files with 414 additions and 414 deletions
+144 -144
View File
@@ -1,156 +1,156 @@
using System.Linq;
using System.Threading;
using xCommons.Extensions;
using xIdentityModels.Dtos;
using xExceptions.Constants;
using System.Threading.Tasks;
using xIdentityService.Interfaces;
// using System.Linq;
// using System.Threading;
// using xCommons.Extensions;
// using xIdentityModels.Dtos;
// using xExceptions.Constants;
// using System.Threading.Tasks;
// using xIdentityService.Interfaces;
//
// TODO: Remove this to xIds ...
namespace xIdentityService.Providers
{
public partial class XAuthorizationProvider : IXAuthorizationProvider
{
//
private readonly IXRoleProvider roles;
private readonly IXScopeProvider scopes;
private readonly IXPolicyProvider policies;
private readonly IXRoleSyncService roleSync;
private readonly IXAuthorizationCache cache;
private readonly IXScopeSyncService scopeSync;
private readonly IXRoleHierarchyResolver resolver;
// private readonly IXEventServiceProvider eventService;
// //
// // TODO: Remove this to xIds ...
// namespace xIdentityService.Providers
// {
// public partial class XAuthorizationProvider : IXAuthorizationProvider
// {
// //
// private readonly IXRoleProvider roles;
// private readonly IXScopeProvider scopes;
// private readonly IXPolicyProvider policies;
// private readonly IXRoleSyncService roleSync;
// private readonly IXAuthorizationCache cache;
// private readonly IXScopeSyncService scopeSync;
// private readonly IXRoleHierarchyResolver resolver;
// // private readonly IXEventServiceProvider eventService;
public XAuthorizationProvider(
IXRoleProvider roles,
IXScopeProvider scopes,
IXPolicyProvider policies,
IXRoleSyncService roleSync,
IXAuthorizationCache cache,
IXScopeSyncService scopeSync,
IXRoleHierarchyResolver resolver
)
{
//
this.roles = roles;
this.cache = cache;
this.scopes = scopes;
this.policies = policies;
this.roleSync = roleSync;
this.resolver = resolver;
this.scopeSync = scopeSync;
}
// public XAuthorizationProvider(
// IXRoleProvider roles,
// IXScopeProvider scopes,
// IXPolicyProvider policies,
// IXRoleSyncService roleSync,
// IXAuthorizationCache cache,
// IXScopeSyncService scopeSync,
// IXRoleHierarchyResolver resolver
// )
// {
// //
// this.roles = roles;
// this.cache = cache;
// this.scopes = scopes;
// this.policies = policies;
// this.roleSync = roleSync;
// this.resolver = resolver;
// this.scopeSync = scopeSync;
// }
//
#region Commons ...
/// <summary>
/// Clear Local Cache and Notify other Instances ...
/// </summary>
public async Task InvalidateAsync(string policyName = null)
{
//
if (policyName.IsNullOrEmpty())
{
cache.Clear();
}
else
{
cache.RemovePolicy(policyName);
}
}
#endregion
// //
// #region Commons ...
// /// <summary>
// /// Clear Local Cache and Notify other Instances ...
// /// </summary>
// public async Task InvalidateAsync(string policyName = null)
// {
// //
// if (policyName.IsNullOrEmpty())
// {
// cache.Clear();
// }
// else
// {
// cache.RemovePolicy(policyName);
// }
// }
// #endregion
//
#region Private ...
private async Task<XPolicyDefinitionDto> FindPolicyOrThrowAsync(
string name,
CancellationToken cancellationToken
)
{
//
if (name.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
// //
// #region Private ...
// private async Task<XPolicyDefinitionDto> FindPolicyOrThrowAsync(
// string name,
// CancellationToken cancellationToken
// )
// {
// //
// if (name.IsNullOrEmpty())
// {
// XException.InvalidArgs.Throw();
// }
//
var normalized = name.ToNormalString();
var result = await policies.FindOneAsync(
predicate: p => p.Name.ToLower() == normalized,
cancellationToken: cancellationToken
);
if (result.IsNull())
{
XException.NotFound.Throw();
}
// //
// var normalized = name.ToNormalString();
// var result = await policies.FindOneAsync(
// predicate: p => p.Name.ToLower() == normalized,
// cancellationToken: cancellationToken
// );
// if (result.IsNull())
// {
// XException.NotFound.Throw();
// }
//
return result;
}
// //
// return result;
// }
// private async Task ValidateReferencesAsync(
// XPolicyDefinitionDto item,
// CancellationToken cancellationToken
// )
// {
// //
// // Referenced Roles must exist ...
// if (item.RequiredRoles.HasChild())
// {
// var all = (await roles.GetAllAsync(cancellationToken: cancellationToken))
// .Select(r => r.Name.ToNormalString()).ToList();
// if (item.RequiredRoles.Any(r => !all.Contains(r.ToNormalString())))
// {
// XException.NotFound.Throw();
// }
// }
// // private async Task ValidateReferencesAsync(
// // XPolicyDefinitionDto item,
// // CancellationToken cancellationToken
// // )
// // {
// // //
// // // Referenced Roles must exist ...
// // if (item.RequiredRoles.HasChild())
// // {
// // var all = (await roles.GetAllAsync(cancellationToken: cancellationToken))
// // .Select(r => r.Name.ToNormalString()).ToList();
// // if (item.RequiredRoles.Any(r => !all.Contains(r.ToNormalString())))
// // {
// // XException.NotFound.Throw();
// // }
// // }
// //
// // Referenced Scopes must exist ...
// if (item.RequiredScopes.HasChild())
// {
// var all = (await scopes.GetAllAsync(cancellationToken: cancellationToken))
// .Select(s => s.Name.ToNormalString()).ToList();
// if (item.RequiredScopes.Any(s => !all.Contains(s.ToNormalString())))
// {
// XException.NotFound.Throw();
// }
// }
// }
// // //
// // // Referenced Scopes must exist ...
// // if (item.RequiredScopes.HasChild())
// // {
// // var all = (await scopes.GetAllAsync(cancellationToken: cancellationToken))
// // .Select(s => s.Name.ToNormalString()).ToList();
// // if (item.RequiredScopes.Any(s => !all.Contains(s.ToNormalString())))
// // {
// // XException.NotFound.Throw();
// // }
// // }
// // }
// private async Task<XPolicyDefinitionDto> ToDtoWithEffectiveRolesAsync(
// XPolicyDefinition entity,
// CancellationToken cancellationToken
// )
// {
// //
// var dto = entity.ToDto();
// dto.EffectiveRoles = (await resolver.ResolveEffectiveRolesAsync(
// explicitRoles: entity.RequiredRoles.ToCsvList(),
// minRoleWeight: entity.MinRoleWeight,
// cancellationToken: cancellationToken
// )).ToList();
// // private async Task<XPolicyDefinitionDto> ToDtoWithEffectiveRolesAsync(
// // XPolicyDefinition entity,
// // CancellationToken cancellationToken
// // )
// // {
// // //
// // var dto = entity.ToDto();
// // dto.EffectiveRoles = (await resolver.ResolveEffectiveRolesAsync(
// // explicitRoles: entity.RequiredRoles.ToCsvList(),
// // minRoleWeight: entity.MinRoleWeight,
// // cancellationToken: cancellationToken
// // )).ToList();
// //
// return dto;
// }
// // //
// // return dto;
// // }
// private async Task<XPolicyDefinitionDto> ToDtoWithEffectiveRolesAsync(
// XPolicyDefinitionDto item,
// CancellationToken cancellationToken = default
// )
// {
// //
// item.EffectiveRoles = (await resolver.ResolveEffectiveRolesAsync(
// minRoleWeight: item.MinRoleWeight,
// cancellationToken: cancellationToken,
// explicitRoles: item.RequiredRoles.ParseListString<string>()
// )).ToList();
// // private async Task<XPolicyDefinitionDto> ToDtoWithEffectiveRolesAsync(
// // XPolicyDefinitionDto item,
// // CancellationToken cancellationToken = default
// // )
// // {
// // //
// // item.EffectiveRoles = (await resolver.ResolveEffectiveRolesAsync(
// // minRoleWeight: item.MinRoleWeight,
// // cancellationToken: cancellationToken,
// // explicitRoles: item.RequiredRoles.ParseListString<string>()
// // )).ToList();
// //
// return item;
// }
#endregion
}
}
// // //
// // return item;
// // }
// #endregion
// }
// }