Skip to content

Commit

Permalink
Added Group support
Browse files Browse the repository at this point in the history
  • Loading branch information
keaz committed Dec 16, 2023
1 parent e1c0692 commit c861dec
Show file tree
Hide file tree
Showing 3 changed files with 419 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
repository = "https://github.com/keaz/simple-ldap"
keywords = ["ldap", "ldap3", "async","high-level"]
name = "simple-ldap"
version = "1.2.0"
version = "1.3.0"
edition = "2021"


Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,66 @@ async fn main() -> Result<()> {
}
```

### Create a group
```rust
use simple_ldap::LdapClient;
use simple_ldap::pool::LdapConfig;

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,
};

let pool = pool::build_connection_pool(&ldap_config).await;
let mut ldap = pool.get_connection().await;
let result = ldap.create_group("test_group", "ou=groups,dc=example,dc=com", "test group").await;

Ok(ldap.unbind().await?)
```

### Add user to a group
```rust
use simple_ldap::LdapClient;
use simple_ldap::pool::LdapConfig;

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,
};

let pool = pool::build_connection_pool(&ldap_config).await;
let mut ldap = pool.get_connection().await;
let result = ldap.add_user_to_group("test_group", "ou=groups,dc=example,dc=com", "test_user").await;

Ok(ldap.unbind().await?)
```


### Get users in a group
```rust
use simple_ldap::LdapClient;
use simple_ldap::pool::LdapConfig;

#[derive(Debug, Deserialize)]
struct User {
uid: String,
cn: String,
sn: String,
}
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,
};

let pool = pool::build_connection_pool(&ldap_config).await;
let mut ldap = pool.get_connection().await;
let result = ldap.get_members::<User>("cn=test_group,ou=groups,dc=example,dc=com", "ou=people,dc=example,dc=com", self::ldap3::Scope::OneLevel, vec!["cn", "sn", "uid"]).await;

Ok(ldap.unbind().await?)
```
Loading

0 comments on commit c861dec

Please sign in to comment.