Skip to content

Commit

Permalink
Merge pull request #161 from abpio/maliming/ldap-domain
Browse files Browse the repository at this point in the history
Update LDAP document.
  • Loading branch information
maliming authored Jan 10, 2022
2 parents 786ccfc + 662d784 commit 0276e77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Binary file modified en/images/configure-ldap-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 18 additions & 14 deletions en/modules/account/ldap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbpLdapOptions> ldapSettingsOptions)
: base(ldapSettingsOptions)
public VoloOpenLdapManager(ILdapSettingProvider ldapSettingProvider)
: base(ldapSettingProvider)
{

}

protected override string NormalizeUserName(string userName)
protected override async Task<string> 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<string> 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<string> GetUserEmailAsync(LdapEntry ldapEntry)
{
// You can use another attribute to get user email.
return ldapEntry.ToDirectoryEntry().GetAttribute("mail")?.GetValue<string>();
return Task.FromResult(ldapEntry.ToDirectoryEntry().GetAttribute("mail")?.GetValue<string>());
}
}
```
Expand All @@ -66,7 +68,7 @@ public class VoloLdapExternalLoginProvider : LdapExternalLoginProvider
IdentityUserManager userManager,
IIdentityUserRepository identityUserRepository,
OpenLdapManager ldapManager,
IOptions<AbpLdapOptions> ldapOptions,
ILdapSettingProvider ldapSettingProvider,
IFeatureChecker featureChecker,
ISettingProvider settingProvider,
IOptions<IdentityOptions> identityOptions)
Expand All @@ -75,18 +77,20 @@ public class VoloLdapExternalLoginProvider : LdapExternalLoginProvider
userManager,
identityUserRepository,
ldapManager,
ldapOptions,
ldapSettingProvider,
featureChecker,
settingProvider,
identityOptions)
{

}

protected override string NormalizeUserName(string userName)
protected override async Task<string> NormalizeUserNameAsync(string userName)
{
// Default is $"uid={userName}, {BaseDc}"
return $"Volo\\{userName}";
// or "userName@domain
// await LdapSettingProvider.GetDomainAsync()
return Task.FromResult($"Volo\\{userName}");
}
}
```
Expand Down

0 comments on commit 0276e77

Please sign in to comment.