Skip to content

Commit

Permalink
Merge pull request #13 from aeveris/make-dn-attribute-configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
keaz authored Apr 17, 2024
2 parents 3189680 + 74bf998 commit a58f465
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 31 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ cargo add simple-ldap

## Examples

### Authenticate a user

```rust
use simple-ldap::{LdapClient,Error,EqFilter};
use simple-ldap::ldap3::Scope;

#[tokio::main]
async fn main() -> Result<()> {
let ldap_config = LdapConfig {
bind_dn: "cn=manager".to_string(),
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
// By default, simple-ldap uses the "entryDN" attribute to get a record's distinguished name.
// In case the attribute containing the DN is named differently, you can use `dn_attribute` to
// provide the correct attribute.
dn_attribute: Some("distinguishedName"),
};

let pool = pool::build_connection_pool(&ldap_config).await;
let mut ldap = pool.pool.get_connection().await.unwrap();
let name_filter = EqFilter::from("cn".to_string(), "Ada".to_string());

ldap.authenticate("ou=users,dc=example,dc=org", "Ada", "password", Box::new(name_filter))
.await
.expect("Authentication unsuccessful");
}
```

### Create a new record
```rust
use simple-ldap::{LdapClient,Error,EqFilter};
Expand All @@ -25,6 +54,7 @@ async fn main() -> Result<()> {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand Down Expand Up @@ -65,6 +95,7 @@ async fn main() -> Result<()> {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand Down Expand Up @@ -96,6 +127,7 @@ async fn main() -> Result<()> {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand Down Expand Up @@ -126,6 +158,7 @@ async fn main() -> Result<()> {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand Down Expand Up @@ -154,6 +187,7 @@ async fn main() -> Result<()> {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand All @@ -179,6 +213,7 @@ let ldap_config = LdapConfig {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand All @@ -198,6 +233,7 @@ let ldap_config = LdapConfig {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand All @@ -224,6 +260,7 @@ let ldap_config = LdapConfig {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand All @@ -243,6 +280,7 @@ let ldap_config = LdapConfig {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand All @@ -267,6 +305,7 @@ let ldap_config = LdapConfig {
bind_pw: "password".to_string(),
ldap_url: "ldap://ldap_server:1389/dc=example,dc=com".to_string(),
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
Expand Down
Loading

0 comments on commit a58f465

Please sign in to comment.