Enable cert_as_username to pass value to username_as_clientid (#2536)

This commit is contained in:
JianBo He 2019-05-15 10:20:04 +08:00 committed by tigercl
parent 79c1b7eb78
commit 1a92f3259f
1 changed files with 18 additions and 17 deletions

View File

@ -381,21 +381,22 @@ process(?CONNECT_PACKET(
username = Username, username = Username,
password = Password} = ConnPkt), PState) -> password = Password} = ConnPkt), PState) ->
NewClientId = maybe_use_username_as_clientid(ClientId, Username, PState),
emqx_logger:set_metadata_client_id(NewClientId),
%% TODO: Mountpoint... %% TODO: Mountpoint...
%% Msg -> emqx_mountpoint:mount(MountPoint, Msg) %% Msg -> emqx_mountpoint:mount(MountPoint, Msg)
PState0 = set_username(Username, PState0 = maybe_use_username_as_clientid(ClientId,
PState#pstate{client_id = NewClientId, set_username(Username,
proto_ver = ProtoVer, PState#pstate{proto_ver = ProtoVer,
proto_name = ProtoName, proto_name = ProtoName,
clean_start = CleanStart, clean_start = CleanStart,
keepalive = Keepalive, keepalive = Keepalive,
conn_props = ConnProps, conn_props = ConnProps,
is_bridge = IsBridge, is_bridge = IsBridge,
connected_at = os:timestamp()}), connected_at = os:timestamp()})),
NewClientId = PState0#pstate.client_id,
emqx_logger:set_metadata_client_id(NewClientId),
Credentials = credentials(PState0), Credentials = credentials(PState0),
PState1 = PState0#pstate{credentials = Credentials}, PState1 = PState0#pstate{credentials = Credentials},
connack( connack(
@ -706,12 +707,12 @@ send(Packet = ?PACKET(Type), PState = #pstate{proto_ver = Ver, sendfun = Send})
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Maybe use username replace client id %% Maybe use username replace client id
maybe_use_username_as_clientid(ClientId, undefined, _PState) -> maybe_use_username_as_clientid(ClientId, PState = #pstate{username = undefined}) ->
ClientId; PState#pstate{client_id = ClientId};
maybe_use_username_as_clientid(ClientId, Username, #pstate{zone = Zone}) -> maybe_use_username_as_clientid(ClientId, PState = #pstate{username = Username, zone = Zone}) ->
case emqx_zone:get_env(Zone, use_username_as_clientid, false) of case emqx_zone:get_env(Zone, use_username_as_clientid, false) of
true -> Username; true -> PState#pstate{client_id = Username};
false -> ClientId false -> PState#pstate{client_id = ClientId}
end. end.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------