@@ -1185,65 +1185,56 @@ get_vhost(UserBin, SslLogin, Port) ->
11851185 get_vhost_ssl (UserBin , SslLogin , Port ).
11861186
11871187get_vhost_no_ssl (UserBin , Port ) ->
1188- case vhost_in_username (UserBin ) of
1189- true ->
1190- {vhost_in_username_or_default , get_vhost_username (UserBin )};
1191- false ->
1192- PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1193- mqtt_port_to_vhost_mapping
1194- ),
1195- case get_vhost_from_port_mapping (Port , PortVirtualHostMapping ) of
1188+ case get_vhost_username (UserBin ) of
1189+ undefined ->
1190+ case get_vhost_from_port_mapping (Port ) of
11961191 undefined ->
1197- {plugin_configuration_or_default_vhost , {rabbit_mqtt_util :env (vhost ), UserBin }};
1198- VHost ->
1199- {port_to_vhost_mapping , {VHost , UserBin }}
1200- end
1192+ VhostFromConfig = rabbit_mqtt_util :env (vhost ),
1193+ {plugin_configuration_or_default_vhost , {VhostFromConfig , UserBin }};
1194+ VHostFromPortMapping ->
1195+ {port_to_vhost_mapping , {VHostFromPortMapping , UserBin }}
1196+ end ;
1197+ VHostUser ->
1198+ {vhost_in_username , VHostUser }
12011199 end .
12021200
12031201get_vhost_ssl (UserBin , SslLoginName , Port ) ->
1204- UserVirtualHostMapping = rabbit_runtime_parameters :value_global (
1205- mqtt_default_vhosts
1206- ),
1207- case get_vhost_from_user_mapping (SslLoginName , UserVirtualHostMapping ) of
1202+ case get_vhost_from_user_mapping (SslLoginName ) of
12081203 undefined ->
1209- PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1210- mqtt_port_to_vhost_mapping
1211- ),
1212- case get_vhost_from_port_mapping (Port , PortVirtualHostMapping ) of
1204+ case get_vhost_from_port_mapping (Port ) of
12131205 undefined ->
1214- {vhost_in_username_or_default , get_vhost_username (UserBin )};
1206+ case get_vhost_username (UserBin ) of
1207+ undefined ->
1208+ VhostFromConfig = rabbit_mqtt_util :env (vhost ),
1209+ {plugin_configuration_or_default_vhost , {VhostFromConfig , UserBin }};
1210+ VHostUser ->
1211+ {vhost_in_username , VHostUser }
1212+ end ;
12151213 VHostFromPortMapping ->
12161214 {port_to_vhost_mapping , {VHostFromPortMapping , UserBin }}
12171215 end ;
12181216 VHostFromCertMapping ->
12191217 {client_cert_to_vhost_mapping , {VHostFromCertMapping , UserBin }}
12201218 end .
12211219
1222- vhost_in_username (UserBin ) ->
1223- case application :get_env (? APP_NAME , ignore_colons_in_username ) of
1224- {ok , true } -> false ;
1225- _ ->
1226- % % split at the last colon, disallowing colons in username
1227- case re :split (UserBin , " :(?!.*?:)" ) of
1228- [_ , _ ] -> true ;
1229- [UserBin ] -> false ;
1230- [] -> false
1231- end
1232- end .
1233-
12341220get_vhost_username (UserBin ) ->
1235- Default = {rabbit_mqtt_util :env (vhost ), UserBin },
12361221 case application :get_env (? APP_NAME , ignore_colons_in_username ) of
1237- {ok , true } -> Default ;
1222+ {ok , true } -> undefined ;
12381223 _ ->
12391224 % % split at the last colon, disallowing colons in username
12401225 case re :split (UserBin , " :(?!.*?:)" ) of
12411226 [Vhost , UserName ] -> {Vhost , UserName };
1242- [UserBin ] -> Default ;
1243- [] -> Default
1227+ [UserBin ] -> undefined ;
1228+ [] -> undefined
12441229 end
12451230 end .
12461231
1232+ get_vhost_from_user_mapping (User ) ->
1233+ UserVirtualHostMapping = rabbit_runtime_parameters :value_global (
1234+ mqtt_default_vhosts
1235+ ),
1236+ get_vhost_from_user_mapping (User , UserVirtualHostMapping ).
1237+
12471238get_vhost_from_user_mapping (_User , not_found ) ->
12481239 undefined ;
12491240get_vhost_from_user_mapping (User , Mapping ) ->
@@ -1255,6 +1246,12 @@ get_vhost_from_user_mapping(User, Mapping) ->
12551246 VHost
12561247 end .
12571248
1249+ get_vhost_from_port_mapping (Port ) ->
1250+ PortVirtualHostMapping = rabbit_runtime_parameters :value_global (
1251+ mqtt_port_to_vhost_mapping
1252+ ),
1253+ get_vhost_from_port_mapping (Port , PortVirtualHostMapping ).
1254+
12581255get_vhost_from_port_mapping (_Port , not_found ) ->
12591256 undefined ;
12601257get_vhost_from_port_mapping (Port , Mapping ) ->
0 commit comments