@@ -10,6 +10,7 @@ class UnityUser
10
10
private const HOME_DIR = "/home/ " ;
11
11
12
12
private $ uid ;
13
+ private $ entry ;
13
14
14
15
// service stack
15
16
private $ LDAP ;
@@ -21,6 +22,7 @@ class UnityUser
21
22
public function __construct ($ uid , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK )
22
23
{
23
24
$ this ->uid = $ uid ;
25
+ $ this ->entry = $ LDAP ->getUserEntry ($ uid );
24
26
25
27
$ this ->LDAP = $ LDAP ;
26
28
$ this ->SQL = $ SQL ;
@@ -70,7 +72,7 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true)
70
72
//
71
73
// Create LDAP user
72
74
//
73
- $ ldapUserEntry = $ this ->getLDAPUser () ;
75
+ $ ldapUserEntry = $ this ->entry ;
74
76
75
77
if (!$ ldapUserEntry ->exists ()) {
76
78
$ ldapUserEntry ->setAttribute ("objectclass " , UnityLDAP::POSIX_ACCOUNT_CLASS );
@@ -141,16 +143,6 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true)
141
143
}
142
144
}
143
145
144
- /**
145
- * Returns the ldap account entry corresponding to the user
146
- *
147
- * @return ldapEntry posix account
148
- */
149
- public function getLDAPUser ()
150
- {
151
- return $ this ->LDAP ->getUserEntry ($ this ->uid );
152
- }
153
-
154
146
/**
155
147
* Returns the ldap group entry corresponding to the user
156
148
*
@@ -163,7 +155,7 @@ public function getLDAPGroup()
163
155
164
156
public function exists ()
165
157
{
166
- return $ this ->getLDAPUser () ->exists () && $ this ->getLDAPGroup ()->exists ();
158
+ return $ this ->entry ->exists () && $ this ->getLDAPGroup ()->exists ();
167
159
}
168
160
169
161
//
@@ -182,7 +174,7 @@ public function getUID()
182
174
183
175
public function setOrg ($ org )
184
176
{
185
- $ ldap_user = $ this ->getLDAPUser () ;
177
+ $ ldap_user = $ this ->entry ;
186
178
$ ldap_user ->setAttribute ("o " , $ org );
187
179
$ ldap_user ->write ();
188
180
$ this ->REDIS ->setCache ($ this ->uid , "org " , $ org );
@@ -199,13 +191,13 @@ public function getOrg($ignorecache = false)
199
191
}
200
192
201
193
if ($ this ->exists ()) {
202
- $ org = $ this ->getLDAPUser () ->getAttribute ("o " )[0 ];
194
+ $ org = $ this ->entry ->getAttribute ("o " )[0 ];
203
195
204
196
if (!$ ignorecache ) {
205
197
$ this ->REDIS ->setCache ($ this ->getUID (), "org " , $ org );
206
198
}
207
199
208
- return $ this ->getLDAPUser () ->getAttribute ("o " )[0 ];
200
+ return $ this ->entry ->getAttribute ("o " )[0 ];
209
201
}
210
202
211
203
return null ;
@@ -218,7 +210,7 @@ public function getOrg($ignorecache = false)
218
210
*/
219
211
public function setFirstname ($ firstname , $ operator = null )
220
212
{
221
- $ ldap_user = $ this ->getLDAPUser () ;
213
+ $ ldap_user = $ this ->entry ;
222
214
$ ldap_user ->setAttribute ("givenname " , $ firstname );
223
215
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
224
216
@@ -249,7 +241,7 @@ public function getFirstname($ignorecache = false)
249
241
}
250
242
251
243
if ($ this ->exists ()) {
252
- $ firstname = $ this ->getLDAPUser () ->getAttribute ("givenname " )[0 ];
244
+ $ firstname = $ this ->entry ->getAttribute ("givenname " )[0 ];
253
245
254
246
if (!$ ignorecache ) {
255
247
$ this ->REDIS ->setCache ($ this ->getUID (), "firstname " , $ firstname );
@@ -268,7 +260,7 @@ public function getFirstname($ignorecache = false)
268
260
*/
269
261
public function setLastname ($ lastname , $ operator = null )
270
262
{
271
- $ ldap_user = $ this ->getLDAPUser () ;
263
+ $ ldap_user = $ this ->entry ;
272
264
$ ldap_user ->setAttribute ("sn " , $ lastname );
273
265
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
274
266
@@ -279,7 +271,7 @@ public function setLastname($lastname, $operator = null)
279
271
$ this ->getUID ()
280
272
);
281
273
282
- $ this ->getLDAPUser () ->write ();
274
+ $ this ->entry ->write ();
283
275
$ this ->REDIS ->setCache ($ this ->uid , "lastname " , $ lastname );
284
276
}
285
277
@@ -299,7 +291,7 @@ public function getLastname($ignorecache = false)
299
291
}
300
292
301
293
if ($ this ->exists ()) {
302
- $ lastname = $ this ->getLDAPUser () ->getAttribute ("sn " )[0 ];
294
+ $ lastname = $ this ->entry ->getAttribute ("sn " )[0 ];
303
295
304
296
if (!$ ignorecache ) {
305
297
$ this ->REDIS ->setCache ($ this ->getUID (), "lastname " , $ lastname );
@@ -324,7 +316,7 @@ public function getFullname()
324
316
*/
325
317
public function setMail ($ email , $ operator = null )
326
318
{
327
- $ ldap_user = $ this ->getLDAPUser () ;
319
+ $ ldap_user = $ this ->entry ;
328
320
$ ldap_user ->setAttribute ("mail " , $ email );
329
321
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
330
322
@@ -335,7 +327,7 @@ public function setMail($email, $operator = null)
335
327
$ this ->getUID ()
336
328
);
337
329
338
- $ this ->getLDAPUser () ->write ();
330
+ $ this ->entry ->write ();
339
331
$ this ->REDIS ->setCache ($ this ->uid , "mail " , $ email );
340
332
}
341
333
@@ -355,7 +347,7 @@ public function getMail($ignorecache = false)
355
347
}
356
348
357
349
if ($ this ->exists ()) {
358
- $ mail = $ this ->getLDAPUser () ->getAttribute ("mail " )[0 ];
350
+ $ mail = $ this ->entry ->getAttribute ("mail " )[0 ];
359
351
360
352
if (!$ ignorecache ) {
361
353
$ this ->REDIS ->setCache ($ this ->getUID (), "mail " , $ mail );
@@ -374,7 +366,7 @@ public function getMail($ignorecache = false)
374
366
*/
375
367
public function setSSHKeys ($ keys , $ operator = null , $ send_mail = true )
376
368
{
377
- $ ldapUser = $ this ->getLDAPUser () ;
369
+ $ ldapUser = $ this ->entry ;
378
370
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
379
371
$ keys_filt = array_values (array_unique ($ keys ));
380
372
if ($ ldapUser ->exists ()) {
@@ -419,7 +411,7 @@ public function getSSHKeys($ignorecache = false)
419
411
}
420
412
421
413
if ($ this ->exists ()) {
422
- $ ldapUser = $ this ->getLDAPUser () ;
414
+ $ ldapUser = $ this ->entry ;
423
415
$ result = $ ldapUser ->getAttribute ("sshpublickey " );
424
416
if (is_null ($ result )) {
425
417
$ keys = array ();
@@ -454,7 +446,7 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
454
446
if (empty ($ shell )) {
455
447
throw new Exception ("login shell must not be empty! " );
456
448
}
457
- $ ldapUser = $ this ->getLDAPUser () ;
449
+ $ ldapUser = $ this ->entry ;
458
450
if ($ ldapUser ->exists ()) {
459
451
$ ldapUser ->setAttribute ("loginshell " , $ shell );
460
452
$ ldapUser ->write ();
@@ -496,7 +488,7 @@ public function getLoginShell($ignorecache = false)
496
488
}
497
489
498
490
if ($ this ->exists ()) {
499
- $ ldapUser = $ this ->getLDAPUser () ;
491
+ $ ldapUser = $ this ->entry ;
500
492
501
493
$ loginshell = $ ldapUser ->getAttribute ("loginshell " )[0 ];
502
494
@@ -512,7 +504,7 @@ public function getLoginShell($ignorecache = false)
512
504
513
505
public function setHomeDir ($ home , $ operator = null )
514
506
{
515
- $ ldapUser = $ this ->getLDAPUser () ;
507
+ $ ldapUser = $ this ->entry ;
516
508
if ($ ldapUser ->exists ()) {
517
509
$ ldapUser ->setAttribute ("homedirectory " , $ home );
518
510
$ ldapUser ->write ();
@@ -545,7 +537,7 @@ public function getHomeDir($ignorecache = false)
545
537
}
546
538
547
539
if ($ this ->exists ()) {
548
- $ ldapUser = $ this ->getLDAPUser () ;
540
+ $ ldapUser = $ this ->entry ;
549
541
550
542
$ homedir = $ ldapUser ->getAttribute ("homedirectory " );
551
543
0 commit comments