Add hook to auth packet
This commit is contained in:
parent
e806a96031
commit
dccf3560f0
|
@ -1138,21 +1138,18 @@ do_enhanced_auth(undefined, _AuthData, Channel) ->
|
||||||
do_enhanced_auth(_AuthMethod, undefined, Channel) ->
|
do_enhanced_auth(_AuthMethod, undefined, Channel) ->
|
||||||
{error, emqx_reason_codes:connack_error(not_authorized), Channel};
|
{error, emqx_reason_codes:connack_error(not_authorized), Channel};
|
||||||
do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) ->
|
do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) ->
|
||||||
case do_auth_check(AuthMethod, AuthData, Cache) of
|
case run_hooks('client.enhanced_authenticate',[AuthMethod, AuthData, Cache]) of
|
||||||
ok -> {ok, #{}, Channel#channel{auth_cache = #{}}};
|
{ok, <<>>} -> {ok, #{}, Channel#channel{auth_cache = #{}}};
|
||||||
{ok, NAuthData} ->
|
{ok, NAuthData} ->
|
||||||
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
||||||
{ok, NProperties, Channel#channel{auth_cache = #{}}};
|
{ok, NProperties, Channel#channel{auth_cache = #{}}};
|
||||||
{continue, NAuthData, NCache} ->
|
{continue, NAuthData, NCache} ->
|
||||||
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
||||||
{continue, NProperties, Channel#channel{auth_cache = NCache}};
|
{continue, NProperties, Channel#channel{auth_cache = NCache}};
|
||||||
{error, _Reason} ->
|
_ ->
|
||||||
{error, emqx_reason_codes:connack_error(not_authorized), Channel}
|
{error, emqx_reason_codes:connack_error(not_authorized), Channel}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_auth_check(_AuthMethod, _AuthData, _AuthDataCache) ->
|
|
||||||
{error, not_authorized}.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Process Topic Alias
|
%% Process Topic Alias
|
||||||
|
|
||||||
|
|
|
@ -520,11 +520,12 @@ reserved_idx('client.connect') -> 200;
|
||||||
reserved_idx('client.connack') -> 201;
|
reserved_idx('client.connack') -> 201;
|
||||||
reserved_idx('client.connected') -> 202;
|
reserved_idx('client.connected') -> 202;
|
||||||
reserved_idx('client.authenticate') -> 203;
|
reserved_idx('client.authenticate') -> 203;
|
||||||
reserved_idx('client.auth.anonymous') -> 204;
|
reserved_idx('client.enhanced_authenticate') -> 204;
|
||||||
reserved_idx('client.check_acl') -> 205;
|
reserved_idx('client.auth.anonymous') -> 205;
|
||||||
reserved_idx('client.subscribe') -> 206;
|
reserved_idx('client.check_acl') -> 206;
|
||||||
reserved_idx('client.unsubscribe') -> 207;
|
reserved_idx('client.subscribe') -> 207;
|
||||||
reserved_idx('client.disconnected') -> 208;
|
reserved_idx('client.unsubscribe') -> 208;
|
||||||
|
reserved_idx('client.disconnected') -> 209;
|
||||||
|
|
||||||
reserved_idx('session.created') -> 220;
|
reserved_idx('session.created') -> 220;
|
||||||
reserved_idx('session.resumed') -> 221;
|
reserved_idx('session.resumed') -> 221;
|
||||||
|
|
|
@ -120,7 +120,7 @@ t_handle_in_connect_auth_failed(_) ->
|
||||||
clean_start = true,
|
clean_start = true,
|
||||||
keepalive = 30,
|
keepalive = 30,
|
||||||
properties = #{
|
properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
clientid = <<"clientid">>,
|
clientid = <<"clientid">>,
|
||||||
|
@ -131,7 +131,7 @@ t_handle_in_connect_auth_failed(_) ->
|
||||||
|
|
||||||
t_handle_in_continue_auth(_) ->
|
t_handle_in_continue_auth(_) ->
|
||||||
Properties = #{
|
Properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
{shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} =
|
{shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} =
|
||||||
|
@ -141,7 +141,7 @@ t_handle_in_continue_auth(_) ->
|
||||||
|
|
||||||
t_handle_in_re_auth(_) ->
|
t_handle_in_re_auth(_) ->
|
||||||
Properties = #{
|
Properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
{ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} =
|
{ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} =
|
||||||
|
|
Loading…
Reference in New Issue