@@ -48,21 +48,17 @@ check_user_login(Username, AuthProps) ->
48
48
% % extra auth properties like MQTT client id are in AuthProps
49
49
{ok , Modules } = application :get_env (rabbit , auth_backends ),
50
50
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 , _ , _ , _ }) ->
56
58
% % Different modules for authN vs authZ. So authenticate
57
59
% % with authN module, then if that succeeds do
58
60
% % 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 );
66
62
(Mod , {refused , _ , _ , _ }) ->
67
63
% % Same module for authN and authZ. Just take the result
68
64
% % it gives us
@@ -80,6 +76,19 @@ check_user_login(Username, AuthProps) ->
80
76
{refused , Username , " No modules checked '~s '" , [Username ]}, Modules ),
81
77
R .
82
78
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
+
83
92
try_authenticate (Module , Username , AuthProps ) ->
84
93
case Module :user_login_authentication (Username , AuthProps ) of
85
94
{ok , AuthUser } -> {ok , AuthUser };
0 commit comments