mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-04 07:08:32 +00:00
44 lines
759 B
Go
44 lines
759 B
Go
/* Copyright (c) 2018, joy.zhou <chowyu08@gmail.com>
|
|
*/
|
|
package broker
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/fhmq/hmq/plugins/authhttp"
|
|
)
|
|
|
|
const (
|
|
SUB = "1"
|
|
PUB = "2"
|
|
)
|
|
|
|
func (b *Broker) CheckTopicAuth(action, username, topic string) bool {
|
|
if b.pluginAuthHTTP {
|
|
if strings.HasPrefix(topic, "$SYS/broker/connection/clients/") {
|
|
return true
|
|
}
|
|
|
|
if strings.HasPrefix(topic, "$queue/") {
|
|
topic = strings.TrimPrefix(topic, "$queue/")
|
|
}
|
|
|
|
return authhttp.CheckACL(username, action, topic)
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
func (b *Broker) CheckConnectAuth(clientID, username, password string) bool {
|
|
if b.pluginAuthHTTP {
|
|
if clientID == "" || username == "" {
|
|
return false
|
|
}
|
|
return authhttp.CheckAuth(clientID, username, password)
|
|
}
|
|
|
|
return true
|
|
|
|
}
|