Crate simple_ldap

Source
Expand description

§simple-ldap

This is a high-level LDAP client library created by wrapping the rust LDAP3 clinet. This provides high-level functions that helps to interact with LDAP.

§Features

  • All the usual LDAP operations
  • Search result deserialization
  • Connection pooling
  • Streaming search with native rust Streams

§Usage

Adding simple_ldap as a dependency to your project:

cargo add simple-ldap

Most functionalities are defined on the LdapClient type. Have a look at the docs.

§Example

Examples of individual operations are scattered throughout the docs, but here’s the basic usage:

use simple_ldap::{
    LdapClient, LdapConfig,
    filter::EqFilter,
    ldap3::Scope
};
use url::Url;
use serde::Deserialize;

// A type for deserializing the search result into.
#[derive(Debug, Deserialize)]
struct User {
    uid: String,
    cn: String,
    sn: String,
}


#[tokio::main]
async fn main(){
    let ldap_config = LdapConfig {
        bind_dn: String::from("cn=manager"),
        bind_password: String::from("password"),
        ldap_url: Url::parse("ldaps://localhost:1389/dc=example,dc=com").unwrap(),
        dn_attribute: None,
        connection_settings: None
    };
    let mut client = LdapClient::new(ldap_config).await.unwrap();
    let name_filter = EqFilter::from("cn".to_string(), "Sam".to_string());
    let user: User = client
        .search::<User>(
        "ou=people,dc=example,dc=com",
        Scope::OneLevel,
        &name_filter,
        &vec!["cn", "sn", "uid"],
    ).await.unwrap();
}

§Compile time features

  • tls-native - (Enabled by default) Enables TLS support using the systems native implementation.
  • tls-rustls - Enables TLS support using rustls. **Conflicts with tls-native so you need to disable default features to use this.
  • pool - Enable connection pooling

Re-exports§

pub extern crate ldap3;

Modules§

filter
Filter

Structs§

LdapClient
High-level LDAP client wrapper ontop of ldap3 crate. This wrapper provides a high-level interface to perform LDAP operations including authentication, search, update, delete
LdapConfig
Configuration and authentication for LDAP connection
Record
The Record struct is used to map the search result to a struct. The Record struct has a method to_record which will map the search result to a struct. The Record struct has a method to_multi_valued_record which will map the search result to a struct with multi valued attributes.
Stream
The Stream struct is used to iterate through the search results. The stream will return a Record object. The Record object can be used to map the search result to a struct. After the stream is finished, the cleanup method should be called to cleanup the stream.

Enums§

Error
The error type for the LDAP client
StreamResult