13
13
14
14
use Symfony \Component \Ldap \Exception \ConnectionException ;
15
15
use Symfony \Component \Ldap \Exception \LdapException ;
16
+ use Symfony \Component \Security \Core \User \LdapUserProvider ;
16
17
17
18
/**
18
19
* @author Grégoire Pineau <lyrixx@lyrixx.info>
@@ -42,7 +43,7 @@ class LdapClient implements LdapClientInterface
42
43
* @param bool $useStartTls
43
44
* @param bool $optReferrals
44
45
*/
45
- public function __construct ($ host = null , $ port = 389 , $ version = 3 , $ useSsl = false , $ useStartTls = false , $ optReferrals = false )
46
+ public function __construct ($ host = null , $ port = 389 , $ version = 3 , $ useSsl = false , $ useStartTls = false , $ optReferrals = false , $ ldapBaseDn = null , $ ldapSearchDn = null , $ ldapSearchPassword = null , $ ldapUidKey = null , $ ldapFilter = null )
46
47
{
47
48
if (!extension_loaded ('ldap ' )) {
48
49
throw new LdapException ('The ldap module is needed. ' );
@@ -54,6 +55,11 @@ public function __construct($host = null, $port = 389, $version = 3, $useSsl = f
54
55
$ this ->useSsl = (bool ) $ useSsl ;
55
56
$ this ->useStartTls = (bool ) $ useStartTls ;
56
57
$ this ->optReferrals = (bool ) $ optReferrals ;
58
+ $ this ->ldapBaseDn = $ ldapBaseDn ;
59
+ $ this ->ldapSearchDn = $ ldapSearchDn ;
60
+ $ this ->ldapSearchPassword = $ ldapSearchPassword ;
61
+ $ this ->ldapUidKey = $ ldapUidKey ;
62
+ $ this ->ldapFilter = $ ldapFilter ;
57
63
}
58
64
59
65
public function __destruct ()
@@ -70,16 +76,14 @@ public function bind($dn = null, $password = null)
70
76
$ this ->connect ();
71
77
}
72
78
73
- $ dnArr = explode ('; ' ,$ dn );
74
- if (count ($ dnArr ) > 1 )
75
- {
76
- $ searchResult = $ this ->find ($ dnArr [1 ], $ dnArr [0 ], '* ' );
77
-
78
- if (count ($ searchResult ))
79
- {
80
- $ dn = $ searchResult [0 ]['dn ' ];
79
+ if ($ this ->ldapBaseDn && $ this ->ldapSearchDn ){
80
+ $ ldapUserProvider = new LdapUserProvider ($ this , $ this ->ldapBaseDn , $ this ->ldapSearchDn , $ this ->ldapSearchPassword , null , $ this ->ldapUidKey , $ this ->ldapFilter );
81
+ $ ldapUser = $ ldapUserProvider ->getUser ($ dn );
82
+ if (count ($ ldapUser )){
83
+ $ dn = $ ldapUser ['dn ' ];
81
84
}
82
85
}
86
+
83
87
if (false === @ldap_bind ($ this ->connection , $ dn , $ password )) {
84
88
throw new ConnectionException (ldap_error ($ this ->connection ));
85
89
}
0 commit comments