last ...
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
namespace xIdentityService.Constants
|
||||||
|
{
|
||||||
|
public struct XIdentityServiceConstants
|
||||||
|
{
|
||||||
|
public const string PolicyCacheKeyPrefix = "XAuth:Cache";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace xIdentityService.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXAuthorizationCache
|
||||||
|
{
|
||||||
|
void Clear();
|
||||||
|
void RemovePolicy(string name);
|
||||||
|
void SetPolicy(string name, AuthorizationPolicy policy);
|
||||||
|
bool TryGetPolicy(string name, out AuthorizationPolicy policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xIdentityService.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXPolicyProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Readers ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve whole items as queryable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asNoTracking">a flag for Tracking behaviour</param>
|
||||||
|
/// <param name="predicate">an Expression for Filter Items ...</param>
|
||||||
|
/// <param name="orderBuilder">an Order Builder expression for Ordering Query ...</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IQueryable<XPolicyDefinition> AsQueryable(
|
||||||
|
bool asNoTracking = true,
|
||||||
|
Expression<Func<XPolicyDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XPolicyDefinition>, IOrderedQueryable<XPolicyDefinition>> orderBuilder = null
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> GetAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XPolicyDefinitionDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XPolicyDefinition>, IOrderedQueryable<XPolicyDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Entity by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> FindOneAsync(
|
||||||
|
Expression<Func<XPolicyDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Entities by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XPolicyDefinitionDto>> FindManyAsync(
|
||||||
|
Expression<Func<XPolicyDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XPolicyDefinition>, IOrderedQueryable<XPolicyDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities Pages by providing page size ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageSize"></param>
|
||||||
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> PagesCountAsync(
|
||||||
|
int pageSize,
|
||||||
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check an Entity exists or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsExistsAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Query ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XPolicyDefinitionDto>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<XPolicyDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XPolicyDefinition>, IOrderedQueryable<XPolicyDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Add/Update/Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> AddAsync(
|
||||||
|
XPolicyDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an Entity values ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> UpdateAsync(
|
||||||
|
int id,
|
||||||
|
XPolicyDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> RemoveAsync(
|
||||||
|
int id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Custom ...
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> EnrichAsync(
|
||||||
|
XPolicyDefinition source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XPolicyDefinitionDto> EnrichAsync(
|
||||||
|
XPolicyDefinitionDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XPolicyDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XPolicyDefinition> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XPolicyDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XPolicyDefinitionDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xIdentityService.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXRoleProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Readers ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve whole items as queryable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asNoTracking">a flag for Tracking behaviour</param>
|
||||||
|
/// <param name="predicate">an Expression for Filter Items ...</param>
|
||||||
|
/// <param name="orderBuilder">an Order Builder expression for Ordering Query ...</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IQueryable<XRoleDefinition> AsQueryable(
|
||||||
|
bool asNoTracking = true,
|
||||||
|
Expression<Func<XRoleDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XRoleDefinition>, IOrderedQueryable<XRoleDefinition>> orderBuilder = null
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> GetAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XRoleDefinitionDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XRoleDefinition>, IOrderedQueryable<XRoleDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Entity by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> FindOneAsync(
|
||||||
|
Expression<Func<XRoleDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Entities by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XRoleDefinitionDto>> FindManyAsync(
|
||||||
|
Expression<Func<XRoleDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XRoleDefinition>, IOrderedQueryable<XRoleDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities Pages by providing page size ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageSize"></param>
|
||||||
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> PagesCountAsync(
|
||||||
|
int pageSize,
|
||||||
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check an Entity exists or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsExistsAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Query ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XRoleDefinitionDto>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<XRoleDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XRoleDefinition>, IOrderedQueryable<XRoleDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Add/Update/Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> AddAsync(
|
||||||
|
XRoleDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an Entity values ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> UpdateAsync(
|
||||||
|
int id,
|
||||||
|
XRoleDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> RemoveAsync(
|
||||||
|
int id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Custom ...
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> EnrichAsync(
|
||||||
|
XRoleDefinition source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XRoleDefinitionDto> EnrichAsync(
|
||||||
|
XRoleDefinitionDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XRoleDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XRoleDefinition> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XRoleDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XRoleDefinitionDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using xIdentityModels.Dtos;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xIdentityService.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXScopeProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Readers ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve whole items as queryable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asNoTracking">a flag for Tracking behaviour</param>
|
||||||
|
/// <param name="predicate">an Expression for Filter Items ...</param>
|
||||||
|
/// <param name="orderBuilder">an Order Builder expression for Ordering Query ...</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IQueryable<XScopeDefinition> AsQueryable(
|
||||||
|
bool asNoTracking = true,
|
||||||
|
Expression<Func<XScopeDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> GetAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XScopeDefinitionDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find an Entity by providing a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> FindOneAsync(
|
||||||
|
Expression<Func<XScopeDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// find a collection of Entities by proving a Conditional Expression ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XScopeDefinitionDto>> FindManyAsync(
|
||||||
|
Expression<Func<XScopeDefinition, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> CountAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// count all exists Entities Pages by providing page size ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageSize"></param>
|
||||||
|
/// <param name="totalItems"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> PagesCountAsync(
|
||||||
|
int pageSize,
|
||||||
|
int? totalItems = null,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check an Entity exists or not ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsExistsAsync(
|
||||||
|
int id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Query ...
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="orderBuilder"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XScopeDefinitionDto>> QueryAsync(
|
||||||
|
XQuery query,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Expression<Func<XScopeDefinition, bool>> predicate = null,
|
||||||
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Add/Update/Remove ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Entity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> AddAsync(
|
||||||
|
XScopeDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an Entity values ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> UpdateAsync(
|
||||||
|
int id,
|
||||||
|
XScopeDefinitionDto item,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove an Entity by it's Id ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="softDelete"></param>
|
||||||
|
/// <param name="saveChanges"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> RemoveAsync(
|
||||||
|
int id,
|
||||||
|
bool softDelete = true,
|
||||||
|
bool saveChanges = true,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Custom ...
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> EnrichAsync(
|
||||||
|
XScopeDefinition source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XScopeDefinitionDto> EnrichAsync(
|
||||||
|
XScopeDefinitionDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XScopeDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XScopeDefinition> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich a Collection of Items(s) ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XScopeDefinitionDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XScopeDefinitionDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xIdentityService.Constants;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
|
||||||
|
namespace xIdentityService.Providers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Thread-safe local cache; IMemoryCache gives TTL,
|
||||||
|
/// ConcurrentDictionary gives key tracking for Clear() ...
|
||||||
|
/// </summary>
|
||||||
|
public class XAuthorizationCache : IXAuthorizationCache
|
||||||
|
{
|
||||||
|
private readonly TimeSpan ttl;
|
||||||
|
private readonly IMemoryCache cache;
|
||||||
|
private readonly ConcurrentDictionary<string, byte> keys = new();
|
||||||
|
private readonly XAppConfiguration appConfiguration;
|
||||||
|
|
||||||
|
public XAuthorizationCache(
|
||||||
|
IMemoryCache cache,
|
||||||
|
XAppConfiguration appConfiguration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
this.cache = cache;
|
||||||
|
this.appConfiguration = appConfiguration;
|
||||||
|
ttl = TimeSpan.FromMinutes(appConfiguration.DefaultCacheTtlMinutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetPolicy(
|
||||||
|
string name,
|
||||||
|
out AuthorizationPolicy policy
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
policy = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!name.IsNullOrEmpty() &&
|
||||||
|
cache.TryGetValue(Key(name), out policy);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPolicy(
|
||||||
|
string name,
|
||||||
|
AuthorizationPolicy policy
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (name.IsNullOrEmpty() || policy.IsNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
cache.Set(Key(name), policy, ttl);
|
||||||
|
keys[Key(name)] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemovePolicy(string name)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (name.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
cache.Remove(Key(name));
|
||||||
|
keys.TryRemove(Key(name), out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
foreach (var key in keys.Keys)
|
||||||
|
{
|
||||||
|
cache.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
keys.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Private ...
|
||||||
|
private static string Key(string name) =>
|
||||||
|
XIdentityServiceConstants.PolicyCacheKeyPrefix + name.ToNormalString();
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user