Skip to content

ozanerturk/LdapManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Ldap Manager

Easily read ldap user enrties and authenticate them.

Build Status codecov

This is a simple library that helps to map and authenticate Ldap users easily. It is handling common connection case with provided configuration.

Usage

Create your own custom usermodel class like below. LdapExtract attribute indicates the attribute of LDAP entry

public class CustomUserModel
{
    [LdapExtract("displayName")]
    public string DisplayName { get; set; }
    
    [LdapExtract("sAMAccountName",IsUsername:true)]
    public string Username { get; set; }

    [LdapExtract("name")]
    public string Name { get; set; }
    
    [LdapExtract("sn")]
    public string Surname { get; set; }

}

And open connection, create manager instance and fetch users based on the configuration

  var config = new LdapConfig(){
                Host ="localhost",
                Port=389, //default
                BindDn="CN=admin,CN=Users,DC=example,DC=com",
                BindPassword="secret",
                SearchBase="CN=Users,DC=example,DC=com",
                UserObjectClass = "user",//default
                SearchFilter = "(objectClass={0})"//default
            };
            
ILdapConnectionFactory ldapConnectionFactory = new LdapConnectionFactory();

using(var connection = ldapConnectionFactory.OpenConnection(config)){

    ILdapManager manager = new LdapManager(connection);
    IList<CustomUserModel> users = manager.Fetch<CustomUserModel>();
    
}

or verify a user

using(var connection = ldapConnectionFactory.OpenConnection(config)){

    ILdapManager manager = new LdapManager(connection);
    LoginResult users = manager.Login<CustomUserModel>("tbmm01","33301");
    
}