diff --git a/src/modules/acl/acl.go b/src/modules/acl/acl.go index e1494fc..b857641 100644 --- a/src/modules/acl/acl.go +++ b/src/modules/acl/acl.go @@ -190,15 +190,15 @@ func (acl *ACL) SetUser(ctx context.Context, cmd []string) error { continue } if len(str) > 4 && strings.EqualFold(str[0:4], "%RW~") { - user.IncludedKeys = append(user.IncludedKeys, str[3:]) + user.IncludedKeys = append(user.IncludedKeys, str[4:]) continue } - if len(str) > 3 && strings.EqualFold(str[0:4], "%R~") { - user.IncludedReadKeys = append(user.IncludedReadKeys, str[2:]) + if len(str) > 3 && strings.EqualFold(str[0:3], "%R~") { + user.IncludedReadKeys = append(user.IncludedReadKeys, str[3:]) continue } - if len(str) > 3 && strings.EqualFold(str[0:4], "%w~") { - user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[2:]) + if len(str) > 3 && strings.EqualFold(str[0:3], "%W~") { + user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[3:]) continue } // Parse channels diff --git a/src/modules/acl/user.go b/src/modules/acl/user.go index 1d914b4..eacd4fc 100644 --- a/src/modules/acl/user.go +++ b/src/modules/acl/user.go @@ -1,5 +1,9 @@ package acl +import ( + "github.com/kelvinmwinuka/memstore/src/utils" +) + type User struct { Username string `json:"Username" yaml:"Username"` Enabled bool `json:"Enabled" yaml:"Enabled"` @@ -24,13 +28,37 @@ type User struct { func (user *User) Normalise() { user.IncludedCategories = RemoveDuplicateEntries(user.IncludedCategories, "allCategories") user.ExcludedCategories = RemoveDuplicateEntries(user.ExcludedCategories, "allCategories") + if utils.Contains(user.ExcludedCategories, "*") { + user.IncludedCategories = []string{} + } + user.IncludedCommands = RemoveDuplicateEntries(user.IncludedCommands, "allCommands") user.ExcludedCommands = RemoveDuplicateEntries(user.ExcludedCommands, "allCommands") + if utils.Contains(user.ExcludedCommands, "*") { + user.IncludedCommands = []string{} + } + user.IncludedKeys = RemoveDuplicateEntries(user.IncludedKeys, "allKeys") + if len(user.IncludedKeys) == 0 { + user.IncludedKeys = []string{"*"} + } user.IncludedReadKeys = RemoveDuplicateEntries(user.IncludedReadKeys, "allKeys") + if len(user.IncludedReadKeys) == 0 { + user.IncludedReadKeys = []string{"*"} + } user.IncludedWriteKeys = RemoveDuplicateEntries(user.IncludedWriteKeys, "allKeys") + if len(user.IncludedWriteKeys) == 0 { + user.IncludedWriteKeys = []string{"*"} + } + user.IncludedPubSubChannels = RemoveDuplicateEntries(user.IncludedPubSubChannels, "allChannels") + if len(user.IncludedPubSubChannels) == 0 { + user.IncludedPubSubChannels = []string{"*"} + } user.ExcludedPubSubChannels = RemoveDuplicateEntries(user.ExcludedPubSubChannels, "allChannels") + if utils.Contains(user.ExcludedPubSubChannels, "*") { + user.IncludedPubSubChannels = []string{} + } } func RemoveDuplicateEntries(entries []string, allAlias string) (res []string) {