2017-09-11 23 views

回答

0

LDAP/Active Directory的

LdapAuthenticationSource是外部認證的實現,使用戶使用他們的LDAP(活動目錄)的用戶名和密碼登錄。

如果我們想要使用LDAP認證,我們首先添加Abp.Zero.Ldap nuget包到我們的項目中(一般是Core(域)項目)。然後,如下圖所示,我們應該擴大我們的應用程序LdapAuthenticationSource:

公共類MyLdapAuthenticationSource:LdapAuthenticationSource { 公共MyLdapAuthenticationSource(ILdapSettings設置,IAbpZeroLdapModuleConfig ldapModuleConfig) :基地(設置,ldapModuleConfig) { } }

最後,我們應該將模塊依賴關係設置爲AbpZeroLdapModule並使用上面創建的認證來源啓用LDAP:

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

    ... 
} 

完成這些步驟後,將爲您的應用程序啓用LDAP模塊。但是,默認情況下,LDAP驗證未啓用。我們可以使用設置啓用它。 設置

LdapSettingNames類定義設置名稱的常量。您可以在更改設置(或獲取設置)時使用這些常量名稱。 LDAP設置是每個租戶(對於多租戶應用程序)。因此,不同的租戶有不同的設置(請參閱github上的設置定義)。

正如您在MyLdapAuthenticationSource構造函數中所看到的,LdapAuthenticationSource期望ILdapSettings作爲構造函數參數。此接口用於獲取LDAP設置,如域,用戶名和密碼以連接到Active Directory。默認實現(LdapSettings類)從設置管理器獲取這些設置。

如果你使用設置管理器,那麼沒問題。您可以使用設置管理器API更改LDAP設置。如果需要,可以將初始/種子數據添加到數據庫以默認啓用LDAP身份驗證。

注意:如果您未定義域,用戶名和密碼,那麼如果您的應用程序在具有相應權限的域中運行,則LDAP認證適用於當前域。 自定義設置

如果要定義另一個設定源,可以實現自定義ILdapSettings類,如下圖所示:

public class MyLdapSettings : ILdapSettings 
{ 
    public async Task<bool> GetIsEnabled(int? tenantId) 
    { 
     return true; 
    } 

    public async Task<ContextType> GetContextType(int? tenantId) 
    { 
     return ContextType.Domain; 
    } 

    public async Task<string> GetContainer(int? tenantId) 
    { 
     return null; 
    } 

    public async Task<string> GetDomain(int? tenantId) 
    { 
     return null; 
    } 

    public async Task<string> GetUserName(int? tenantId) 
    { 
     return null; 
    } 

    public async Task<string> GetPassword(int? tenantId) 
    { 
     return null; 
    } 
} 

而在你的模塊的預初始化註冊到IOC:

[DependsOn(typeof(AbpZeroLdapModule))] 
public class MyApplicationCoreModule : AbpModule 
{ 
    public override void PreInitialize() 
    { 
     IocManager.Register<ILdapSettings, MyLdapSettings>(); //change default setting source 
     Configuration.Modules.ZeroLdap().Enable(typeof (MyLdapAuthenticationSource)); 
    } 

    ... 
} 

然後,您可以從任何其他來源獲取LDAP設置。

https://aspnetboilerplate.com/Pages/Documents/Zero/User-Management#ldapactive-directory

+0

謝謝,這非常有幫助,它讓我朝着正確的方向前進! –

+0

請參閱[this](https://stackoverflow.com/questions/49106683/no-component-for-supporting-the-service-abp-zero-configuration-iabpzeroconfig-wa)。 – Aria

相關問題