@@ -183,7 +183,7 @@ process_connect(
183
183
maybe
184
184
ok ?= check_extended_auth (ConnectProps ),
185
185
{ok , ClientId } ?= ensure_client_id (ClientId0 , CleanStart , ProtoVer ),
186
- {ok , { Username1 , Password } } ?= check_credentials (Username0 , Password0 , SslLoginName , PeerIp ),
186
+ {ok , Username1 , Password } ?= check_credentials (Username0 , Password0 , SslLoginName , PeerIp ),
187
187
188
188
{VHostPickedUsing , {VHost , Username2 }} = get_vhost (Username1 , SslLoginName , Port ),
189
189
? LOG_DEBUG (" MQTT connection ~s picked vhost using ~s " , [ConnName0 , VHostPickedUsing ]),
@@ -626,6 +626,8 @@ check_extended_auth(_) ->
626
626
627
627
check_credentials (Username , Password , SslLoginName , PeerIp ) ->
628
628
case creds (Username , Password , SslLoginName ) of
629
+ {ok , _ , _ } = Ok ->
630
+ Ok ;
629
631
nocreds ->
630
632
? LOG_ERROR (" MQTT login failed: no credentials provided" ),
631
633
auth_attempt_failed (PeerIp , <<>>),
@@ -637,9 +639,7 @@ check_credentials(Username, Password, SslLoginName, PeerIp) ->
637
639
{invalid_creds , {User , _Pass }} when is_binary (User ) ->
638
640
? LOG_ERROR (" MQTT login failed for user '~s ': no password provided" , [User ]),
639
641
auth_attempt_failed (PeerIp , User ),
640
- {error , ? RC_BAD_USER_NAME_OR_PASSWORD };
641
- {UserBin , PassBin } ->
642
- {ok , {UserBin , PassBin }}
642
+ {error , ? RC_BAD_USER_NAME_OR_PASSWORD }
643
643
end .
644
644
645
645
-spec ensure_client_id (client_id (), boolean (), protocol_version ()) ->
@@ -1201,29 +1201,37 @@ get_vhost_from_port_mapping(Port, Mapping) ->
1201
1201
Res .
1202
1202
1203
1203
creds (User , Pass , SSLLoginName ) ->
1204
- DefaultUser = rabbit_mqtt_util :env (default_user ),
1205
- DefaultPass = rabbit_mqtt_util :env (default_pass ),
1206
- {ok , Anon } = application :get_env (? APP_NAME , allow_anonymous ),
1207
- {ok , TLSAuth } = application :get_env (? APP_NAME , ssl_cert_login ),
1208
- HaveDefaultCreds = Anon =:= true andalso
1209
- is_binary (DefaultUser ) andalso
1210
- is_binary (DefaultPass ),
1211
-
1212
1204
CredentialsProvided = User =/= undefined orelse Pass =/= undefined ,
1213
- CorrectCredentials = is_binary (User ) andalso is_binary (Pass ) andalso Pass =/= <<>>,
1205
+ ValidCredentials = is_binary (User ) andalso is_binary (Pass ) andalso Pass =/= <<>>,
1206
+ {ok , TLSAuth } = application :get_env (? APP_NAME , ssl_cert_login ),
1214
1207
SSLLoginProvided = TLSAuth =:= true andalso SSLLoginName =/= none ,
1215
1208
1216
- case {CredentialsProvided , CorrectCredentials , SSLLoginProvided , HaveDefaultCreds } of
1217
- % % Username and password take priority
1218
- {true , true , _ , _ } -> {User , Pass };
1219
- % % Either username or password is provided
1220
- {true , false , _ , _ } -> {invalid_creds , {User , Pass }};
1221
- % % rabbitmq_mqtt.ssl_cert_login is true. SSL user name provided.
1222
- % % Authenticating using username only.
1223
- {false , false , true , _ } -> {SSLLoginName , none };
1224
- % % Anonymous connection uses default credentials
1225
- {false , false , false , true } -> {DefaultUser , DefaultPass };
1226
- _ -> nocreds
1209
+ case {CredentialsProvided , ValidCredentials , SSLLoginProvided } of
1210
+ {true , true , _ } ->
1211
+ % % Username and password take priority
1212
+ {ok , User , Pass };
1213
+ {true , false , _ } ->
1214
+ % % Either username or password is provided
1215
+ {invalid_creds , {User , Pass }};
1216
+ {false , false , true } ->
1217
+ % % rabbitmq_mqtt.ssl_cert_login is true. SSL user name provided.
1218
+ % % Authenticating using username only.
1219
+ {ok , SSLLoginName , none };
1220
+ {false , false , false } ->
1221
+ {ok , AllowAnon } = application :get_env (? APP_NAME , allow_anonymous ),
1222
+ case AllowAnon of
1223
+ true ->
1224
+ case rabbit_auth_mechanism_anonymous :credentials () of
1225
+ {ok , _ , _ } = Ok ->
1226
+ Ok ;
1227
+ error ->
1228
+ nocreds
1229
+ end ;
1230
+ false ->
1231
+ nocreds
1232
+ end ;
1233
+ _ ->
1234
+ nocreds
1227
1235
end .
1228
1236
1229
1237
-spec auth_attempt_failed (inet :ip_address (), binary ()) -> ok .
0 commit comments