From 19c9b40b4c72906c16d370e958459c003d3fd2f4 Mon Sep 17 00:00:00 2001 From: Kelvin Clement Mwinuka Date: Thu, 14 Dec 2023 15:14:00 +0800 Subject: [PATCH] Implemented connection registration ACL method --- src/modules/acl/acl.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/modules/acl/acl.go b/src/modules/acl/acl.go index 92a3fdf..64a0a45 100644 --- a/src/modules/acl/acl.go +++ b/src/modules/acl/acl.go @@ -38,9 +38,14 @@ type User struct { ExcludedPubSubChannels []string `json:"ExcludedPubSubChannels" yaml:"ExcludedPubSubChannels"` } +type Connection struct { + Authenticated bool + User User +} + type ACL struct { Users []User - Connections map[*net.Conn]*User + Connections map[*net.Conn]Connection Config utils.Config } @@ -58,7 +63,7 @@ func NewACL(config utils.Config) *ACL { } } - // 2. Read and parse the ACL config file and etc the + // 2. Read and parse the ACL config file if config.AclConfig != "" { // Override acl configurations from file if f, err := os.Open(config.AclConfig); err != nil { @@ -109,17 +114,22 @@ func NewACL(config utils.Config) *ACL { acl := ACL{ Users: users, - Connections: make(map[*net.Conn]*User), + Connections: make(map[*net.Conn]Connection), Config: config, } - fmt.Println(acl.Users) - return &acl } func (acl *ACL) RegisterConnection(conn *net.Conn) { - fmt.Println("Register connection...") + // This is called only when a connection is established. + defaultUser := utils.Filter(acl.Users, func(elem User) bool { + return elem.Username == "default" + })[0] + acl.Connections[conn] = Connection{ + Authenticated: false, + User: defaultUser, + } } func (acl *ACL) AuthenticateConnection(conn *net.Conn, cmd []string) error {