Просмотр исходного кода

fix(ldap): use the search result as bind target

firest 2 лет назад
Родитель
Сommit
43ea367df8

+ 2 - 2
apps/emqx_dashboard_sso/src/emqx_dashboard_sso_ldap.erl

@@ -124,11 +124,11 @@ login(
     of
     of
         {ok, []} ->
         {ok, []} ->
             {error, user_not_found};
             {error, user_not_found};
-        {ok, [_Entry | _]} ->
+        {ok, [Entry | _]} ->
             case
             case
                 emqx_resource:simple_sync_query(
                 emqx_resource:simple_sync_query(
                     ResourceId,
                     ResourceId,
-                    {bind, Sign}
+                    {bind, Entry#eldap_entry.object_name, Sign}
                 )
                 )
             of
             of
                 ok ->
                 ok ->

+ 1 - 1
apps/emqx_ldap/src/emqx_ldap.erl

@@ -177,7 +177,7 @@ on_query(InstId, {query, Data, Attrs}, State) ->
     on_query(InstId, {query, Data}, [{attributes, Attrs}], State);
     on_query(InstId, {query, Data}, [{attributes, Attrs}], State);
 on_query(InstId, {query, Data, Attrs, Timeout}, State) ->
 on_query(InstId, {query, Data, Attrs, Timeout}, State) ->
     on_query(InstId, {query, Data}, [{attributes, Attrs}, {timeout, Timeout}], State);
     on_query(InstId, {query, Data}, [{attributes, Attrs}, {timeout, Timeout}], State);
-on_query(InstId, {bind, _Data} = Req, State) ->
+on_query(InstId, {bind, _DN, _Data} = Req, State) ->
     emqx_ldap_bind_worker:on_query(InstId, Req, State).
     emqx_ldap_bind_worker:on_query(InstId, Req, State).
 
 
 on_get_status(_InstId, #{pool_name := PoolName} = _State) ->
 on_get_status(_InstId, #{pool_name := PoolName} = _State) ->

+ 2 - 2
apps/emqx_ldap/src/emqx_ldap_authn_bind.erl

@@ -95,11 +95,11 @@ authenticate(
     of
     of
         {ok, []} ->
         {ok, []} ->
             ignore;
             ignore;
-        {ok, [_Entry | _]} ->
+        {ok, [Entry | _]} ->
             case
             case
                 emqx_resource:simple_sync_query(
                 emqx_resource:simple_sync_query(
                     ResourceId,
                     ResourceId,
-                    {bind, Credential}
+                    {bind, Entry#eldap_entry.object_name, Credential}
                 )
                 )
             of
             of
                 ok ->
                 ok ->

+ 1 - 3
apps/emqx_ldap/src/emqx_ldap_bind_worker.erl

@@ -58,14 +58,12 @@ on_stop(InstId, _State) ->
 
 
 on_query(
 on_query(
     InstId,
     InstId,
-    {bind, Data},
+    {bind, DN, Data},
     #{
     #{
-        base_tokens := DNTks,
         bind_password := PWTks,
         bind_password := PWTks,
         bind_pool_name := PoolName
         bind_pool_name := PoolName
     } = State
     } = State
 ) ->
 ) ->
-    DN = emqx_placeholder:proc_tmpl(DNTks, Data),
     Password = emqx_placeholder:proc_tmpl(PWTks, Data),
     Password = emqx_placeholder:proc_tmpl(PWTks, Data),
 
 
     LogMeta = #{connector => InstId, state => State},
     LogMeta = #{connector => InstId, state => State},