ozanerturk / LdapManager

LdapManager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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");
    
}

About

LdapManager


Languages

Language:C# 99.1%Language:Batchfile 0.9%