diff options
| author | Michael Klishin <michael@novemberain.com> | 2017-06-27 17:37:54 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-27 17:37:54 +0300 |
| commit | f74855c1e3b0d5dfb2f723bdbfd6ceec6913442c (patch) | |
| tree | a6463cfe2dfb0b8a0f3330b140393915c3ac45bb /src | |
| parent | 1b2aeacbf9d84a40c9f7d7786f03450df3bdb7d3 (diff) | |
| parent | b1c86ad2896ba24df9ea69a5b0f68fc5124d80ae (diff) | |
| download | rabbitmq-server-git-f74855c1e3b0d5dfb2f723bdbfd6ceec6913442c.tar.gz | |
Merge pull request #1274 from rabbitmq/rabbitmq-mqtt-139
Pass in extra arguments to authentication backend
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_direct.erl | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/rabbit_direct.erl b/src/rabbit_direct.erl index 19fc828a52..4b7f06305a 100644 --- a/src/rabbit_direct.erl +++ b/src/rabbit_direct.erl @@ -21,6 +21,9 @@ %% Internal -export([list_local/0]). +%% For testing only +-export([extract_extra_auth_props/4]). + -include("rabbit.hrl"). %%---------------------------------------------------------------------------- @@ -65,21 +68,22 @@ list() -> %%---------------------------------------------------------------------------- -auth_fun({none, _}, _VHost) -> +auth_fun({none, _}, _VHost, _ExtraAuthProps) -> fun () -> {ok, rabbit_auth_backend_dummy:user()} end; -auth_fun({Username, none}, _VHost) -> +auth_fun({Username, none}, _VHost, _ExtraAuthProps) -> fun () -> rabbit_access_control:check_user_login(Username, []) end; -auth_fun({Username, Password}, VHost) -> +auth_fun({Username, Password}, VHost, ExtraAuthProps) -> fun () -> rabbit_access_control:check_user_login( Username, - [{password, Password}, {vhost, VHost}]) + [{password, Password}, {vhost, VHost}] ++ ExtraAuthProps) end. connect(Creds, VHost, Protocol, Pid, Infos) -> - AuthFun = auth_fun(Creds, VHost), + ExtraAuthProps = extract_extra_auth_props(Creds, VHost, Pid, Infos), + AuthFun = auth_fun(Creds, VHost, ExtraAuthProps), case rabbit:is_running() of true -> case is_over_connection_limit(VHost, Creds, Pid) of @@ -101,6 +105,42 @@ connect(Creds, VHost, Protocol, Pid, Infos) -> false -> {error, broker_not_found_on_node} end. +extract_extra_auth_props(Creds, VHost, Pid, Infos) -> + case extract_protocol(Infos) of + undefined -> + []; + Protocol -> + maybe_call_connection_info_module(Protocol, Creds, VHost, Pid, Infos) + end. + +extract_protocol(Infos) -> + case proplists:get_value(protocol, Infos, undefined) of + {Protocol, _Version} -> + Protocol; + _ -> + undefined + end. + +maybe_call_connection_info_module(Protocol, Creds, VHost, Pid, Infos) -> + Module = rabbit_data_coercion:to_atom(string:to_lower( + "rabbit_" ++ rabbit_data_coercion:to_list(Protocol) ++ "_connection_info") + ), + case code:get_object_code(Module) of + {_Module, _Binary, _Filename} -> + try + Module:additional_authn_params(Creds, VHost, Pid, Infos) + catch + _:Reason -> + rabbit_log:error("Calling ~p:additional_authn_params/4 failed:~p~n", [Module, Reason]), + [] + end; + error -> + []; + _ -> + [] + end. + + is_over_connection_limit(VHost, {Username, _Password}, Pid) -> PrintedUsername = case Username of none -> ""; |
