fix(stomp): fix anonymous not working
This commit is contained in:
parent
3d9054d25e
commit
d2b6a95484
|
@ -77,19 +77,19 @@ init(#{peername := Peername,
|
||||||
AllowAnonymous = get_value(allow_anonymous, Env, false),
|
AllowAnonymous = get_value(allow_anonymous, Env, false),
|
||||||
DefaultUser = get_value(default_user, Env),
|
DefaultUser = get_value(default_user, Env),
|
||||||
#pstate{peername = Peername,
|
#pstate{peername = Peername,
|
||||||
heartfun = HeartFun,
|
heartfun = HeartFun,
|
||||||
sendfun = SendFun,
|
sendfun = SendFun,
|
||||||
timers = #{},
|
timers = #{},
|
||||||
transaction = #{},
|
transaction = #{},
|
||||||
allow_anonymous = AllowAnonymous,
|
allow_anonymous = AllowAnonymous,
|
||||||
default_user = DefaultUser}.
|
default_user = DefaultUser}.
|
||||||
|
|
||||||
info(#pstate{connected = Connected,
|
info(#pstate{connected = Connected,
|
||||||
proto_ver = ProtoVer,
|
proto_ver = ProtoVer,
|
||||||
proto_name = ProtoName,
|
proto_name = ProtoName,
|
||||||
heart_beats = Heartbeats,
|
heart_beats = Heartbeats,
|
||||||
login = Login,
|
login = Login,
|
||||||
subscriptions = Subscriptions}) ->
|
subscriptions = Subscriptions}) ->
|
||||||
[{connected, Connected},
|
[{connected, Connected},
|
||||||
{proto_ver, ProtoVer},
|
{proto_ver, ProtoVer},
|
||||||
{proto_name, ProtoName},
|
{proto_name, ProtoName},
|
||||||
|
@ -139,7 +139,7 @@ received(Frame = #stomp_frame{command = <<"SEND">>, headers = Headers}, State) -
|
||||||
end;
|
end;
|
||||||
|
|
||||||
received(#stomp_frame{command = <<"SUBSCRIBE">>, headers = Headers},
|
received(#stomp_frame{command = <<"SUBSCRIBE">>, headers = Headers},
|
||||||
State = #pstate{subscriptions = Subscriptions}) ->
|
State = #pstate{subscriptions = Subscriptions, login = Login}) ->
|
||||||
Id = header(<<"id">>, Headers),
|
Id = header(<<"id">>, Headers),
|
||||||
Topic = header(<<"destination">>, Headers),
|
Topic = header(<<"destination">>, Headers),
|
||||||
Ack = header(<<"ack">>, Headers, <<"auto">>),
|
Ack = header(<<"ack">>, Headers, <<"auto">>),
|
||||||
|
@ -147,7 +147,7 @@ received(#stomp_frame{command = <<"SUBSCRIBE">>, headers = Headers},
|
||||||
{Id, Topic, Ack} ->
|
{Id, Topic, Ack} ->
|
||||||
{ok, State};
|
{ok, State};
|
||||||
false ->
|
false ->
|
||||||
emqx_broker:subscribe(Topic),
|
emqx_broker:subscribe(Topic, Login),
|
||||||
{ok, State#pstate{subscriptions = [{Id, Topic, Ack}|Subscriptions]}}
|
{ok, State#pstate{subscriptions = [{Id, Topic, Ack}|Subscriptions]}}
|
||||||
end,
|
end,
|
||||||
maybe_send_receipt(receipt_id(Headers), State1);
|
maybe_send_receipt(receipt_id(Headers), State1);
|
||||||
|
@ -312,13 +312,15 @@ negotiate_version(Ver, [AcceptVer|_]) when Ver >= AcceptVer ->
|
||||||
negotiate_version(Ver, [_|T]) ->
|
negotiate_version(Ver, [_|T]) ->
|
||||||
negotiate_version(Ver, T).
|
negotiate_version(Ver, T).
|
||||||
|
|
||||||
check_login(undefined, _, AllowAnonymous, _) ->
|
check_login(Login, _, AllowAnonymous, _)
|
||||||
|
when Login == <<>>;
|
||||||
|
Login == undefined ->
|
||||||
AllowAnonymous;
|
AllowAnonymous;
|
||||||
check_login(_, _, _, undefined) ->
|
check_login(_, _, _, undefined) ->
|
||||||
false;
|
false;
|
||||||
check_login(Login, Passcode, _, DefaultUser) ->
|
check_login(Login, Passcode, _, DefaultUser) ->
|
||||||
case {list_to_binary(get_value(login, DefaultUser)),
|
case {iolist_to_binary(get_value(login, DefaultUser)),
|
||||||
list_to_binary(get_value(passcode, DefaultUser))} of
|
iolist_to_binary(get_value(passcode, DefaultUser))} of
|
||||||
{Login, Passcode} -> true;
|
{Login, Passcode} -> true;
|
||||||
{_, _ } -> false
|
{_, _ } -> false
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue