1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use ldap3::{exop::WhoAmI, LdapConn, LdapError};
use r2d2::ManageConnection;
pub struct LDAPConnectionManager(pub &'static str);
impl ManageConnection for LDAPConnectionManager {
type Connection = LdapConn;
type Error = LdapError;
fn connect(&self) -> Result<LdapConn, LdapError> {
LdapConn::new(self.0)
}
fn is_valid(&self, conn: &mut LdapConn) -> Result<(), LdapError> {
conn.extended(WhoAmI).map(|_| ())
}
fn has_broken(&self, conn: &mut LdapConn) -> bool {
conn.extended(WhoAmI).is_err()
}
}