ASPNET Boilerplate or ASPNETZero have the ability to integrate with LDAP. Apparently the configuration is easy, but it only lets me configure a Domain, a User and Password. I was wondering if anyone has a working example with a test server of LDAP? Currently I have enabled the LDAP Authentication:
//Enable LDAP authentication (It can be enabled only if MultiTenancy is disabled!)
Configuration.Modules.ZeroLdap().Enable(typeof(Authorization.Ldap.AppLdapAuthenticationSource));
And using a test LDAP server for it. Once I enable the LDAP authentication I configure the domain, user and password, but I am getting an error on the method GetLoginResultAsync in TokenAuthController.cs. The error is as follows:
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]
Any help is appreciated.
The current Abp.Zero.Ldap used PrincipalContext: PrincipalContext - I Can't connect to a local openldap server
For AD add the settings in the DefaultSettingsCreator.cs:
AddSettingIfNotExists(LdapSettingNames.UserName, "AD_Administrator", tenantId);
AddSettingIfNotExists(LdapSettingNames.Password, "password", tenantId);
AddSettingIfNotExists(LdapSettingNames.ContextType, "Domain.Context", tenantId);
AddSettingIfNotExists(LdapSettingNames.Domain, "test.local");
Note: If you don't define a domain, username and password, LDAP authentication works for the current domain if your application runs in a domain with appropriate privileges. https://aspnetboilerplate.com/Pages/Documents/Zero/User-Management#settings
Check out: https://github.com/do-it-ger/DoAspnetboilerplateLdap for the Novell.Ldap implementation. Test runs against the online Ldap test Server: ldap.forumsys.com
User contributions licensed under CC BY-SA 3.0