How to use LDAP in ASP.NET Boilerplate (Free Startup Template)

狂风中的少年 提交于 2019-12-02 16:45:09

问题


I would like to integrate authentication via Active Directory in my .net Core app using Free Startup Template version of the Boilerplate. I followed the instruction in the documentation such as installing Abp.Zero.Ldap package, creating LdapAuthenticationSource class, and injecting dependency like:

[DependsOn(typeof(AbpZeroLdapModule))]
public class MyApplicationCoreModule : AbpModule
{
    public override void PreInitialize()
    {
        Configuration.Modules.ZeroLdap().Enable(typeof (MyLdapAuthenticationSource));    
    }

    ...
}

Do I need to define any custom settings by using a class implementing ILdapSettings interface? Or create any class or files referencing to this folder?


回答1:


.NET Core 2.0

The instructions may not work, as LDAP / AD auth extension for .NET Core isn't implemented yet.

Track this feature: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2755

.NET Framework 4.6.1

By installing Abp.Zero.Ldap package, you're already referencing that module (moved here).

As mentioned in LDAP/Active Directory > Settings:

LdapAuthenticationSource expects ILdapSettings as a constructor argument. This interface is used to get LDAP settings like domain, user name and password to connect to Active Directory. Default implementation (LdapSettings class) gets these settings from the setting manager.

If you work with Setting manager, then no problem. You can change LDAP settings using setting manager API. If you want, you can add an initial/seed data to database to enable LDAP auth by default.

So, you don't need to create a class that implements ILdapSettings. The benefit of using the Setting Manager is that it stores the settings in your database. A custom class is for getting it from elsewhere or hardcoding it (useful if you just want to try, but a big no-no in production / git commit).

For a start, you can add seed data for your Host in DefaultSettingsCreator with LdapSettingNames:

public void Create()
{
    // ...

    // LDAP
    AddSettingIfNotExists(LdapSettingNames.IsEnabled, "false");
    // AddSettingIfNotExists(LdapSettingNames...
}


来源:https://stackoverflow.com/questions/47628282/how-to-use-ldap-in-asp-net-boilerplate-free-startup-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!