Open shrey-shah opened 2 months ago
@sagilio @sociometry @AsakusaRinne
Would you like to provide a valid model and policy text sample?
enforcer.GetModel().Model.Count
is the section count of the model, It may want to get the tokens count of policy.For example:
[request_definition]
r = sub, obj, act
[policy_definition] p = sub, obj, act
[policy_effect] e = some(where (p.eft == allow))
[matchers] m = r.sub == r.obj.Owner
You can get the **tokens count** like this:
```csharp
var assertion = e.Model.Sections.GetPolicyAssertion(PermConstants.DefaultPolicyType);
var tokensCount = assertion.Tokens.Count;
enforcer.GetPolicy().Any(x => x.Count != model_count)
is unnecessary now.enforcer.GetPolicy()
exist in the latest version yet, it is here: https://github.com/casbin/Casbin.NET/blob/fe66cd4c4b290997bec6ea4184424702db36f42b/Casbin/Extensions/Enforcer/ManagementEnforcerExtension.cs#L111-L116permission model:
[request_definition]
r = role, resource, action
[policy_definition]
p = role, resource, action, eft
[policy_effect]
# There must be atleast one rule to allow and no rule to deny
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
[matchers]
m = keyMatch(r.role, p.role) && (keyMatch(r.resource, p.resource) || keyMatch2(r.resource, p.resource)) && regexMatch(r.action, p.action)
permission policy sample:
p, SecurityAdmin, *, GET, allow
p, SecurityAdmin, /api/preferences, GET, deny
p, SecurityAdmin, /api/calendar_sync, GET, deny
p, SecurityAdmin, /api//bulk_download, POST, deny
p, SecurityAdmin, /api/service/*, POST, deny
the above code was used to validate if policy is setup as per the model. can we validate using any other way in the latest version?
any update here?
Here is the sample:
private bool IsValidPermissionPolicySetup(string model, string policy)
{
CustomEnforcer enforcer = new CustomEnforcer(model, policy);
return enforcer.GetPolicy().All(p =>
{
string last = p.Last();
return last is "allow" or "deny";
});
}
I am trying to migrate Casbin.net package from V1.13.0 to V2.9.1. I was validating my permission setup with this function in the earlier version.
in the wiki, it says that
enforcer.GetModel()
is now replaced byenforcer.Model
. but I couldn't find a way to get this count as theIModel
interface doesn't explicitly have any property. Also, the wiki doesn't mention the alternative ofenforcer.GetPolicy()
so not sure how to convert the above function to the latest version. Can someone help here?