diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2012-09-11 13:09:29 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2012-09-11 13:09:29 +0100 |
| commit | 97da95f1390d401df3e00accd16af43e87f408d2 (patch) | |
| tree | f8e9f7ade493da0970f29d82e695874591a8cc7e /src | |
| parent | d893c71442696f854a3e50f8af872c2c7d475efe (diff) | |
| download | rabbitmq-server-git-97da95f1390d401df3e00accd16af43e87f408d2.tar.gz | |
Remove the previous hack, add a check for the "impersonator" tag instead.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_channel.erl | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 2a08278138..e50e823c7e 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -459,6 +459,21 @@ check_write_permitted(Resource, #ch{user = User}) -> check_read_permitted(Resource, #ch{user = User}) -> check_resource_access(User, Resource, read). +check_user_id_header(#'P_basic'{user_id = undefined}, _) -> + ok; +check_user_id_header(#'P_basic'{user_id = Username}, + #ch{user = #user{username = Username}}) -> + ok; +check_user_id_header(#'P_basic'{user_id = Claimed}, + #ch{user = #user{username = Actual, + tags = Tags}}) -> + case lists:member(impersonator, Tags) of + true -> ok; + false -> precondition_failed( + "user_id property set to '~s' but authenticated user was " + "'~s'", [Claimed, Actual]) + end. + check_internal_exchange(#exchange{name = Name, internal = true}) -> rabbit_misc:protocol_error(access_refused, "cannot publish to internal ~s", @@ -466,21 +481,6 @@ check_internal_exchange(#exchange{name = Name, internal = true}) -> check_internal_exchange(_) -> ok. -ensure_user_id_header(Props = #'P_basic'{user_id = undefined}, _) -> - Props; -%% We rely on the fact that the codec can't express this. So we must -%% be talking to the direct client, which can do anything anyway. -ensure_user_id_header(Props = #'P_basic'{user_id = {trust, Username}}, _) -> - Props#'P_basic'{user_id = Username}; -ensure_user_id_header(Props = #'P_basic'{user_id = Username}, - #ch{user = #user{username = Username}}) -> - Props; -ensure_user_id_header(#'P_basic'{user_id = Claimed}, - #ch{user = #user{username = Actual}}) -> - precondition_failed( - "user_id property set to '~s' but authenticated user was '~s'", - [Claimed, Actual]). - expand_queue_name_shortcut(<<>>, #ch{most_recently_declared_queue = <<>>}) -> rabbit_misc:protocol_error( not_found, "no previously declared queue", []); @@ -612,11 +612,8 @@ handle_method(#'basic.publish'{exchange = ExchangeNameBin, check_internal_exchange(Exchange), %% We decode the content's properties here because we're almost %% certain to want to look at delivery-mode and priority. - DecodedContent0 = rabbit_binary_parser:ensure_content_decoded(Content), - DecodedContent = - DecodedContent0#content{ - properties = ensure_user_id_header( - DecodedContent0#content.properties, State)}, + DecodedContent = rabbit_binary_parser:ensure_content_decoded(Content), + check_user_id_header(DecodedContent#content.properties, State), {MsgSeqNo, State1} = case {TxStatus, ConfirmEnabled} of {none, false} -> {undefined, State}; |
