Skip to main content

Crate bb8_ldap

Crate bb8_ldap 

Source
Expand description

A bb8 connection manager for ldap3 LDAP connections.

This crate provides LdapConnectionManager, which implements bb8::ManageConnection to pool and reuse asynchronous LDAP connections. The manager handles connection creation, optional bind credentials, and health-check validation via lightweight LDAP searches.

Both bb8 and ldap3 are re-exported for convenience, so you can use them directly without adding separate dependencies.

§Example

use bb8::Pool;
use bb8_ldap::LdapConnectionManager;
use ldap3::LdapConnSettings;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let manager = LdapConnectionManager::new("ldap://localhost:1389")?
        .with_connection_settings(LdapConnSettings::new().set_starttls(false))
        .with_bind_credentials("cn=admin,dc=example,dc=org", "adminpassword")
        .with_connect_timeout(std::time::Duration::from_secs(3))
        .with_validation_timeout(std::time::Duration::from_secs(2));

    let pool = Pool::builder().max_size(15).build(manager).await?;

    let mut conn = pool.get().await?;
    let (results, _res) = conn
        .search("ou=users,dc=example,dc=org", ldap3::Scope::Subtree, "(cn=alice)", vec!["cn"])
        .await?
        .success()?;

    println!("Found {} entries", results.len());
    Ok(())
}

§Feature Flags

FeatureDescription
tls-rustls-aws-lc-rs(default) Enable rustls with the aws-lc-rs crypto provider
tls-rustls-ringEnable rustls with the ring crypto provider
tls-nativeEnable native TLS support (use with --no-default-features)

Example using native TLS:

[dependencies]
bb8-ldap = { version = "*", default-features = false, features = ["tls-native"] }

§Supported URL Schemes

This crate supports the following URL schemes:

  • ldap:// — Standard LDAP over TCP (optionally upgraded with StartTLS)
  • ldapi:// — LDAP over Unix domain sockets

Note: ldaps:// (LDAP over implicit TLS) is not supported. To use TLS, connect via ldap:// and enable StartTLS with LdapConnSettings::set_starttls(true).

§Connection Lifecycle

Each connection is established using ldap3::LdapConnAsync, which returns a connection driver and an Ldap handle. The driver is spawned as a background task via ldap3::drive!(), and the Ldap handle is what gets pooled and returned to callers. All LDAP operations go through this handle while the background task manages the underlying protocol I/O.

Re-exports§

pub use bb8;
pub use ldap3;

Structs§

LdapConnectionManager
A bb8::ManageConnection implementation for ldap3 async connections.