如何在 ASP.NET 样板文件中使用 LDAP(免费启动模板)

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

我想使用 Boilerplate 的免费启动模板版本通过 Active Directory 在我的 .net Core 应用程序中集成身份验证。我按照 documentation 中的说明进行安装,例如安装 Abp.Zero.Ldap 包,创建 LdapAuthenticationSource class,并注入依赖项,例如:

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

    ...
}

我是否需要使用 class 实现 ILdapSettings 接口来定义任何自定义设置?或者创建任何 class 或引用 this folder?

的文件

.NET 核心 2.0

这些说明可能不起作用,因为 .NET Core 的 LDAP/AD 身份验证扩展尚未实现。

跟踪此功能:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2755

.NET Framework 4.6.1

通过安装 Abp.Zero.Ldap 包,您已经在引用该模块(已移动 here)。

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.

因此,您无需创建实现 ILdapSettings 的 class。使用设置管理器的好处是它将设置存储在您的数据库中。自定义 class 用于从其他地方获取它或对其进行硬编码(如果您只是想尝试,这很有用,但在生产/ git 提交中是一个很大的禁忌)。

首先,您可以在 DefaultSettingsCreator with LdapSettingNames 中为您的主机添加种子数据:

public void Create()
{
    // ...

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