diff options
| author | Arnaud Cogoluègnes <acogoluegnes@gmail.com> | 2018-03-14 15:36:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-14 15:36:43 +0100 |
| commit | 6c03f0b2b206a7b8749470e7c1c430ae86a787dd (patch) | |
| tree | d3b0f53681701c82c023968baf1742f889fc2e72 | |
| parent | 500d31679603b6eaf9f70ad5237e7ec2070b30b8 (diff) | |
| parent | 0c1a2feb4dc8bec660c6613fb1a32bd849f2cbab (diff) | |
| download | rabbitmq-server-git-6c03f0b2b206a7b8749470e7c1c430ae86a787dd.tar.gz | |
Merge pull request #1544 from rabbitmq/rabbitmq-server-1538-master
Merge rabbitmq-server-1538 to master
| -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 171a4dd8a7..c4cb4e7c13 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -841,24 +841,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 @@ -873,6 +871,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}). |
