mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-12-25 10:37:33 +00:00
Fix invalid email field error
Instead of crashing with a cryptic message, instead we print an error message. Also, as a bonus, better testing instructions! Fixes #3 Fixes #2
This commit is contained in:
parent
829ed5585c
commit
c493366efd
29
README.md
29
README.md
@ -31,6 +31,35 @@ Configuration values are as follows:
|
||||
|`ldap_sync_interval_seconds`|Integer|Optional|Number of seconds to wait between each LDAP request. Defaults to `60`|
|
||||
|`ldap_sync_loop`|Boolean|Optional|Indicates whether or not syncing should be polled in a loop or done once. Defaults to `true`|
|
||||
|
||||
## Testing
|
||||
|
||||
All testing is manual right now. First step is to set up Bitwarden and the LDAP server.
|
||||
|
||||
```bash
|
||||
docker-compose up -d bitwarden ldap ldap_admin
|
||||
```
|
||||
|
||||
1. After that, open the admin portal on http://localhost:8001 and log in using the default account info:
|
||||
|
||||
Username: cn=admin,dc=example,dc=org
|
||||
Password: admin
|
||||
|
||||
From there you can set up your test group and users.
|
||||
|
||||
2. Expand the `dc=example,dc=org` nav tree and select "Create new entry here"
|
||||
3. Select "Generic: Posix Group"
|
||||
4. Give it a name, eg. "Users" and then save and commit
|
||||
5. Select "Create child object"
|
||||
6. Select "Generic: User Account"
|
||||
7. Give the user a name and select a group ID number and save and commit
|
||||
8. Select "Add new attribute" and select "Email" and then add a test email address
|
||||
|
||||
9. Run the ldap sync
|
||||
|
||||
```bash
|
||||
docker-compose up ldap_sync
|
||||
```
|
||||
|
||||
## Future
|
||||
|
||||
* Any kind of proper logging
|
||||
|
@ -6,7 +6,8 @@ services:
|
||||
# dockerfile: Dockerfile.alpine
|
||||
volumes:
|
||||
- ./example.config.toml:/usr/src/bitwarden_rs_ldap/config.toml:ro
|
||||
# - ./example.config.toml:/config.toml:ro
|
||||
environment:
|
||||
RUST_BACKTRACE: 1
|
||||
restart: always
|
||||
|
||||
bitwarden:
|
||||
|
@ -131,10 +131,9 @@ impl Config {
|
||||
}
|
||||
|
||||
pub fn get_ldap_mail_field(&self) -> String {
|
||||
let default = String::from("mail");
|
||||
match &self.ldap_mail_field {
|
||||
Some(mail_field) => mail_field.clone(),
|
||||
None => default.clone(),
|
||||
None => String::from("mail").clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,12 @@ fn invite_from_ldap(
|
||||
let mail_field = config.get_ldap_mail_field();
|
||||
let mut num_users = 0;
|
||||
for ldap_user in search_entries(config)? {
|
||||
if let Some(user_email) = ldap_user.attrs[mail_field.as_str()].first() {
|
||||
// Safely get first email from list of emails in field
|
||||
if let Some(user_email) = ldap_user
|
||||
.attrs
|
||||
.get(mail_field.as_str())
|
||||
.and_then(|l| (l.first()))
|
||||
{
|
||||
if existing_users.contains(user_email) {
|
||||
println!("User with email already exists: {}", user_email);
|
||||
} else {
|
||||
@ -124,6 +129,8 @@ fn invite_from_ldap(
|
||||
num_users = num_users + 1;
|
||||
// println!("Invite response: {:?}", response);
|
||||
}
|
||||
} else {
|
||||
println!("Warning: Email field, {:?}, not found on user", mail_field);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user