如何使用 ASPNETBOILERPLATE 测试 LDAP?

How can I test LDAP using ASPNETBOILERPLATE?

ASPNET Boilerplate 或 ASPNETZero 能够与 LDAP 集成。显然配置很简单,但它只让我配置一个域、一个用户和密码。我想知道是否有人有 LDAP 测试服务器的工作示例?目前我已经启用了 LDAP 身份验证:

//Enable LDAP authentication (It can be enabled only if MultiTenancy is disabled!)
Configuration.Modules.ZeroLdap().Enable(typeof(Authorization.Ldap.AppLdapAuthenticationSource));

并为其使用测试 LDAP 服务器。启用 LDAP 身份验证后,我配置了域、用户和密码,但我在 TokenAuthController.cs 中的方法 GetLoginResultAsync 上收到错误。错误如下:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=System.DirectoryServices.AccountManagement
  StackTrace:
   at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
   at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
   at Abp.Zero.Ldap.Authentication.LdapAuthenticationSource`2.<CreatePrincipalContext>d__13.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Zero.Ldap.Authentication.LdapAuthenticationSource`2.<TryAuthenticateAsync>d__6.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Abp.Authorization.AbpLogInManager`3.<TryLoginFromExternalAuthenticationSources>d__41.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Authorization.AbpLogInManager`3.<LoginAsyncInternal>d__37.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Authorization.AbpLogInManager`3.<LoginAsync>d__36.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Paradigm.Web.Controllers.TokenAuthController.<GetLoginResultAsync>d__43.MoveNext() in C:\Users\victo\Documents\Work\NS\JNJ\QueDevBase2\src\Paradigm.Web.Core\Controllers\TokenAuthController.cs:line 618

  This exception was originally thrown at this call stack:
    System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(string, ref System.DirectoryServices.AccountManagement.ServerProperties)
    System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
    System.DirectoryServices.AccountManagement.PrincipalContext.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType, string, string, System.DirectoryServices.AccountManagement.ContextOptions, string, string)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Abp.Authorization.AbpLogInManager<TTenant, TRole, TUser>.LoginAsyncInternal(string, string, string, bool)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ...
    [Call Stack Truncated]

感谢任何帮助。

当前Abp.Zero.Ldap使用的PrincipalContext:

对于 AD 添加 DefaultSettingsCreator.cs 中的设置:

AddSettingIfNotExists(LdapSettingNames.UserName, "AD_Administrator", tenantId);
AddSettingIfNotExists(LdapSettingNames.Password, "password", tenantId);
AddSettingIfNotExists(LdapSettingNames.ContextType, "Domain.Context", tenantId);
AddSettingIfNotExists(LdapSettingNames.Domain, "test.local");

注意:如果您未定义域、用户名和密码,并且您的应用程序在具有适当权限的域中运行,则 LDAP 身份验证适用于当前域。 https://aspnetboilerplate.com/Pages/Documents/Zero/User-Management#settings

对于 LDAP 在线测试服务器

查看:https://github.com/do-it-ger/DoAspnetboilerplateLdap Novell.Ldap 实施。 针对在线 Ldap 测试服务器运行测试:ldap.forumsys.com