casbin / Casbin.NET

An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
https://casbin.org
Apache License 2.0
1.13k stars 110 forks source link

Cannot get Policy with null value in EF core Adapter. #335

Closed vansangnguyen1998 closed 2 months ago

vansangnguyen1998 commented 9 months ago

I am implemented Authorization with casbin in my dotnet project. I use EF core adapter for casbin and sql server to database. My model.conf:

[request_definition]
r = RoleId, domain, TypeQuery, operationName

[policy_definition]
p = RoleId, domain, TypeQuery, operationName, eft, scope

[role_definition]
g = _, _, _

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m = g(r.RoleId, p.RoleId, r.domain) && r.domain == p.domain && r.TypeQuery == p.TypeQuery && r.operationName == p.operationName

I have the fake policy in sql server similar like that: image

When I call request to check permission for pipeline request: image

But data when e.GetPolicy() only return 2 item with v5 is not null image

Please help me solve problem with casbin.

I want to e.GetPolicy() have to have 3 policy contain record v5 is null

casbin-bot commented 9 months ago

@sagilio @sociometry @AsakusaRinne

hsluoyz commented 9 months ago

@vansangnguyen1998 please:

  1. Use pure Casbin API (enforcer, adapter, etc.) in the code (don't add your RESTful)
  2. Clarify what you get and what you expect
vansangnguyen1998 commented 9 months ago

@hsluoyz With my models.conf above. When use e.GetPolicy() I get response 2 record:

My expect have to exists 3 record 2 record 2 above and 1 record with v5 null same image above ticket.

sagilio commented 9 months ago

This should be related to the SQL generated by the policy. I will try to reproduce it later.

vansangnguyen1998 commented 8 months ago

@sagilio I have reproduce with NodeJS with the same case, same data, and same model, Surprisingly, I can get all policy with the same my expectation (3 policy). Please check again with CasbinNodeJS (Node Cas) and Casbin-Dotnet

please reproduce with dotnet ASAP help me. Thanks all

hsluoyz commented 8 months ago

@vansangnguyen1998 if your problem is for one adapter, create issue in that adapter's repo, not here

dacongda commented 5 months ago

it seems that adapter is not the problem, the question is cause by function ValuesFrom in model/policy.cs, it use string.IsNullOrWhiteSpace to valid weather the field is exist , so when the field is blank , it will return false when TryAddPolicy call ValidatePolicy, and it will not appears in the result

github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 2.6.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: