diff --git a/en/images/configure-ldap-setting.png b/en/images/configure-ldap-setting.png index fc73d943..73f24720 100644 Binary files a/en/images/configure-ldap-setting.png and b/en/images/configure-ldap-setting.png differ diff --git a/en/modules/account/ldap.md b/en/modules/account/ldap.md index 03fd7f19..88f7dc02 100644 --- a/en/modules/account/ldap.md +++ b/en/modules/account/ldap.md @@ -24,33 +24,35 @@ The default `OpenLdapManager` service uses `$"cn={userName},{BaseDc}"` to normal > The value of `BaseDc` is the setting of the `Base domain component`. -If your **username** has a prefix or a specific format, you can override the `NormalizeUserName` method of `OpenLdapManager` to handle it. You can also customize the `GetUserFilter` and `GetUserEmail` methods at the same time. +If your **username** has a prefix or a specific format, you can override the `NormalizeUserNameAsync` method of `OpenLdapManager` to handle it. You can also customize the `GetUserFilterAsync` and `GetUserEmailAsync` methods at the same time. ```cs [Dependency(ReplaceServices = true)] [ExposeServices(typeof(OpenLdapManager), typeof(ILdapManager), typeof(LdapManager))] public class VoloOpenLdapManager : OpenLdapManager { - public VoloOpenLdapManager(IOptions ldapSettingsOptions) - : base(ldapSettingsOptions) + public VoloOpenLdapManager(ILdapSettingProvider ldapSettingProvider) + : base(ldapSettingProvider) { + } - protected override string NormalizeUserName(string userName) + protected override async Task NormalizeUserNameAsync(string userName) { - return $"Volo\\{userName}"; + // or "userName@domain + // await LdapSettingProvider.GetDomainAsync() + return Task.FromResult($"Volo\\{userName}"); } - protected override string GetUserFilter(string userName) + protected override Task GetUserFilterAsync(string userName) { // Default is $"cn={userName},{LdapOptions.BaseDc}" - return $"(&(objectClass=user)(sAMAccountName={userName}))"; + return return Task.FromResult($"(&(objectClass=user)(sAMAccountName={userName}))"); } - protected override string GetUserEmail(LdapEntry ldapEntry) + protected override Task GetUserEmailAsync(LdapEntry ldapEntry) { - // You can use another attribute to get user email. - return ldapEntry.ToDirectoryEntry().GetAttribute("mail")?.GetValue(); + return Task.FromResult(ldapEntry.ToDirectoryEntry().GetAttribute("mail")?.GetValue()); } } ``` @@ -66,7 +68,7 @@ public class VoloLdapExternalLoginProvider : LdapExternalLoginProvider IdentityUserManager userManager, IIdentityUserRepository identityUserRepository, OpenLdapManager ldapManager, - IOptions ldapOptions, + ILdapSettingProvider ldapSettingProvider, IFeatureChecker featureChecker, ISettingProvider settingProvider, IOptions identityOptions) @@ -75,7 +77,7 @@ public class VoloLdapExternalLoginProvider : LdapExternalLoginProvider userManager, identityUserRepository, ldapManager, - ldapOptions, + ldapSettingProvider, featureChecker, settingProvider, identityOptions) @@ -83,10 +85,12 @@ public class VoloLdapExternalLoginProvider : LdapExternalLoginProvider } - protected override string NormalizeUserName(string userName) + protected override async Task NormalizeUserNameAsync(string userName) { // Default is $"uid={userName}, {BaseDc}" - return $"Volo\\{userName}"; + // or "userName@domain + // await LdapSettingProvider.GetDomainAsync() + return Task.FromResult($"Volo\\{userName}"); } } ```