Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GetRolesForUserForAllDomains #612

Closed
wants to merge 8 commits into from

Conversation

00LT00
Copy link
Member

@00LT00 00LT00 commented Sep 25, 2020

Fix: #588

Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
Signed-off-by: 00LT00 <lightning@zerokirin.online>
@00LT00
Copy link
Member Author

00LT00 commented Sep 25, 2020

plz review @PhilippSeitz @hsluoyz @nodece

Signed-off-by: 00LT00 <lightning@zerokirin.online>
rbac_api_with_domains.go Show resolved Hide resolved
func (rm *RoleManager) GetAllDomainsForUser(name string) []string {
var res []string
rm.allDomains.Range(func(key, value interface{}) bool {
role := value.(*Roles).createRole(name, rm.matchingFunc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the matchingFunc supposed to work already, like discussed here #588?

p, admin, *, read, allow
p, admin, *, write, allow
p, member, *, read, allow
p, trudy.custom, trudy_org, write, allow
p, trudy.custom, trudy_org, read, deny

g, alice, admin, alice_org
g, bob, member, alice_org
g, trudy, member, trudy_org
g, trudy, trudy.custom, trudy_org
e, _ := casbin.NewEnforcer(config)
e.GetRoleManager().(*defaultrolemanager.RoleManager).AddMatchingFunc("keyMatch", util.KeyMatch)
result, err := e.GetImplicitPermissionsForUserForAllDomains(subject)
expected := [][]string{
	{"member", "trudy_org", "read", "allow"},
	{"trudy.custom", "trudy_org", "write", "allow"},
	{"trudy.custom", "trudy_org", "read", "deny"},
}
Expect(err).ShouldNot(HaveOccurred())
Expect(result).Should(ConsistOf(expected))

will result in:

  Expected
      <[][]string | len:2, cap:2>: [
          ["trudy.custom", "trudy_org", "write", "allow"],
          ["trudy.custom", "trudy_org", "read", "deny"],
      ]
  to consist of
      <[]interface {} | len:1, cap:1>: [
          [
              ["member", "trudy_org", "read", "allow"],
              ["trudy.custom", "trudy_org", "write", "allow"],
              ["trudy.custom", "trudy_org", "read", "deny"],
          ],
      ]
  the missing elements were
      <[]interface {} | len:1, cap:1>: [
          ["member", "trudy_org", "read", "allow"],
      ]

@hsluoyz
Copy link
Member

hsluoyz commented Dec 18, 2020

@00LT00 any update?

@hsluoyz hsluoyz closed this Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Get roles for user with matcher_functions in the role_definition
3 participants