使用Elixir / Erlang验证AD的凭据

问题描述 投票:1回答:1

我正在尝试使用Elixir / Erlang实现简单的AD凭据验证。我在C#中的代码工作正常。

C#

private static void Main(string[] args)
{
  try
  {
    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "132.10.100.156"))
    {
      bool isValid = pc.ValidateCredentials("my-username", "my-password");

      Console.WriteLine(isValid);
    }
  }
  catch (Exception e)
  {
    Console.WriteLine(e);
  }

  Console.ReadLine();
}

Elixir

defmodule AD do
  @moduledoc false
  require Logger

  @format [
    limit: :infinity,
    pretty: true,
    structs: true,
    width: 210,
    syntax_colors: [number: :yellow, atom: :cyan, string: :green, boolean: :magenta, nil: :magenta]
  ]

  def test do
    {:ok, pid} = :eldap.open(['132.10.100.156'], log: &log/3)
    :eldap.simple_bind(pid, 'my-username', 'my-password')
  end

  def log(_, format_string, format_args) do
    Logger.debug(inspect({format_string, format_args}, @format))
  end
end

控制台:

iex> AD.test
[2019-11-16 18:23:53.354] {'bind request = ~p~n', [{:BindRequest, 3, 'my-username', {:simple, 'my-password'}}]}
{:error, :invalidCredentials}
[2019-11-16 18:23:53.511] {'bind reply = ~p~n',
 [
   ok: {:LDAPMessage, 1,
    {:bindResponse,
     {:BindResponse, :invalidCredentials, [],
      [56, 48, 48, 57, 48, 51, 48, 56, 58, 32, 76, 100, 97, 112, 69, 114, 114, 58, 32, 68, 83, 73, 68, 45, 48, 67, 48, 57, 48, 51, 67, 56, 44, 32, 99, 111, 109, 109, 101, 110, 116, 58, 32, 65, 99, 99, 101, 112,
       116, 83, 101, 99, 117, 114, 105, 116, 121, 67, 111, 110, 116, 101, 120, 116, 32, 101, 114, 114, 111, 114, 44, 32, 100, 97, 116, 97, 32, 53, 50, 101, 44, 32, 118, 50, 53, 56, 48, 0], :asn1_NOVALUE,
      :asn1_NOVALUE}}, :asn1_NOVALUE}
 ]}
iex>
active-directory erlang elixir
1个回答
0
投票

[:erldap需要my-username @ somedomain或完整的DN才能正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.