summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bakken <lbakken@pivotal.io>2018-03-06 10:21:18 -0800
committerLuke Bakken <lbakken@pivotal.io>2018-03-06 10:21:18 -0800
commit0c1a2feb4dc8bec660c6613fb1a32bd849f2cbab (patch)
treeb7082942c4a198973d38b20441a6b4bb120147a5
parente3ba0b51b1754427594cc0b0e6c2064b6efc280f (diff)
parent5b5b06be3b9dde1032d366744da653acbb444b61 (diff)
downloadrabbitmq-server-git-0c1a2feb4dc8bec660c6613fb1a32bd849f2cbab.tar.gz
Merge branch 'rabbitmq-server-1538' into rabbitmq-server-1538-master
-rw-r--r--src/rabbit_channel.erl38
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}).