-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from Sagilio/fix#154
feat: Support multiple role manager
- Loading branch information
Showing
8 changed files
with
172 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using NetCasbin.Model; | ||
|
||
namespace NetCasbin.Extensions | ||
{ | ||
public static class EnforcerExtension | ||
{ | ||
public static Enforcer AddMatchingFunc(this Enforcer enforcer, Func<string, string, bool> func) | ||
{ | ||
enforcer.AddNamedMatchingFunc(PermConstants.DefaultRoleType, func); | ||
return enforcer; | ||
} | ||
|
||
public static Enforcer AddDomainMatchingFunc(this Enforcer enforcer, Func<string, string, bool> func) | ||
{ | ||
enforcer.AddNamedDomainMatchingFunc(PermConstants.DefaultRoleType, func); | ||
return enforcer; | ||
} | ||
|
||
public static Enforcer AddNamedMatchingFunc(this Enforcer enforcer, string roleType, Func<string, string, bool> func) | ||
{ | ||
enforcer.GetModel().GetNamedRoleManger(roleType).AddMatchingFunc(func); | ||
return enforcer; | ||
} | ||
|
||
public static Enforcer AddNamedDomainMatchingFunc(this Enforcer enforcer, string roleType, Func<string, string, bool> func) | ||
{ | ||
enforcer.GetModel().GetNamedRoleManger(roleType).AddMatchingFunc(func); | ||
return enforcer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using NetCasbin.Model; | ||
using NetCasbin.Rbac; | ||
|
||
namespace NetCasbin.Extensions | ||
{ | ||
public static class ModelExtension | ||
{ | ||
internal static IRoleManager GetRoleManger(this Model.Model model) | ||
{ | ||
return model.GetNamedRoleManger(PermConstants.DefaultRoleType); | ||
} | ||
|
||
internal static IRoleManager GetNamedRoleManger(this Model.Model model, string roleType) | ||
{ | ||
return model.GetExistAssertion(PermConstants.Section.RoleSection, roleType).RoleManager; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.