11
11
12
12
namespace Symfony \Component \Ldap \Security ;
13
13
14
+ use Doctrine \Common \Persistence \ManagerRegistry ;
14
15
use Symfony \Component \Ldap \Entry ;
15
16
use Symfony \Component \Ldap \Exception \ConnectionException ;
16
17
use Symfony \Component \Ldap \Exception \ExceptionInterface ;
31
32
*/
32
33
class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterface
33
34
{
35
+ private $ managerRegistry ;
34
36
private $ ldap ;
35
37
private $ baseDn ;
36
38
private $ searchDn ;
@@ -41,7 +43,7 @@ class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterfa
41
43
private $ passwordAttribute ;
42
44
private $ extraFields ;
43
45
44
- public function __construct (LdapInterface $ ldap , string $ baseDn , string $ searchDn = null , string $ searchPassword = null , array $ defaultRoles = [], string $ uidKey = null , string $ filter = null , string $ passwordAttribute = null , array $ extraFields = [])
46
+ public function __construct (ManagerRegistry $ managerRegistry , LdapInterface $ ldap , string $ baseDn , string $ searchDn = null , string $ searchPassword = null , array $ defaultRoles = [], string $ uidKey = null , string $ filter = null , string $ passwordAttribute = null , array $ extraFields = [])
45
47
{
46
48
if (null === $ uidKey ) {
47
49
$ uidKey = 'sAMAccountName ' ;
@@ -51,6 +53,7 @@ public function __construct(LdapInterface $ldap, string $baseDn, string $searchD
51
53
$ filter = '({uid_key}={username}) ' ;
52
54
}
53
55
56
+ $ this ->managerRegistry = $ managerRegistry ;
54
57
$ this ->ldap = $ ldap ;
55
58
$ this ->baseDn = $ baseDn ;
56
59
$ this ->searchDn = $ searchDn ;
@@ -108,7 +111,7 @@ public function refreshUser(UserInterface $user)
108
111
throw new UnsupportedUserException (sprintf ('Instances of "%s" are not supported. ' , \get_class ($ user )));
109
112
}
110
113
111
- return new LdapUser ( $ user -> getEntry (), $ user -> getUsername (), $ user-> getPassword (), $ user ->getRoles () );
114
+ return $ this -> managerRegistry -> getRepository ( \get_class ( $ user))-> findOneBy ([ ' username ' => $ user ->getUsername ()] );
112
115
}
113
116
114
117
/**
0 commit comments