fix(channel): add warning log if the acl check of a subscribed topic failed

This commit is contained in:
JimMoen 2022-10-10 16:03:31 +08:00
parent 505507139e
commit 48d8f7e7a9
1 changed files with 5 additions and 2 deletions

View File

@ -1501,12 +1501,15 @@ check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS,
check_sub_acls(TopicFilters, Channel) ->
check_sub_acls(TopicFilters, Channel, []).
check_sub_acls([ TopicFilter = {Topic, _} | More] , Channel, Acc) ->
check_sub_acls([ TopicFilter = {Topic, SubOpts} | More] , Channel, Acc) ->
case check_sub_acl(Topic, Channel) of
allow ->
check_sub_acls(More, Channel, [ {TopicFilter, 0} | Acc]);
deny ->
check_sub_acls(More, Channel, [ {TopicFilter, ?RC_NOT_AUTHORIZED} | Acc])
ReasonCode = ?RC_NOT_AUTHORIZED,
?LOG(warning, "Cannot subscribe ~s with options ~p due to ~s.",
[Topic, SubOpts, emqx_reason_codes:text(ReasonCode)]),
check_sub_acls(More, Channel, [ {TopicFilter, ReasonCode} | Acc])
end;
check_sub_acls([], _Channel, Acc) ->
lists:reverse(Acc).