Merge pull request #12133 from lafirest/fix/ldap
fix(authn_ldap): Improve the type inference of method union
This commit is contained in:
commit
11622031c5
|
@ -52,7 +52,7 @@ authenticate(
|
||||||
{ok, #{result := ok}} ->
|
{ok, #{result := ok}} ->
|
||||||
{ok, #{is_superuser => false}};
|
{ok, #{is_superuser => false}};
|
||||||
{ok, #{result := 'invalidCredentials'}} ->
|
{ok, #{result := 'invalidCredentials'}} ->
|
||||||
?TRACE_AUTHN_PROVIDER(error, "ldap_bind_failed", #{
|
?TRACE_AUTHN_PROVIDER(info, "ldap_bind_failed", #{
|
||||||
resource => ResourceId,
|
resource => ResourceId,
|
||||||
reason => 'invalidCredentials'
|
reason => 'invalidCredentials'
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -55,7 +55,7 @@ fields(ldap) ->
|
||||||
[
|
[
|
||||||
{method,
|
{method,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
hoconsc:union([?R_REF(hash_method), ?R_REF(bind_method)]),
|
hoconsc:union(fun method_union_member_selector/1),
|
||||||
#{desc => ?DESC(method)}
|
#{desc => ?DESC(method)}
|
||||||
)}
|
)}
|
||||||
];
|
];
|
||||||
|
@ -88,6 +88,26 @@ desc(bind_method) ->
|
||||||
desc(_) ->
|
desc(_) ->
|
||||||
undefined.
|
undefined.
|
||||||
|
|
||||||
|
method_union_member_selector(all_union_members) ->
|
||||||
|
[?R_REF(hash_method), ?R_REF(bind_method)];
|
||||||
|
method_union_member_selector({value, Val}) ->
|
||||||
|
Val2 =
|
||||||
|
case is_map(Val) of
|
||||||
|
true -> emqx_utils_maps:binary_key_map(Val);
|
||||||
|
false -> Val
|
||||||
|
end,
|
||||||
|
case Val2 of
|
||||||
|
#{<<"type">> := <<"bind">>} ->
|
||||||
|
[?R_REF(bind_method)];
|
||||||
|
#{<<"type">> := <<"hash">>} ->
|
||||||
|
[?R_REF(hash_method)];
|
||||||
|
_ ->
|
||||||
|
throw(#{
|
||||||
|
field_name => method,
|
||||||
|
expected => [bind_method, hash_method]
|
||||||
|
})
|
||||||
|
end.
|
||||||
|
|
||||||
method_type(Type) ->
|
method_type(Type) ->
|
||||||
?HOCON(?ENUM([Type]), #{desc => ?DESC(?FUNCTION_NAME), default => Type}).
|
?HOCON(?ENUM([Type]), #{desc => ?DESC(?FUNCTION_NAME), default => Type}).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue