diff --git a/src/Acl.Net.Core.Database/Acl.Net.Core.Database.csproj b/src/Acl.Net.Core.Database/Acl.Net.Core.Database.csproj index 8c17732..64f15ba 100644 --- a/src/Acl.Net.Core.Database/Acl.Net.Core.Database.csproj +++ b/src/Acl.Net.Core.Database/Acl.Net.Core.Database.csproj @@ -30,7 +30,7 @@ - + diff --git a/src/Acl.Net.Core.Database/RoleDataSeeder.cs b/src/Acl.Net.Core.Database/RoleDataSeeder.cs index 31b964b..865af86 100644 --- a/src/Acl.Net.Core.Database/RoleDataSeeder.cs +++ b/src/Acl.Net.Core.Database/RoleDataSeeder.cs @@ -10,4 +10,4 @@ public Role SeedAdminRole() { return new Role { Id = 1, Name = "Admin" }; } -} +} \ No newline at end of file diff --git a/src/Acl.Net.Core.Managers/AclManager.cs b/src/Acl.Net.Core.Managers/AclManager.cs index 13e4fc0..ca093d0 100644 --- a/src/Acl.Net.Core.Managers/AclManager.cs +++ b/src/Acl.Net.Core.Managers/AclManager.cs @@ -5,8 +5,8 @@ namespace Acl.Net.Core.Managers; /// -/// Manages access control lists (ACLs) using integer keys. -/// This class provides a simplified interface for managing ACLs with integer keys, by extending the more generic with TKey. +/// Manages access control lists (ACLs) using integer keys.
+/// This class provides a simplified interface for managing ACLs with integer keys, by extending the more generic . ///
public class AclManager : AclManager, IAclManager { @@ -35,7 +35,7 @@ AclDbContext context } /// -/// Manages access control lists (ACLs) using keys of type . +/// Manages access control lists (ACLs) using keys of type .
/// This class provides the base functionality for managing ACLs with specified key types. ///
/// The type of the key, which must implement . @@ -57,14 +57,14 @@ AclDbContext context } /// -/// Manages access control lists (ACLs) using keys, users, roles, and resources of specified types. +/// Manages access control lists (ACLs) using keys, users, roles, and resources of specified types.
/// This class provides the complete functionality for managing ACLs with specified key, user, role, and resource types. ///
/// The type of the key, which must implement . /// The type of the user, which must be a derived type of . /// The type of the role, which must be a derived type of /// The type of the resource, which must be a derived type of -public class AclManager : IAclManager +public class AclManager : IAclManager where TKey : IEquatable where TUser : User, new() where TRole : Role @@ -88,20 +88,23 @@ AclDbContext context Context = context; } + /// public bool IsPermitted(string userName, string resourceName) { var user = GetUserByName(userName); return IsAdmin(user) || GetUserRoles(user.Name).Any(role => IsPermitted(role, GetResourceByName(resourceName))); } + /// public bool IsPermitted(TUser user, TResource resource) { return IsAdmin(user) || GetUserRoles(user.Name).Any(role => IsPermitted(role, resource)); } + /// public bool IsPermitted(TRole role, TResource resource) { - return IsAdmin(role) || Context.Resources.Any(r => r.RoleId.Equals(role.Id) && r.Id.Equals(resource.Id)); + return IsAdmin(role) || Context.Resources.Any(res => res.Name.Equals(resource.Name) && res.RoleId.Equals(role.Id)); } public bool IsAdmin(TKey roleId) => roleId.Equals(InitialDataSeeder.SeedAdminRole().Id); diff --git a/src/Acl.Net.Core.Managers/IAclManager.cs b/src/Acl.Net.Core.Managers/IAclManager.cs index edf030a..59533b5 100644 --- a/src/Acl.Net.Core.Managers/IAclManager.cs +++ b/src/Acl.Net.Core.Managers/IAclManager.cs @@ -12,7 +12,7 @@ public interface IAclManager : IAclManager; /// Defines the contract for Access Control List (ACL) management with support for a specific key type. /// /// The type of key used to identify users and resources. -public interface IAclManager : IAclManager, Resource> +public interface IAclManager : IAclManager, Role, Resource> where TKey : IEquatable; /// @@ -20,10 +20,12 @@ public interface IAclManager : IAclManager, Resource /// The type of key, which must implement . /// The type representing a user, which must inherit from . +/// The type representing a role, which must inherit from . /// The type representing a resource, which must inherit from . -public interface IAclManager +public interface IAclManager where TKey : IEquatable where TUser : User + where TRole: Role where TResource : Resource { /// @@ -31,52 +33,24 @@ public interface IAclManager /// /// The name of the user to check permission for. /// The name of the resource to check permission against. - /// - /// if the user is permitted to access the resource; otherwise, . - /// - /// Thrown when the specified resource name does not exist. - //public bool IsPermitted(string userName, string resourceName); - - /// - /// Determines if the specified user object is permitted to access the specified resource by name. - /// - /// The user object to check permission for. - /// The name of the resource to check permission against. - /// - /// if the user is permitted to access the resource; otherwise, . - /// - /// Thrown when the specified resource name does not exist. - //public bool IsPermitted(TUser user, string resourceName); - - /// - /// Determines if the specified user by name is permitted to access the specified resource object. - /// - /// The name of the user to check permission for. - /// The resource object to check permission against. - /// - /// if the user is permitted to access the resource; otherwise, . - /// - //public bool IsPermitted(string userName, TResource resource); + /// if the user is permitted to access the resource; otherwise, . + /// Thrown when the specified resource by name does not exist. + /// Thrown when the specified user by name does not exist. + public bool IsPermitted(string userName, string resourceName); /// /// Determines if the specified user object is permitted to access the specified resource object. /// /// The user object to check permission for. /// The resource object to check permission against. - /// - /// if the user is permitted to access the resource; otherwise, . - /// - //public bool IsPermitted(TUser user, TResource resource); + /// if the user is permitted to access the resource; otherwise, . + public bool IsPermitted(TUser user, TResource resource); /// - /// Determines the resources that the specified user by name is permitted to access from a collection of resource names. + /// Determines whether the specified role is permitted to access the given resource. /// - /// The name of the user to check permission for. - /// The collection of resource names to check permissions against. - /// - /// A collection of objects that the user is permitted to access; - /// an empty collection if the user is not permitted to access any of the resources. - /// - /// Thrown when one or more of the specified resource names do not exist. - //public IEnumerable IsPermitted(string userName, IEnumerable resourceNames); + /// The role to check permissions for. + /// The resource to check. + /// if the role is permitted to access the resource; otherwise, . + public bool IsPermitted(TRole role, TResource resource); } \ No newline at end of file