挂载回调函数到 client.authenticate 钩子:

    钩子回调函数必须接受一个 Credentials 参数,并且返回一个新的 Credentials:

    1. on_client_authenticate(Credentials = #{password := Password}) ->
    2. {ok, Credentials#{result => success}}.

    编写 ACL 钩子回调函数

    挂载回调函数到 client.authenticate 钩子:

    1. emqx:hook('client.check_acl', fun ?MODULE:on_client_check_acl/4, []).

    回调函数必须可接受 Credentials , AccessType , Topic , ACLResult 这几个参数, 然后返回一个新的 ACLResult:

    emqx_mod_acl_internal 模块实现了基于 etc/acl.conf 文件的 ACL 机制,etc/acl.conf 文件的默认内容:

    1. %%%-----------------------------------------------------------------------------
    2. %%%
    3. %%% -type who() :: all | binary() |
    4. %%% {ipaddr, esockd_access:cidr()} |
    5. %%% {user, binary()}.
    6. %%%
    7. %%% -type access() :: subscribe | publish | pubsub.
    8. %%%
    9. %%% -type topic() :: binary().
    10. %%% -type rule() :: {allow, all} |
    11. %%% {allow, who(), access(), list(topic())} |
    12. %%% {deny, all} |
    13. %%%
    14. %%%-----------------------------------------------------------------------------
    15. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
    16. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
    17. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

    由 emqx 提供的 Auth/ACL 插件: