1010use OCA \User_LDAP \User \DeletedUsersIndex ;
1111use OCA \User_LDAP \User \OfflineUser ;
1212use OCA \User_LDAP \User \User ;
13+ use OCP \IUser ;
1314use OCP \IUserBackend ;
15+ use OCP \IUserManager ;
16+ use OCP \LDAP \Exceptions \MultipleUsersReturnedException ;
1417use OCP \Notification \IManager as INotificationManager ;
1518use OCP \User \Backend \ICountMappedUsersBackend ;
1619use OCP \User \Backend \IGetDisplayNameBackend ;
2528 */
2629class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend, IGetDisplayNameBackend, IPropertyPermissionBackend {
2730 public function __construct (
28- private Helper $ helper ,
31+ Helper $ helper ,
2932 ILDAPWrapper $ ldap ,
3033 AccessFactory $ accessFactory ,
31- private INotificationManager $ notificationManager ,
32- private UserPluginManager $ userPluginManager ,
33- private LoggerInterface $ logger ,
34- private DeletedUsersIndex $ deletedUsersIndex ,
34+ private readonly INotificationManager $ notificationManager ,
35+ private readonly UserPluginManager $ userPluginManager ,
36+ private readonly LoggerInterface $ logger ,
37+ private readonly DeletedUsersIndex $ deletedUsersIndex ,
38+ private readonly IUserManager $ userManager ,
3539 ) {
3640 parent ::__construct ($ helper , $ ldap , $ accessFactory );
3741 }
@@ -43,6 +47,7 @@ protected function newInstance(string $configPrefix): User_LDAP {
4347 $ this ->userPluginManager ,
4448 $ this ->logger ,
4549 $ this ->deletedUsersIndex ,
50+ $ this ->userManager ,
4651 );
4752 }
4853
@@ -437,4 +442,18 @@ public function getDisabledUserList(?int $limit = null, int $offset = 0, string
437442 public function canEditProperty (string $ uid , string $ property ): bool {
438443 return $ this ->handleRequest ($ uid , 'canEditProperty ' , [$ uid , $ property ]);
439444 }
445+
446+ public function getUserFromCustomAttribute (string $ attribute , string $ searchTerm ): ?IUser {
447+ $ this ->setup ();
448+ $ user = null ;
449+ foreach ($ this ->backends as $ backend ) {
450+ $ fetchUser = $ backend ->getUserFromCustomAttribute ($ attribute , $ searchTerm );
451+ // if we found a different user, no need to continue
452+ if ($ user !== null && $ fetchUser !== null && $ fetchUser ->getUID () !== $ user ->getUID ()) {
453+ throw new MultipleUsersReturnedException ('Multiple users found for custom attribute search ' );
454+ }
455+ $ user = $ fetchUser ; // may be null
456+ }
457+ return $ user ;
458+ }
440459}
0 commit comments