last ...
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xExceptions.Constants;
|
|
||||||
using xIdentityModels.Dtos;
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
|
|
||||||
namespace xIdentityService.Providers
|
namespace xIdentityService.Providers
|
||||||
@@ -77,85 +77,10 @@ namespace xIdentityService.Providers
|
|||||||
await InvalidateAsync(entity.Name);
|
await InvalidateAsync(entity.Name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPolicyAsync / QueryPoliciesAsync / UpdatePolicyAsync follow same style ...
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Private ...
|
#region Private ...
|
||||||
private async Task<XPolicyDefinition> FindPolicyOrThrowAsync(
|
|
||||||
string name,
|
|
||||||
CancellationToken cancellationToken
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (name.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var normalized = name.ToNormalString();
|
|
||||||
var result = await policies.Repository.FindOneAsync(
|
|
||||||
predicate: p => p.Name.ToLower() == normalized,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
if (result.IsNull())
|
|
||||||
{
|
|
||||||
XException.NotFound.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ValidateReferencesAsync(
|
|
||||||
XPolicyDefinitionDto item,
|
|
||||||
CancellationToken cancellationToken
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Referenced Roles must exist ...
|
|
||||||
if (item.RequiredRoles.HasChild())
|
|
||||||
{
|
|
||||||
var all = (await roles.Repository.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.Repository.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();
|
|
||||||
|
|
||||||
//
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using xIdentityModels.Dtos;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Remove this to xIds ...
|
// TODO: Remove this to xIds ...
|
||||||
@@ -62,22 +63,94 @@ namespace xIdentityService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Private ...
|
#region Private ...
|
||||||
//
|
private async Task<XPolicyDefinitionDto> FindPolicyOrThrowAsync(
|
||||||
private async Task<XPolicyDefinitionDto> ToDtoWithEffectiveRolesAsync(
|
string name,
|
||||||
XPolicyDefinitionDto item,
|
CancellationToken cancellationToken
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
item.EffectiveRoles = (await resolver.ResolveEffectiveRolesAsync(
|
if (name.IsNullOrEmpty())
|
||||||
minRoleWeight: item.MinRoleWeight,
|
{
|
||||||
cancellationToken: cancellationToken,
|
XException.InvalidArgs.Throw();
|
||||||
explicitRoles: item.RequiredRoles.ParseListString<string>()
|
}
|
||||||
)).ToList();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return item;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user