diff --git a/Constants/XPolicyKind.cs b/Constants/XPolicyKind.cs
new file mode 100644
index 0000000..d7a474d
--- /dev/null
+++ b/Constants/XPolicyKind.cs
@@ -0,0 +1,22 @@
+using xExceptions.Attributes;
+
+namespace xIdentityModels.Constants
+{
+ ///
+ /// Kind of a Policy Definition ...
+ ///
+ public enum XPolicyKind
+ {
+ [StringValue("roleBased")]
+ RoleBased = 0,
+
+ [StringValue("scopeBased")]
+ ScopeBased = 1,
+
+ [StringValue("claimBased")]
+ ClaimBased = 2,
+
+ [StringValue("composite")]
+ Composite = 3
+ }
+}
\ No newline at end of file
diff --git a/Dtos/XPolicyDefinitionDto.cs b/Dtos/XPolicyDefinitionDto.cs
new file mode 100644
index 0000000..21ec876
--- /dev/null
+++ b/Dtos/XPolicyDefinitionDto.cs
@@ -0,0 +1,66 @@
+using xModels.Base;
+using xIdentityModels.Constants;
+
+namespace xIdentityModels.Dtos
+{
+ ///
+ /// a Policy Definition Model which can be converted to AuthorizationPolicy ...
+ ///
+ public class XPolicyDefinitionDto : XBaseIntIDEntityDto
+ {
+ ///
+ /// Unique Policy Name, e.g. enabledEditorPolicy ...
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Display Name ...
+ ///
+ public string DisplayName { get; set; }
+
+ ///
+ /// Policy Kind ...
+ ///
+ public XPolicyKind Kind { get; set; } = XPolicyKind.RoleBased;
+
+ ///
+ /// Comma Separated Role Names (explicit list) ...
+ ///
+ public string RequiredRoles { get; set; }
+
+ ///
+ /// if provided, all Roles with Weight >= MinRoleWeight will be Injected ...
+ ///
+ public int? MinRoleWeight { get; set; }
+
+ ///
+ /// Comma Separated Scope Names ...
+ ///
+ public string RequiredScopes { get; set; }
+
+ ///
+ /// Json Array of { "Type": "...", "Values": ["..."] } ...
+ ///
+ public string RequiredClaims { get; set; }
+
+ ///
+ /// Requires IsBanned=false and IsEnabled=true Claims ...
+ ///
+ public bool RequireEnabledUser { get; set; }
+
+ ///
+ /// Requires Authenticated User ...
+ ///
+ public bool RequireAuthenticatedUser { get; set; } = true;
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Dtos/XPolicyEvaluationResultDto.cs b/Dtos/XPolicyEvaluationResultDto.cs
new file mode 100644
index 0000000..8874b50
--- /dev/null
+++ b/Dtos/XPolicyEvaluationResultDto.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace xIdentityModels.Dtos
+{
+ public class XPolicyEvaluationResultDto
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/Dtos/XRoleDefinitionDto.cs b/Dtos/XRoleDefinitionDto.cs
new file mode 100644
index 0000000..347a842
--- /dev/null
+++ b/Dtos/XRoleDefinitionDto.cs
@@ -0,0 +1,40 @@
+using xModels.Base;
+
+namespace xIdentityModels.Dtos
+{
+ ///
+ /// a Role Definition Model (mirror of ASP.NET IdentityRole + Weight) ...
+ ///
+ public class XRoleDefinitionDto : XBaseIntIDEntityDto
+ {
+ ///
+ /// Unique Normalized Role Name, e.g. chief_clerk ...
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Persian Display Name, e.g. سر دبیر ...
+ ///
+ public string DisplayName { get; set; }
+
+ ///
+ /// Role Weight, same as XUserRole enum (user=0 ... admin=10) ...
+ ///
+ public int Weight { get; set; }
+
+ ///
+ /// Optional Parent Role for Inheritance ...
+ ///
+ public string ParentRoleName { get; set; }
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Dtos/XScopeDefinitionDto.cs b/Dtos/XScopeDefinitionDto.cs
new file mode 100644
index 0000000..a6a4286
--- /dev/null
+++ b/Dtos/XScopeDefinitionDto.cs
@@ -0,0 +1,45 @@
+using xModels.Base;
+
+namespace xIdentityModels.Dtos
+{
+ ///
+ /// a Scope Definition Model (mirror of IdentityServer ApiScope) ...
+ ///
+ public class XScopeDefinitionDto : XBaseIntIDEntityDto
+ {
+ ///
+ /// Unique Scope Name, e.g. XAPI.read ...
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Display Name ...
+ ///
+ public string DisplayName { get; set; }
+
+ ///
+ /// Description ...
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// Comma Separated List of User Claims ...
+ ///
+ public string UserClaims { get; set; }
+
+ ///
+ /// Optional ApiResource Name on IdentityServer ...
+ ///
+ public string ApiResourceName { get; set; }
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Extensions/XModelExtensions.cs b/Extensions/XModelExtensions.cs
index 39d30bd..8fb329a 100644
--- a/Extensions/XModelExtensions.cs
+++ b/Extensions/XModelExtensions.cs
@@ -251,6 +251,198 @@ namespace xIdentityModels.Extensions
return result;
}
+ ///
+ /// Validate Policy Kind ...
+ ///
+ ///
+ ///
+ public static bool IsKindValid(this XPolicyDefinition source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault();
+ switch (source.Kind)
+ {
+ //
+ case Constants.XPolicyKind.Composite:
+ //
+ result =
+ !(source.RequiredRoles.IsNullOrEmpty() &&
+ source.RequiredClaims.IsNullOrEmpty() &&
+ source.RequiredScopes.IsNullOrEmpty());
+ break;
+
+ //
+ case Constants.XPolicyKind.ClaimBased:
+ //
+ result =
+ !source.RequiredClaims.IsNullOrEmpty();
+ break;
+
+ //
+ case Constants.XPolicyKind.ScopeBased:
+ //
+ result =
+ !source.RequiredScopes.IsNullOrEmpty();
+ break;
+
+ //
+ case Constants.XPolicyKind.RoleBased:
+ //
+ result =
+ !source.RequiredRoles.IsNullOrEmpty();
+ break;
+ }
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Policy Kind ...
+ ///
+ ///
+ ///
+ public static bool IsKindValid(this XPolicyDefinitionDto source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault();
+ switch (source.Kind)
+ {
+ //
+ case Constants.XPolicyKind.Composite:
+ //
+ result =
+ !(source.RequiredRoles.IsNullOrEmpty() &&
+ source.RequiredClaims.IsNullOrEmpty() &&
+ source.RequiredScopes.IsNullOrEmpty());
+ break;
+
+ //
+ case Constants.XPolicyKind.ClaimBased:
+ //
+ result =
+ !source.RequiredClaims.IsNullOrEmpty();
+ break;
+
+ //
+ case Constants.XPolicyKind.ScopeBased:
+ //
+ result =
+ !source.RequiredScopes.IsNullOrEmpty();
+ break;
+
+ //
+ case Constants.XPolicyKind.RoleBased:
+ //
+ result =
+ !source.RequiredRoles.IsNullOrEmpty();
+ break;
+ }
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XPolicyDefinition source)
+ {
+ //
+ var result =
+ source.IsKindValid() &&
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XPolicyDefinitionDto source)
+ {
+ //
+ var result =
+ source.IsKindValid() &&
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XRoleDefinition source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XRoleDefinitionDto source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XScopeDefinition source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
+ ///
+ /// Validate Item for Add or Update ...
+ ///
+ ///
+ ///
+ public static bool IsValidForAdd(this XScopeDefinitionDto source)
+ {
+ //
+ var result =
+ !source.IsNullOrDefault() &&
+ !source.Name.IsNullOrEmpty();
+
+ //
+ return result;
+ }
+
///
/// Validate Item for Add or Update ...
///
diff --git a/Interfaces/IXAuthorizationCache.cs b/Interfaces/IXAuthorizationCache.cs
new file mode 100644
index 0000000..83f3e51
--- /dev/null
+++ b/Interfaces/IXAuthorizationCache.cs
@@ -0,0 +1,12 @@
+using Microsoft.AspNetCore.Authorization;
+
+namespace xIdentityModels.Interfaces
+{
+ public interface IXAuthorizationCache
+ {
+ void Clear();
+ void RemovePolicy(string name);
+ void SetPolicy(string name, AuthorizationPolicy policy);
+ bool TryGetPolicy(string name, out AuthorizationPolicy policy);
+ }
+}
\ No newline at end of file
diff --git a/Interfaces/IXPolicyProvider.cs b/Interfaces/IXPolicyProvider.cs
new file mode 100644
index 0000000..ab3eb51
--- /dev/null
+++ b/Interfaces/IXPolicyProvider.cs
@@ -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 xIdentityModels.Interfaces
+{
+ public interface IXPolicyProvider
+ {
+ //
+ #region Readers ...
+ ///
+ /// retrieve whole items as queryable ...
+ ///
+ /// a flag for Tracking behaviour
+ /// an Expression for Filter Items ...
+ /// an Order Builder expression for Ordering Query ...
+ ///
+ IQueryable AsQueryable(
+ bool asNoTracking = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null
+ );
+
+ ///
+ /// retrieve an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task GetAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// retrieve all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetAllAsync(
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find an Entity by providing a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task FindOneAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find a collection of Entities by proving a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> FindManyAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ Task CountAsync(
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities Pages by providing page size ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task PagesCountAsync(
+ int pageSize,
+ int? totalItems = null,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Check an Entity exists or not ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task IsExistsAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Query ...
+ ///
+ /// retrieve Entities based on XQuery Pagination structure ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> QueryAsync(
+ XQuery query,
+ bool ignoreSoftDeleteds = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Add/Update/Remove ...
+ ///
+ /// add a new Entity ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddAsync(
+ XPolicyDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Update an Entity values ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task UpdateAsync(
+ int id,
+ XPolicyDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// remove an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveAsync(
+ int id,
+ bool softDelete = true,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Custom ...
+ #endregion
+
+ //
+ #region Enrichers ...
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XPolicyDefinition source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XPolicyDefinitionDto source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Interfaces/IXRoleProvider.cs b/Interfaces/IXRoleProvider.cs
new file mode 100644
index 0000000..d226301
--- /dev/null
+++ b/Interfaces/IXRoleProvider.cs
@@ -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 xIdentityModels.Interfaces
+{
+ public interface IXRoleProvider
+ {
+ //
+ #region Readers ...
+ ///
+ /// retrieve whole items as queryable ...
+ ///
+ /// a flag for Tracking behaviour
+ /// an Expression for Filter Items ...
+ /// an Order Builder expression for Ordering Query ...
+ ///
+ IQueryable AsQueryable(
+ bool asNoTracking = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null
+ );
+
+ ///
+ /// retrieve an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task GetAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// retrieve all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetAllAsync(
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find an Entity by providing a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task FindOneAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find a collection of Entities by proving a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> FindManyAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ Task CountAsync(
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities Pages by providing page size ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task PagesCountAsync(
+ int pageSize,
+ int? totalItems = null,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Check an Entity exists or not ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task IsExistsAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Query ...
+ ///
+ /// retrieve Entities based on XQuery Pagination structure ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> QueryAsync(
+ XQuery query,
+ bool ignoreSoftDeleteds = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Add/Update/Remove ...
+ ///
+ /// add a new Entity ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddAsync(
+ XRoleDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Update an Entity values ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task UpdateAsync(
+ int id,
+ XRoleDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// remove an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveAsync(
+ int id,
+ bool softDelete = true,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Custom ...
+ #endregion
+
+ //
+ #region Enrichers ...
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XRoleDefinition source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XRoleDefinitionDto source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Interfaces/IXScopeProvider.cs b/Interfaces/IXScopeProvider.cs
new file mode 100644
index 0000000..4bcd78a
--- /dev/null
+++ b/Interfaces/IXScopeProvider.cs
@@ -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 xIdentityModels.Interfaces
+{
+ public interface IXScopeProvider
+ {
+ //
+ #region Readers ...
+ ///
+ /// retrieve whole items as queryable ...
+ ///
+ /// a flag for Tracking behaviour
+ /// an Expression for Filter Items ...
+ /// an Order Builder expression for Ordering Query ...
+ ///
+ IQueryable AsQueryable(
+ bool asNoTracking = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null
+ );
+
+ ///
+ /// retrieve an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task GetAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// retrieve all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetAllAsync(
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find an Entity by providing a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task FindOneAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// find a collection of Entities by proving a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> FindManyAsync(
+ Expression> predicate,
+ bool ignoreSoftDeleteds = true,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities ...
+ ///
+ ///
+ ///
+ ///
+ Task CountAsync(
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// count all exists Entities Pages by providing page size ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task PagesCountAsync(
+ int pageSize,
+ int? totalItems = null,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Check an Entity exists or not ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task IsExistsAsync(
+ int id,
+ bool ignoreSoftDeleteds = true,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Query ...
+ ///
+ /// retrieve Entities based on XQuery Pagination structure ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> QueryAsync(
+ XQuery query,
+ bool ignoreSoftDeleteds = true,
+ Expression> predicate = null,
+ Func, IOrderedQueryable> orderBuilder = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Add/Update/Remove ...
+ ///
+ /// add a new Entity ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddAsync(
+ XScopeDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Update an Entity values ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task UpdateAsync(
+ int id,
+ XScopeDefinitionDto item,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// remove an Entity by it's Id ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveAsync(
+ int id,
+ bool softDelete = true,
+ bool saveChanges = true,
+ XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+
+ //
+ #region Custom ...
+ #endregion
+
+ //
+ #region Enrichers ...
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XScopeDefinition source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich Item ...
+ ///
+ ///
+ ///
+ ///
+ Task EnrichAsync(
+ XScopeDefinitionDto source,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Enrich a Collection of Items(s) ...
+ ///
+ ///
+ ///
+ ///
+ Task> EnrichRangeAsync(
+ IEnumerable sources,
+ CancellationToken cancellationToken = default
+ );
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Models/XPolicyDefinition.cs b/Models/XPolicyDefinition.cs
new file mode 100644
index 0000000..f54f88e
--- /dev/null
+++ b/Models/XPolicyDefinition.cs
@@ -0,0 +1,70 @@
+using xModels.Base;
+using xIdentityModels.Constants;
+using System.ComponentModel.DataAnnotations;
+
+namespace xIdentityModels.Models
+{
+ ///
+ /// a Policy Definition Model which can be converted to AuthorizationPolicy ...
+ ///
+ public class XPolicyDefinition : XBaseIntIDEntity
+ {
+ ///
+ /// Unique Policy Name, e.g. enabledEditorPolicy ...
+ ///
+ [Required]
+ [StringLength(200)]
+ public string Name { get; set; }
+
+ ///
+ /// Display Name ...
+ ///
+ [StringLength(255)]
+ public string DisplayName { get; set; }
+
+ ///
+ /// Policy Kind ...
+ ///
+ public XPolicyKind Kind { get; set; } = XPolicyKind.RoleBased;
+
+ ///
+ /// Comma Separated Role Names (explicit list) ...
+ ///
+ public string RequiredRoles { get; set; }
+
+ ///
+ /// if provided, all Roles with Weight >= MinRoleWeight will be Injected ...
+ ///
+ public int? MinRoleWeight { get; set; }
+
+ ///
+ /// Comma Separated Scope Names ...
+ ///
+ public string RequiredScopes { get; set; }
+
+ ///
+ /// Json Array of { "Type": "...", "Values": ["..."] } ...
+ ///
+ public string RequiredClaims { get; set; }
+
+ ///
+ /// Requires IsBanned=false and IsEnabled=true Claims ...
+ ///
+ public bool RequireEnabledUser { get; set; }
+
+ ///
+ /// Requires Authenticated User ...
+ ///
+ public bool RequireAuthenticatedUser { get; set; } = true;
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Models/XRoleDefinition.cs b/Models/XRoleDefinition.cs
new file mode 100644
index 0000000..33efced
--- /dev/null
+++ b/Models/XRoleDefinition.cs
@@ -0,0 +1,45 @@
+using xModels.Base;
+using System.ComponentModel.DataAnnotations;
+
+namespace xIdentityModels.Models
+{
+ ///
+ /// a Role Definition Model (mirror of ASP.NET IdentityRole + Weight) ...
+ ///
+ public class XRoleDefinition : XBaseIntIDEntity
+ {
+ ///
+ /// Unique Normalized Role Name, e.g. chief_clerk ...
+ ///
+ [Required]
+ [StringLength(256)]
+ public string Name { get; set; }
+
+ ///
+ /// Persian Display Name, e.g. سر دبیر ...
+ ///
+ [StringLength(255)]
+ public string DisplayName { get; set; }
+
+ ///
+ /// Role Weight, same as XUserRole enum (user=0 ... admin=10) ...
+ ///
+ public int Weight { get; set; }
+
+ ///
+ /// Optional Parent Role for Inheritance ...
+ ///
+ [StringLength(256)]
+ public string ParentRoleName { get; set; }
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Models/XScopeDefinition.cs b/Models/XScopeDefinition.cs
new file mode 100644
index 0000000..664edca
--- /dev/null
+++ b/Models/XScopeDefinition.cs
@@ -0,0 +1,51 @@
+using xModels.Base;
+using System.ComponentModel.DataAnnotations;
+
+namespace xIdentityModels.Models
+{
+ ///
+ /// a Scope Definition Model (mirror of IdentityServer ApiScope) ...
+ ///
+ public class XScopeDefinition : XBaseIntIDEntity
+ {
+ ///
+ /// Unique Scope Name, e.g. XAPI.read ...
+ ///
+ [Required]
+ [StringLength(200)]
+ public string Name { get; set; }
+
+ ///
+ /// Display Name ...
+ ///
+ [StringLength(255)]
+ public string DisplayName { get; set; }
+
+ ///
+ /// Description ...
+ ///
+ [StringLength(1000)]
+ public string Description { get; set; }
+
+ ///
+ /// Comma Separated List of User Claims ...
+ ///
+ public string UserClaims { get; set; }
+
+ ///
+ /// Optional ApiResource Name on IdentityServer ...
+ ///
+ [StringLength(200)]
+ public string ApiResourceName { get; set; }
+
+ ///
+ /// Is Enabled ...
+ ///
+ public bool IsEnabled { get; set; } = true;
+
+ ///
+ /// Seeded from Constants, cannot be removed ...
+ ///
+ public bool IsSystem { get; set; }
+ }
+}
\ No newline at end of file