* update

* update auth file

* fixbug
This commit is contained in:
joy.zhou
2019-11-11 11:41:38 +08:00
committed by GitHub
parent 896769fd9d
commit 4c107c67ab
3 changed files with 8 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ const (
PUB = "2" 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 b.auth != nil {
if strings.HasPrefix(topic, "$SYS/broker/connection/clients/") { if strings.HasPrefix(topic, "$SYS/broker/connection/clients/") {
return true return true
@@ -25,7 +25,7 @@ func (b *Broker) CheckTopicAuth(action, username, topic string) bool {
topic = substr[2] topic = substr[2]
} }
return b.auth.CheckACL(action, username, topic) return b.auth.CheckACL(action, clientID, username, ip, topic)
} }
return true return true

View File

@@ -242,7 +242,7 @@ func (c *client) processClientPublish(packet *packets.PublishPacket) {
topic := packet.TopicName 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)) log.Error("Pub Topics Auth failed, ", zap.String("topic", topic), zap.String("ClientID", c.info.clientID))
return return
} }
@@ -357,7 +357,7 @@ func (c *client) processClientSubscribe(packet *packets.SubscribePacket) {
for i, topic := range topics { for i, topic := range topics {
t := topic t := topic
//check topic auth for client //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)) log.Error("Sub topic Auth failed: ", zap.String("topic", topic), zap.String("ClientID", c.info.clientID))
retcodes = append(retcodes, QosFailure) retcodes = append(retcodes, QosFailure)
continue continue

View File

@@ -1,11 +1,13 @@
package auth package auth
import ( import (
authfile "github.com/fhmq/hmq/plugins/auth/authfile"
"github.com/fhmq/hmq/plugins/auth/authhttp" "github.com/fhmq/hmq/plugins/auth/authhttp"
) )
const ( const (
AuthHTTP = "authhttp" AuthHTTP = "authhttp"
AuthFile = "authfile"
) )
type Auth interface { type Auth interface {
@@ -17,6 +19,8 @@ func NewAuth(name string) Auth {
switch name { switch name {
case AuthHTTP: case AuthHTTP:
return authhttp.Init() return authhttp.Init()
case AuthFile:
return authfile.Init()
default: default:
return &mockAuth{} return &mockAuth{}
} }