@@ -1178,65 +1178,56 @@ get_vhost(UserBin, SslLogin, Port) ->
11781178 get_vhost_ssl (UserBin , SslLogin , Port ).
11791179
11801180get_vhost_no_ssl (UserBin , Port ) ->
1181- case vhost_in_username (UserBin ) of
1182- true ->
1183- {vhost_in_username_or_default , get_vhost_username (UserBin )};
1184- false ->
1185- PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1186- mqtt_port_to_vhost_mapping
1187- ),
1188- case get_vhost_from_port_mapping (Port , PortVirtualHostMapping ) of
1181+ case get_vhost_username (UserBin ) of
1182+ undefined ->
1183+ case get_vhost_from_port_mapping (Port ) of
11891184 undefined ->
1190- {plugin_configuration_or_default_vhost , {rabbit_mqtt_util :env (vhost ), UserBin }};
1191- VHost ->
1192- {port_to_vhost_mapping , {VHost , UserBin }}
1193- end
1185+ VhostFromConfig = rabbit_mqtt_util :env (vhost ),
1186+ {plugin_configuration_or_default_vhost , {VhostFromConfig , UserBin }};
1187+ VHostFromPortMapping ->
1188+ {port_to_vhost_mapping , {VHostFromPortMapping , UserBin }}
1189+ end ;
1190+ VHostUser ->
1191+ {vhost_in_username , VHostUser }
11941192 end .
11951193
11961194get_vhost_ssl (UserBin , SslLoginName , Port ) ->
1197- UserVirtualHostMapping = rabbit_runtime_parameters :value_global (
1198- mqtt_default_vhosts
1199- ),
1200- case get_vhost_from_user_mapping (SslLoginName , UserVirtualHostMapping ) of
1195+ case get_vhost_from_user_mapping (SslLoginName ) of
12011196 undefined ->
1202- PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1203- mqtt_port_to_vhost_mapping
1204- ),
1205- case get_vhost_from_port_mapping (Port , PortVirtualHostMapping ) of
1197+ case get_vhost_from_port_mapping (Port ) of
12061198 undefined ->
1207- {vhost_in_username_or_default , get_vhost_username (UserBin )};
1199+ case get_vhost_username (UserBin ) of
1200+ undefined ->
1201+ VhostFromConfig = rabbit_mqtt_util :env (vhost ),
1202+ {plugin_configuration_or_default_vhost , {VhostFromConfig , UserBin }};
1203+ VHostUser ->
1204+ {vhost_in_username , VHostUser }
1205+ end ;
12081206 VHostFromPortMapping ->
12091207 {port_to_vhost_mapping , {VHostFromPortMapping , UserBin }}
12101208 end ;
12111209 VHostFromCertMapping ->
12121210 {client_cert_to_vhost_mapping , {VHostFromCertMapping , UserBin }}
12131211 end .
12141212
1215- vhost_in_username (UserBin ) ->
1216- case application :get_env (? APP_NAME , ignore_colons_in_username ) of
1217- {ok , true } -> false ;
1218- _ ->
1219- % % split at the last colon, disallowing colons in username
1220- case re :split (UserBin , " :(?!.*?:)" ) of
1221- [_ , _ ] -> true ;
1222- [UserBin ] -> false ;
1223- [] -> false
1224- end
1225- end .
1226-
12271213get_vhost_username (UserBin ) ->
1228- Default = {rabbit_mqtt_util :env (vhost ), UserBin },
12291214 case application :get_env (? APP_NAME , ignore_colons_in_username ) of
1230- {ok , true } -> Default ;
1215+ {ok , true } -> undefined ;
12311216 _ ->
12321217 % % split at the last colon, disallowing colons in username
12331218 case re :split (UserBin , " :(?!.*?:)" ) of
12341219 [Vhost , UserName ] -> {Vhost , UserName };
1235- [UserBin ] -> Default ;
1236- [] -> Default
1220+ [UserBin ] -> undefined ;
1221+ [] -> undefined
12371222 end
12381223 end .
12391224
1225+ get_vhost_from_user_mapping (User ) ->
1226+ UserVirtualHostMapping = rabbit_runtime_parameters :value_global (
1227+ mqtt_default_vhosts
1228+ ),
1229+ get_vhost_from_user_mapping (User , UserVirtualHostMapping ).
1230+
12401231get_vhost_from_user_mapping (_User , not_found ) ->
12411232 undefined ;
12421233get_vhost_from_user_mapping (User , Mapping ) ->
@@ -1248,6 +1239,12 @@ get_vhost_from_user_mapping(User, Mapping) ->
12481239 VHost
12491240 end .
12501241
1242+ get_vhost_from_port_mapping (Port ) ->
1243+ PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1244+ mqtt_port_to_vhost_mapping
1245+ ),
1246+ get_vhost_from_port_mapping (Port , PortVirtualHostMapping ).
1247+
12511248get_vhost_from_port_mapping (_Port , not_found ) ->
12521249 undefined ;
12531250get_vhost_from_port_mapping (Port , Mapping ) ->
0 commit comments