Skip to content

Commit d1adcf5

Browse files
Merge pull request #2323 from rabbitmq/rabbitmq-server-2322
Run both authn and authz steps when rabbit_auth_backend_cache module … (cherry picked from commit c9e9509)
1 parent 1213dc8 commit d1adcf5

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/rabbit_access_control.erl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,17 @@ check_user_login(Username, AuthProps) ->
4848
%% extra auth properties like MQTT client id are in AuthProps
4949
{ok, Modules} = application:get_env(rabbit, auth_backends),
5050
R = lists:foldl(
51-
fun ({ModN, ModZs0}, {refused, _, _, _}) ->
52-
ModZs = case ModZs0 of
53-
A when is_atom(A) -> [A];
54-
L when is_list(L) -> L
55-
end,
51+
fun (rabbit_auth_backend_cache=ModN, {refused, _, _, _}) ->
52+
%% It is possible to specify authn/authz within the cache module settings,
53+
%% so we have to do both auth steps here
54+
%% See this rabbitmq-users discussion:
55+
%% https://groups.google.com/d/topic/rabbitmq-users/ObqM7MQdA3I/discussion
56+
try_authenticate_and_try_authorize(ModN, ModN, Username, AuthProps);
57+
({ModN, ModZs}, {refused, _, _, _}) ->
5658
%% Different modules for authN vs authZ. So authenticate
5759
%% with authN module, then if that succeeds do
5860
%% passwordless (i.e pre-authenticated) login with authZ.
59-
case try_authenticate(ModN, Username, AuthProps) of
60-
{ok, ModNUser = #auth_user{username = Username2}} ->
61-
rabbit_log:debug("User '~s' authenticated successfully by backend ~s", [Username2, ModN]),
62-
user(ModNUser, try_authorize(ModZs, Username2, AuthProps));
63-
Else ->
64-
Else
65-
end;
61+
try_authenticate_and_try_authorize(ModN, ModZs, Username, AuthProps);
6662
(Mod, {refused, _, _, _}) ->
6763
%% Same module for authN and authZ. Just take the result
6864
%% it gives us
@@ -80,6 +76,19 @@ check_user_login(Username, AuthProps) ->
8076
{refused, Username, "No modules checked '~s'", [Username]}, Modules),
8177
R.
8278

79+
try_authenticate_and_try_authorize(ModN, ModZs0, Username, AuthProps) ->
80+
ModZs = case ModZs0 of
81+
A when is_atom(A) -> [A];
82+
L when is_list(L) -> L
83+
end,
84+
case try_authenticate(ModN, Username, AuthProps) of
85+
{ok, ModNUser = #auth_user{username = Username2}} ->
86+
rabbit_log:debug("User '~s' authenticated successfully by backend ~s", [Username2, ModN]),
87+
user(ModNUser, try_authorize(ModZs, Username2, AuthProps));
88+
Else ->
89+
Else
90+
end.
91+
8392
try_authenticate(Module, Username, AuthProps) ->
8493
case Module:user_login_authentication(Username, AuthProps) of
8594
{ok, AuthUser} -> {ok, AuthUser};

0 commit comments

Comments
 (0)