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 add named groups in Casbin v2 #329

Closed mabvanaartrijk closed 9 months ago

mabvanaartrijk commented 10 months ago

We are migrating to v2. With v1 is was possible to add groups with other names than the default g, g2, ...

Changing TestMultipleGroupTypeModelInMemoryAsync to:

public async Task TestMultipleNamedGroupTypeModelInMemoryAsync()
{
    IModel m = DefaultModel.Create();
    m.AddDef("r", "r", "sub, obj, act");
    m.AddDef("p", "p", "sub, obj, act");
    m.AddDef("g", "firstGroup", "_, _");
    m.AddDef("g", "secondGroup", "_, _");
    m.AddDef("e", "e", "some(where (p.eft == allow))");
    m.AddDef("m", "m", "firstGroup(r.sub, p.sub) && secondGroup(r.obj, p.obj) && r.act == p.act");

    Enforcer e = new(m);
    await e.AddPolicyAsync("alice", "data1", "read");
    await e.AddPolicyAsync("bob", "data2", "write");
    await e.AddPolicyAsync("data_group_admin", "data_group", "write");
    await e.AddNamedGroupingPolicyAsync("firstGroup", "alice", "data_group_admin");
    await e.AddNamedGroupingPolicyAsync("secondGroup", "data1", "data_group");
    await e.AddNamedGroupingPolicyAsync("secondGroup", "data2", "data_group");

    Assert.True(await e.EnforceAsync("alice", "data1", "read"));
    Assert.True(await e.EnforceAsync("alice", "data1", "write"));
    Assert.False(await e.EnforceAsync("alice", "data2", "read"));
    Assert.True(await e.EnforceAsync("alice", "data2", "write"));
}

Raises the error: System.ArgumentOutOfRangeException: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'section') Actual value was g.

casbin-bot commented 10 months ago

@sagilio @sociometry @AsakusaRinne

sagilio commented 10 months ago

Thank you for the feedback, we will support this feature in the next version.

github-actions[bot] commented 9 months ago

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

The release is available on GitHub release

Your semantic-release bot :package::rocket: