Skip to content

Commit 6aa3e94

Browse files
committed
Fix: Treat "*" as explicit wildcard instead of "".
This aligns with standard adapter behaviour, allowing "" to act as a literal value.
1 parent 017ae0e commit 6aa3e94

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

management_api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func TestGetPolicyAPI(t *testing.T) {
177177
{"data2_admin", "data2", "write"}})
178178

179179
testGetFilteredPolicy(t, e, 0, [][]string{{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}, "data2_admin", "data2")
180-
// Note: "" (empty string) in fieldValues means matching all values.
181-
testGetFilteredPolicy(t, e, 0, [][]string{{"data2_admin", "data2", "read"}}, "data2_admin", "", "read")
180+
// Note: "*" (asterisk) in fieldValues means matching all values.
181+
testGetFilteredPolicy(t, e, 0, [][]string{{"data2_admin", "data2", "read"}}, "data2_admin", "*", "read")
182182
testGetFilteredPolicy(t, e, 1, [][]string{{"bob", "data2", "write"}, {"data2_admin", "data2", "write"}}, "data2", "write")
183183

184184
testHasPolicy(t, e, []string{"alice", "data1", "read"}, true)
@@ -192,8 +192,8 @@ func TestGetPolicyAPI(t *testing.T) {
192192
testGetFilteredGroupingPolicy(t, e, 0, [][]string{}, "bob")
193193
testGetFilteredGroupingPolicy(t, e, 1, [][]string{}, "data1_admin")
194194
testGetFilteredGroupingPolicy(t, e, 1, [][]string{{"alice", "data2_admin"}}, "data2_admin")
195-
// Note: "" (empty string) in fieldValues means matching all values.
196-
testGetFilteredGroupingPolicy(t, e, 0, [][]string{{"alice", "data2_admin"}}, "", "data2_admin")
195+
// Note: "*" (asterisk) in fieldValues means matching all values.
196+
testGetFilteredGroupingPolicy(t, e, 0, [][]string{{"alice", "data2_admin"}}, "*", "data2_admin")
197197

198198
testHasGroupingPolicy(t, e, []string{"alice", "data2_admin"}, true)
199199
testHasGroupingPolicy(t, e, []string{"bob", "data2_admin"}, false)

model/policy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ func (model Model) GetFilteredPolicy(sec string, ptype string, fieldIndex int, f
127127
for _, rule := range model[sec][ptype].Policy {
128128
matched := true
129129
for i, fieldValue := range fieldValues {
130+
<<<<<<< Updated upstream
130131
if fieldValue != "" && rule[fieldIndex+i] != fieldValue {
132+
=======
133+
if fieldValue != "*" && rule[fieldIndex+i] != fieldValue {
134+
>>>>>>> Stashed changes
131135
matched = false
132136
break
133137
}
@@ -379,7 +383,7 @@ func (model Model) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int
379383
for _, rule := range model[sec][ptype].Policy {
380384
matched := true
381385
for i, fieldValue := range fieldValues {
382-
if fieldValue != "" && rule[fieldIndex+i] != fieldValue {
386+
if fieldValue != "*" && rule[fieldIndex+i] != fieldValue {
383387
matched = false
384388
break
385389
}

rbac_api.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (e *Enforcer) DeleteRolesForUser(user string, domain ...string) (bool, erro
9999
} else if len(domain) > 1 {
100100
return false, errors.ErrDomainParameter
101101
} else {
102-
args = []string{user, "", domain[0]}
102+
args = []string{user, "*", domain[0]}
103103
}
104104
return e.RemoveFilteredGroupingPolicy(0, args...)
105105
}
@@ -194,6 +194,10 @@ func (e *Enforcer) GetNamedPermissionsForUser(ptype string, user string, domain
194194
continue
195195
}
196196
args := make([]string, len(assertion.Tokens))
197+
// Fill all fields with "*" by default
198+
for i := range args {
199+
args[i] = "*"
200+
}
197201
subIndex, err := e.GetFieldIndex("p", constant.SubjectIndex)
198202
if err != nil {
199203
subIndex = 0

rbac_api_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (e *ContextEnforcer) DeleteRolesForUserCtx(ctx context.Context, user string
4848
} else if len(domain) > 1 {
4949
return false, errors.ErrDomainParameter
5050
} else {
51-
args = []string{user, "", domain[0]}
51+
args = []string{user, "*", domain[0]}
5252
}
5353
return e.RemoveFilteredGroupingPolicyCtx(ctx, 0, args...)
5454
}

0 commit comments

Comments
 (0)