This commit is contained in:
2026-11-20 20:23:01 +03:30
parent bc5efed076
commit 002882300d
11 changed files with 664 additions and 450 deletions
+75 -75
View File
@@ -1,86 +1,86 @@
// using System.Threading;
// using xCommons.Extensions;
// using xIdentityModels.Dtos;
// using xExceptions.Constants;
// using System.Threading.Tasks;
// using xIdentityModels.Models;
using System.Threading;
using xCommons.Extensions;
using xIdentityModels.Dtos;
using xExceptions.Constants;
using System.Threading.Tasks;
using xIdentityModels.Models;
// namespace xIdentityService.Providers
// {
// public partial class XAuthorizationProvider
// {
// //
// #region Policy ...
// public async Task<XPolicyDefinitionDto> AddPolicyAsync(
// XPolicyDefinitionDto item,
// XUserClaimsInfoDto userInfo,
// CancellationToken cancellationToken = default
// )
// {
// //
// // Validate ...
// if (item.IsNull() || item.Name.IsNullOrEmpty())
// {
// XException.InvalidArgs.Throw();
// }
namespace xIdentityService.Providers
{
public partial class XAuthorizationProvider
{
//
#region Policy ...
public async Task<XPolicyDefinitionDto> AddPolicyAsync(
XPolicyDefinitionDto item,
XUserClaimsInfoDto userInfo,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (item.IsNull() || item.Name.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
// //
// var normalized = item.Name.ToNormalString();
// var exists = await policies.FindOneAsync(
// predicate: p => p.Name.ToLower() == normalized,
// cancellationToken: cancellationToken
// );
// if (!exists.IsNull())
// {
// XException.Duplicate.Throw();
// }
//
var normalized = item.Name.ToNormalString();
var exists = await policies.FindOneAsync(
predicate: p => p.Name.ToLower() == normalized,
cancellationToken: cancellationToken
);
if (!exists.IsNull())
{
XException.Duplicate.Throw();
}
// //
// await ValidateReferencesAsync(item, cancellationToken);
//
await ValidateReferencesAsync(item, cancellationToken);
// //
// item.IsSystem = false;
//
item.IsSystem = false;
// //
// var result = await policies.AddAsync(
// item: item,
// cancellationToken: cancellationToken
// );
//
var result = await policies.AddAsync(
item: item,
cancellationToken: cancellationToken
);
// //
// await InvalidateAsync(result.Name);
//
await InvalidateAsync(result.Name);
// //
// return await ToDtoWithEffectiveRolesAsync(result, cancellationToken);
// }
//
return await ToDtoWithEffectiveRolesAsync(result, cancellationToken);
}
// public async Task<bool> RemovePolicyAsync(
// string name,
// XUserClaimsInfoDto userInfo,
// CancellationToken cancellationToken = default
// )
// {
// //
// var entity = await FindPolicyOrThrowAsync(name, cancellationToken);
// if (entity.IsSystem)
// {
// XException.NotAllowed.Throw();
// }
public async Task<bool> RemovePolicyAsync(
string name,
XUserClaimsInfoDto userInfo,
CancellationToken cancellationToken = default
)
{
//
var entity = await FindPolicyOrThrowAsync(name, cancellationToken);
if (entity.IsSystem)
{
XException.NotAllowed.Throw();
}
// //
// await policies.RemoveAsync(
// id: entity.Id,
// cancellationToken: cancellationToken
// );
//
await policies.RemoveAsync(
id: entity.Id,
cancellationToken: cancellationToken
);
// //
// await InvalidateAsync(entity.Name);
// return true;
// }
// #endregion
//
await InvalidateAsync(entity.Name);
return true;
}
#endregion
// //
// #region Private ...
// #endregion
// }
// }
//
#region Private ...
#endregion
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace xIdentityService.Providers
{
public partial class XAuthorizationProvider
{
//
#region Role ...
#endregion
}
}
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace xIdentityService.Providers
{
public partial class XAuthorizationProvider
{
}
}