We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b190fce commit 1aba8b9Copy full SHA for 1aba8b9
4 files changed
enforcer_interface.go
@@ -101,6 +101,7 @@ type IEnforcer interface {
101
GetAllNamedActions(ptype string) ([]string, error)
102
GetAllRoles() ([]string, error)
103
GetAllNamedRoles(ptype string) ([]string, error)
104
+ GetAllUsers() ([]string, error)
105
GetPolicy() ([][]string, error)
106
GetFilteredPolicy(fieldIndex int, fieldValues ...string) ([][]string, error)
107
GetNamedPolicy(ptype string) ([][]string, error)
enforcer_synced.go
@@ -285,6 +285,13 @@ func (e *SyncedEnforcer) GetAllNamedRoles(ptype string) ([]string, error) {
285
return e.Enforcer.GetAllNamedRoles(ptype)
286
}
287
288
+// GetAllUsers gets the list of users that show up in the current policy.
289
+func (e *SyncedEnforcer) GetAllUsers() ([]string, error) {
290
+ e.m.RLock()
291
+ defer e.m.RUnlock()
292
+ return e.Enforcer.GetAllUsers()
293
+}
294
+
295
// GetPolicy gets all the authorization rules in the policy.
296
func (e *SyncedEnforcer) GetPolicy() ([][]string, error) {
297
e.m.RLock()
management_api.go
@@ -76,6 +76,23 @@ func (e *Enforcer) GetAllNamedRoles(ptype string) ([]string, error) {
76
return e.model.GetValuesForFieldInPolicy("g", ptype, 1)
77
78
79
80
+// Users are subjects that are not roles (i.e., subjects that do not appear as the second element in any grouping policy).
81
+func (e *Enforcer) GetAllUsers() ([]string, error) {
82
+ subjects, err := e.GetAllSubjects()
83
+ if err != nil {
84
+ return nil, err
85
+ }
86
87
+ roles, err := e.GetAllRoles()
88
89
90
91
92
+ users := util.SetSubtract(subjects, roles)
93
+ return users, nil
94
95
96
97
func (e *Enforcer) GetPolicy() ([][]string, error) {
98
return e.GetNamedPolicy("p")
management_api_test.go
@@ -41,6 +41,7 @@ func TestGetList(t *testing.T) {
41
testStringList(t, "Objects", e.GetAllObjects, []string{"data1", "data2"})
42
testStringList(t, "Actions", e.GetAllActions, []string{"read", "write"})
43
testStringList(t, "Roles", e.GetAllRoles, []string{"data2_admin"})
44
+ testStringList(t, "Users", e.GetAllUsers, []string{"alice", "bob"})
45
46
47
func TestGetListWithDomains(t *testing.T) {
@@ -50,6 +51,7 @@ func TestGetListWithDomains(t *testing.T) {
50
51
52
53
testStringList(t, "Roles", e.GetAllRoles, []string{"admin"})
54
+ testStringList(t, "Users", e.GetAllUsers, []string{})
55
56
57
func testGetPolicy(t *testing.T, e *Enforcer, res [][]string) {
0 commit comments