Merge branch 'fix/ldap' into 'develop'
Fix LDAP support See merge request pleroma/pleroma!4168
This commit is contained in:
commit
7a4687562a
1
changelog.d/ldap.fix
Normal file
1
changelog.d/ldap.fix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix LDAP support
|
@ -102,28 +102,37 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
|
|||||||
{:scope, :eldap.wholeSubtree()},
|
{:scope, :eldap.wholeSubtree()},
|
||||||
{:timeout, @search_timeout}
|
{:timeout, @search_timeout}
|
||||||
]) do
|
]) do
|
||||||
{:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
|
# The :eldap_search_result record structure changed in OTP 24.3 and added a controls field
|
||||||
params = %{
|
# https://github.com/erlang/otp/pull/5538
|
||||||
name: name,
|
{:ok, {:eldap_search_result, [{:eldap_entry, _object, attributes}], _referrals}} ->
|
||||||
nickname: name,
|
try_register(name, attributes)
|
||||||
password: nil
|
|
||||||
}
|
|
||||||
|
|
||||||
params =
|
{:ok, {:eldap_search_result, [{:eldap_entry, _object, attributes}], _referrals, _controls}} ->
|
||||||
case List.keyfind(attributes, ~c"mail", 0) do
|
try_register(name, attributes)
|
||||||
{_, [mail]} -> Map.put_new(params, :email, :erlang.list_to_binary(mail))
|
|
||||||
_ -> params
|
|
||||||
end
|
|
||||||
|
|
||||||
changeset = User.register_changeset_ldap(%User{}, params)
|
|
||||||
|
|
||||||
case User.register(changeset) do
|
|
||||||
{:ok, user} -> user
|
|
||||||
error -> error
|
|
||||||
end
|
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp try_register(name, attributes) do
|
||||||
|
params = %{
|
||||||
|
name: name,
|
||||||
|
nickname: name,
|
||||||
|
password: nil
|
||||||
|
}
|
||||||
|
|
||||||
|
params =
|
||||||
|
case List.keyfind(attributes, ~c"mail", 0) do
|
||||||
|
{_, [mail]} -> Map.put_new(params, :email, :erlang.list_to_binary(mail))
|
||||||
|
_ -> params
|
||||||
|
end
|
||||||
|
|
||||||
|
changeset = User.register_changeset_ldap(%User{}, params)
|
||||||
|
|
||||||
|
case User.register(changeset) do
|
||||||
|
{:ok, user} -> user
|
||||||
|
error -> error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user