Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DN attribute name configurable #13

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading