This commit is contained in:
joy.zhou
2019-07-15 18:29:45 +08:00
parent e945b35c91
commit 9fef7b668d
2 changed files with 8 additions and 13 deletions

View File

@@ -18,9 +18,9 @@ func (c *client) CheckTopicAuth(typ int, topic string) bool {
access := "sub" access := "sub"
switch typ { switch typ {
case 1: case 1:
access = "pub" access = "2"
case 2: case 2:
access = "sub" access = "1"
} }
username := string(c.info.username) username := string(c.info.username)
return authhttp.CheckACL(username, access, topic) return authhttp.CheckACL(username, access, topic)

View File

@@ -114,23 +114,18 @@ func CheckSuper(clientID, username, password string) bool {
//CheckACL check mqtt connect //CheckACL check mqtt connect
func CheckACL(username, access, topic string) bool { func CheckACL(username, access, topic string) bool {
data := url.Values{} req, err := http.NewRequest("GET", config.ACLURL, nil)
data.Add("username", username)
data.Add("topic", topic)
data.Add("access", access)
req, err := http.NewRequest("GET", config.ACLURL, strings.NewReader(data.Encode()))
if err != nil { if err != nil {
log.Error("get acl: ", zap.Error(err)) log.Error("get acl: ", zap.Error(err))
return false return false
} }
// data := req.URL.Query() data := req.URL.Query()
// data.Add("username", username) data.Add("username", username)
// data.Add("topic", topic) data.Add("topic", topic)
// data.Add("access", access) data.Add("access", access)
// req.URL.RawQuery = data.Encode() req.URL.RawQuery = data.Encode()
// fmt.Println("req:", req) // fmt.Println("req:", req)
resp, err := httpClient.Do(req) resp, err := httpClient.Do(req)
if err != nil { if err != nil {