diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_channel.erl | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 1de367e70c..a8a64f1c10 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -840,24 +840,22 @@ check_internal_exchange(#exchange{name = Name, internal = true}) -> check_internal_exchange(_) -> ok. +check_topic_authorisation(Resource = #exchange{type = topic}, + User, none, RoutingKey, Permission) -> + %% Called from outside the channel by mgmt API + AmqpParams = [], + check_topic_authorisation(Resource, User, AmqpParams, RoutingKey, Permission); +check_topic_authorisation(Resource = #exchange{type = topic}, + User, ConnPid, RoutingKey, Permission) when is_pid(ConnPid) -> + AmqpParams = get_amqp_params(ConnPid), + check_topic_authorisation(Resource, User, AmqpParams, RoutingKey, Permission); check_topic_authorisation(#exchange{name = Name = #resource{virtual_host = VHost}, type = topic}, User = #user{username = Username}, - ConnPid, - RoutingKey, - Permission) -> + AmqpParams, RoutingKey, Permission) -> Resource = Name#resource{kind = topic}, - Timeout = get_operation_timeout(), - AmqpParams = case ConnPid of - none -> - %% Called from outside the channel by mgmt API - []; - _ -> - rabbit_amqp_connection:amqp_params(ConnPid, Timeout) - end, VariableMap = build_topic_variable_map(AmqpParams, VHost, Username), - Context = #{routing_key => RoutingKey, - variable_map => VariableMap - }, + Context = #{routing_key => RoutingKey, + variable_map => VariableMap}, Cache = case get(topic_permission_cache) of undefined -> []; Other -> Other @@ -872,6 +870,18 @@ check_topic_authorisation(#exchange{name = Name = #resource{virtual_host = VHost check_topic_authorisation(_, _, _, _, _) -> ok. +get_amqp_params(ConnPid) when is_pid(ConnPid) -> + Timeout = get_operation_timeout(), + get_amqp_params(ConnPid, rabbit_misc:is_process_alive(ConnPid), Timeout). + +get_amqp_params(ConnPid, false, _Timeout) -> + %% Connection process is dead + rabbit_log_channel:debug("file ~p, line ~p - connection process not alive: ~p~n", + [?FILE, ?LINE, ConnPid]), + []; +get_amqp_params(ConnPid, true, Timeout) -> + rabbit_amqp_connection:amqp_params(ConnPid, Timeout). + build_topic_variable_map(AmqpParams, VHost, Username) -> VariableFromAmqpParams = extract_topic_variable_map_from_amqp_params(AmqpParams), maps:merge(VariableFromAmqpParams, #{<<"vhost">> => VHost, <<"username">> => Username}). |
