This commit is contained in:
joy.zhou
2019-11-11 11:40:48 +08:00
parent 716614e626
commit 8eb18410d6
3 changed files with 8 additions and 4 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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{}
}