DotNet Directory Services Library
This library provides a convenience wrapper of LDAP queries from C# including the following:
- Search by SID (objectSid - S-1-5...)
- Search By Guid (objectGUID)
- Active Directory Implementation (windows deployment/usage only as it relies on System.DirectoryServices)
- Novell LDAP Implementation (cross platform)
Use the DotNet CLI package manager dotnet to build the project.
dotnet restore
dotnet build
{
"Ldap": {
"BindDistinguishedName": "DN here",
"BindPassword": "Password here",
"DefaultLdapUsersSearchBase": "DN search base here",
"DefaultLdapGroupsSearchBase": "DN search base here",
"DistinguishedNameEscapeCharactersString": "\\,:\\5C\\2C|\\*:\\5C\\2A|\\(:\\5C\\28|\\):\\5C\\29|\\\\:\\5C\\5C",
"Domain": "local",
"LdapConnectionFallback": "LDAP://ldap.local.domain",
"LdapConnectionOverride": "",
"LdapConnectionUrl": "ldap.local.domain",
"LdapFollowReferrals": true,
"LdapKerberosBind": false,
"LdapSecure": false
}
}
// Part 1 - Add to services container
services.AddSingleton<IDirectoyService, NovellDirectoryService>();
// OR
services.AddSingleton<IDirectoyService, ActiveDirectoryService>();
// Part 2 - Use
public class UsersController : ControllerBase
{
private readonly IDirectoryService _directoryService;
public UsersController(IDirectoryService directoryService)
{
_directorService = directoryService ?? throw new ArgumentNullException(nameof(directorService));
}
private TestMethod()
{
var userBySid = _directoryService.SearchUserBySid("S-1-5....");
var userByGuid = _directoryService.SearchUserByGuid("12345-aedgf234...");
}
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.