EMQ插件开发mysql实现认证和访问控制

来源:互联网 发布:mac谷歌浏览器安插件 编辑:程序博客网 时间:2024/05/16 19:48

为了测试插件开发的可行性,选择了改名emq_auth_mysql进行验证,因为官方给出的插件模板并没有具体逻辑。


include下的hrl改名


etc下的conf和priv下的schema是相互照应的,进行改名


src的源文件与上篇文章改名类似


Makefile中


PROJECT = emq_custom_mysql

app.config::
./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/emq_custom_mysql.conf -i priv/emq_custom_mysql.schema -d data


与上篇类似,,git源代码,,更改makefile relx.config等


开启插件,,,进入conf下配置数据库信息


使用mosquitto 进行测试


mosquitto_sub [-A bind_address] [-c] [-C msg count] [-d] [-h hostname] [-i client_id] [-I client id prefix] [-k keepalive time] [-p port number] [-q message QoS] [-R] [-S] [-N] [--quiet] [-v] [ [-u username] [-P password] ] [ --will-topic topic [--will-payload payload] [--will-qos qos] [--will-retain] ] [[ { --cafile file | --capath dir } [--cert file] [--key file] [--tls-version version] [--insecure] ] | [ --psk hex-key --psk-identity identity [--tls-version version] ]] [--proxy socks-url] [-V protocol-version] [-T filter-out...] -t message-topic...


mosquitto_sub [--help]

详细请见:https://mosquitto.org/man/mosquitto_sub-1.html


首先应该在  给出的mqtt_user 插入几个测试用户。 主要就是用来判断用户名和密码,在配置文件里,auth.custom.password_hash = plain(明文)

可以设置加密方式。


[root@localhost ~]# mosquitto_sub -u *** -P 12345 -q 1 -t topic
Connection Refused: bad user name or password.

密码输错时:

说明插件已经生效


发布:

# mosquitto_pub -u *** -P 123 -t topic -q 1 -m "hi"
^C
[root@localhost ~]# mosquitto_pub -u haha -P 123 -t topic -q 1 -m "helloworld"
Connection Refused: bad user name or password.
Error: The connection was refused.
[root@localhost ~]# mosquitto_pub -u haha -P 1234 -t topic -q 1 -m "helloworld

订阅:

 mosquitto_sub -u *** -P 123 -t topic -q 2
hi
helloworld

订阅某个主题时并有订阅这个主题权限时候会订阅成功,,,发布者发布关于这个主题的消息内容时候, 会收到消息


***是马赛克,不是用户名


阅读全文
0 0
原创粉丝点击