-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add JSON value for ABAC (#373)
* feat: support JSON request Signed-off-by: Taoyuesong <[email protected]> * feat: support JSON request Signed-off-by: Taoyuesong <[email protected]> * feat: add test case Signed-off-by: Taoyuesong <[email protected]> * feat: clean up test project by list pattern Signed-off-by: Taoyuesong <[email protected]> --------- Signed-off-by: Taoyuesong <[email protected]>
- Loading branch information
1 parent
85b9330
commit acd8715
Showing
17 changed files
with
723 additions
and
507 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Casbin.UnitTests/Examples/abac_not_using_policy_model.conf
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,11 @@ | ||
[request_definition] | ||
r = sub, obj, act | ||
|
||
[policy_definition] | ||
p = sub, obj, act, eft | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) && !some(where (p.eft == deny)) | ||
|
||
[matchers] | ||
m = r.sub == r.obj.Owner |
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,4 @@ | ||
p, alice, /data1, read, deny | ||
p, alice, /data1, write, allow | ||
p, bob, /data2, write, deny | ||
p, bob, /data2, read, allow |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
p, r.sub.Age > 18, /data1, read | ||
p, r.sub.Age < 60, /data2, write | ||
p, r.sub.Age < 60, /data2, write |
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,29 @@ | ||
#if !NET452 && !NET461 && !NET462 | ||
using Casbin.Model; | ||
using DynamicExpresso; | ||
using Xunit; | ||
|
||
namespace Casbin.UnitTests.ModelTests; | ||
|
||
public class JsonValueTest | ||
{ | ||
[Fact] | ||
public void GetJsonValueTest() | ||
{ | ||
string json = "{\"name\":\"John\",\"age\":30,\"car\":null}"; | ||
|
||
var interpreter = new Interpreter(); | ||
interpreter.SetVariable("obj", new JsonValue(json)); | ||
object result = interpreter.Eval("obj.name"); | ||
Assert.Equal("John", result); | ||
|
||
string arrayJson = "[{\"name\":\"John\"},{\"name\":\"Doe\"}]"; | ||
|
||
interpreter.SetVariable("array", new JsonValue(arrayJson)); | ||
object arrayResult = interpreter.Eval("array[0].name"); | ||
Assert.Equal("John", arrayResult); | ||
} | ||
} | ||
#endif | ||
|
||
|
Oops, something went wrong.