diff --git a/broker/auth.go b/broker/auth.go index bd7161f..4608b1c 100644 --- a/broker/auth.go +++ b/broker/auth.go @@ -11,7 +11,7 @@ const ( PUB = "2" ) -func (b *Broker) CheckTopicAuth(action, username, topic string) bool { +func (b *Broker) CheckTopicAuth(action, clientID, username, ip, topic string) bool { if b.auth != nil { if strings.HasPrefix(topic, "$SYS/broker/connection/clients/") { return true @@ -25,7 +25,7 @@ func (b *Broker) CheckTopicAuth(action, username, topic string) bool { topic = substr[2] } - return b.auth.CheckACL(action, username, topic) + return b.auth.CheckACL(action, clientID, username, ip, topic) } return true diff --git a/broker/client.go b/broker/client.go index 5362057..f21c977 100644 --- a/broker/client.go +++ b/broker/client.go @@ -242,7 +242,7 @@ func (c *client) processClientPublish(packet *packets.PublishPacket) { topic := packet.TopicName - if !c.broker.CheckTopicAuth(PUB, c.info.username, topic) { + if !c.broker.CheckTopicAuth(PUB, c.info.clientID, c.info.username, c.info.remoteIP, topic) { log.Error("Pub Topics Auth failed, ", zap.String("topic", topic), zap.String("ClientID", c.info.clientID)) return } @@ -357,7 +357,7 @@ func (c *client) processClientSubscribe(packet *packets.SubscribePacket) { for i, topic := range topics { t := topic //check topic auth for client - if !b.CheckTopicAuth(SUB, c.info.username, topic) { + if !b.CheckTopicAuth(SUB, c.info.clientID, c.info.username, c.info.remoteIP, topic) { log.Error("Sub topic Auth failed: ", zap.String("topic", topic), zap.String("ClientID", c.info.clientID)) retcodes = append(retcodes, QosFailure) continue diff --git a/plugins/auth/auth.go b/plugins/auth/auth.go index ed41120..5f842a9 100644 --- a/plugins/auth/auth.go +++ b/plugins/auth/auth.go @@ -1,11 +1,13 @@ package auth import ( + authfile "github.com/fhmq/hmq/plugins/auth/authfile" "github.com/fhmq/hmq/plugins/auth/authhttp" ) const ( AuthHTTP = "authhttp" + AuthFile = "authfile" ) type Auth interface { @@ -17,6 +19,8 @@ func NewAuth(name string) Auth { switch name { case AuthHTTP: return authhttp.Init() + case AuthFile: + return authfile.Init() default: return &mockAuth{} }