mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-22 09:48:33 +00:00
fixbug
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user