mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-24 10:38:34 +00:00
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user