3636use  OCP \IGroup ;
3737use  OCP \IGroupManager ;
3838use  OCP \IImage ;
39+ use  OCP \IL10N ;
40+ use  OCP \ILogger ;
3941use  OCP \IUser ;
4042use  OCP \IUserManager ;
4143use  OCP \IUserSession ;
@@ -62,8 +64,25 @@ class LDAPUserManager implements ILDAPUserPlugin {
6264	private  $ ocConfig
6365	/** @var Configuration */ 
6466	private  $ configuration
67+ 	/** @var IL10N */ 
68+ 	private  $ l10n
69+ 	/** @var ILogger */ 
70+ 	private  $ logger
6571
66- 	public  function  __construct (IUserManager $ userManagerIGroupManager $ groupManagerIUserSession $ userSessionLDAPConnect $ ldapConnectIConfig $ ocConfigILDAPProvider $ ldapProviderConfiguration $ configuration
72+ 	/** 
73+ 	 * LDAPUserManager constructor. 
74+ 	 * 
75+ 	 * @param IUserManager $userManager 
76+ 	 * @param IGroupManager $groupManager 
77+ 	 * @param IUserSession $userSession 
78+ 	 * @param LDAPConnect $ldapConnect 
79+ 	 * @param IConfig $ocConfig 
80+ 	 * @param ILDAPProvider $ldapProvider 
81+ 	 * @param Configuration $configuration 
82+ 	 * @param IL10N $l10n 
83+ 	 * @param ILogger $logger 
84+ 	 */ 
85+ 	public  function  __construct (IUserManager $ userManagerIGroupManager $ groupManagerIUserSession $ userSessionLDAPConnect $ ldapConnectIConfig $ ocConfigILDAPProvider $ ldapProviderConfiguration $ configurationIL10N $ l10nILogger $ logger
6786		$ this userManager  = $ userManager
6887		$ this groupManager  = $ groupManager
6988		$ this userSession  = $ userSession
@@ -75,6 +94,8 @@ public function __construct(IUserManager $userManager, IGroupManager $groupManag
7594		$ this makeLdapBackendFirst ();
7695		$ this ldapProvider  = $ ldapProvider
7796		$ this configuration  = $ configuration
97+ 		$ this l10n  = $ l10n
98+ 		$ this logger  = $ logger
7899	}
79100
80101	/** 
@@ -93,28 +114,40 @@ public function respondToActions() {
93114	}
94115
95116	/** 
96- 	 * set display name of the user 
97117	 * 
98118	 * @param string $uid user ID of the user 
99119	 * @param string $displayName new user's display name 
100120	 * @return bool 
121+ 	 * @throws HintException 
101122	 */ 
102123	public  function  setDisplayName ($ uid$ displayName
103124		$ userDN$ this getUserDN ($ uid
104125
105126		$ connection$ this ldapProvider ->getLDAPConnection ($ uid
106127
107- 		$ displayNameField$ this ldapProvider ->getLDAPDisplayNameField ($ uid
128+ 		try  {
129+ 			$ displayNameField$ this ldapProvider ->getLDAPDisplayNameField ($ uid
130+ 			// The LDAP backend supports a second display name field, but it is 
131+ 			// not exposed at this time. So it is just ignored for now. 
132+ 		} catch  (\Exception   $ e
133+ 			throw  new  HintException (
134+ 				'Corresponding LDAP User not found ' ,
135+ 				$ this l10n ->t ('Could not find related LDAP entry ' )
136+ 			);
137+ 		}
108138
109139		if  (!is_resource ($ connection
110- 			//LDAP not available 
111- 			\OCP \Util::writeLog ('user_ldap ' , 'LDAP resource not available. ' , \OCP \Util::DEBUG );
140+ 			$ this logger ->debug ('LDAP resource not available ' , ['app '  => 'ldap_write_support ' ]);
112141			return  false ;
113142		}
114143		try  {
115- 			return  ldap_mod_replace ($ connection$ userDN$ displayNameField$ displayName
116- 		} catch (ConstraintViolationException $ e
117- 			throw  new  HintException ('DisplayName change rejected. ' , \OC ::$ servergetL10N ('user_ldap ' )->t ('DisplayName change rejected. Hint:  ' ).$ egetMessage (), $ egetCode ());
144+ 			return  ldap_mod_replace ($ connection$ userDN$ displayNameField$ displayName
145+ 		} catch  (ConstraintViolationException $ e
146+ 			throw  new  HintException (
147+ 				$ egetMessage (),
148+ 				$ this l10n ->t ('DisplayName change rejected ' ),
149+ 				$ egetCode ()
150+ 			);
118151		}
119152	}
120153
@@ -180,7 +213,7 @@ public function createUser($username, $password) {
180213		$ requireActorFromLDAPbool )$ this ocConfig ->getAppValue ('ldap_write_support ' , 'create.requireActorFromLDAP ' , '1 ' );
181214		$ adminUser$ this userSession ->getUser ();
182215		if ($ requireActorFromLDAP$ adminUserinstanceof  IUser) {
183- 			throw  new  \Exception ('Acting user is not a user  ' );
216+ 			throw  new  \Exception ('Acting user is not from LDAP  ' );
184217		}
185218		try  {
186219			$ connection$ this ldapProvider ->getLDAPConnection ($ adminUsergetUID ());
0 commit comments