Android 聊天应用程序的 MQTT/限制主题访问

MQTT for Android chat applications / Limiting topic access

我正在尝试使用 MQTT 创建 android 的聊天应用程序,但有关如何操作的信息有限。

到目前为止,我已经设置了 MQTT 代理,但任何用户都可以收听和发布他们喜欢的任何主题(当然这不是聊天应用程序想要的)。

我使用 mosquitto 作为我的代理,它在其文档中列出了这组功能:

Topic access is added with lines of the format:

topic [read|write|readwrite] <topic>

It is also possible to define ACLs based on pattern substitution within the topic. The form is the same as for the topic keyword, but using pattern as the keyword.

pattern [read|write|readwrite] <topic>

The patterns available for substition are:

%c to match the client id of the client

%u to match the username of the client

The substitution pattern must be the only text for that level of hierarchy. Pattern ACLs apply to all users even if the "user" keyword has previously been given.

Example:

pattern write sensor/%u/data

Allow access for bridge connection messages:

pattern write $SYS/broker/connection/%c/state

到目前为止,我想做的事情如下: pattern readwrite chat/%u/msg

但这限制了每个用户 read/write 讨论他们自己的主题,这不是预期的行为。

所以我的问题是:

有没有办法即时设置主题权限?

如何确保例如在 A-B-C 之间的聊天中有一个 A-B-C 的主题 只有 A-B-C 可以读写?

不使用 ACL 文件,但 mosquitto 支持 ACL 的插件系统

例如https://github.com/jpmens/mosquitto-auth-plug/

这允许您将 ACL 存储在可以动态更新的数据库中