19
19
* @author Tobias Perschon <[email protected] >
20
20
* @author Victor Dubiniuk <[email protected] >
21
21
* @author Xuanwo <[email protected] >
22
+ * @author Vincent Van Houtte <[email protected] >
22
23
*
23
24
* @license AGPL-3.0
24
25
*
@@ -97,7 +98,10 @@ public function __destruct() {
97
98
* @throws \Exception
98
99
*/
99
100
public function countEntries (string $ filter , string $ type ): int {
100
- $ reqs = ['ldapHost ' , 'ldapPort ' , 'ldapBase ' ];
101
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
102
+ if ($ this ->configuration ->usesLdapi () === false ) {
103
+ $ reqs [] = 'ldapPort ' ;
104
+ }
101
105
if ($ type === 'users ' ) {
102
106
$ reqs [] = 'ldapUserFilter ' ;
103
107
}
@@ -196,11 +200,11 @@ public function countInBaseDN() {
196
200
* @return int|bool
197
201
*/
198
202
public function countUsersWithAttribute ($ attr , $ existsCheck = false ) {
199
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
200
- ' ldapPort ' ,
201
- ' ldapBase ' ,
202
- ' ldapUserFilter ' ,
203
- ] )) {
203
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
204
+ if ( $ this -> configuration -> usesLdapi () === false ) {
205
+ $ reqs [] = ' ldapPort ' ;
206
+ }
207
+ if (! $ this -> checkRequirements ( $ reqs )) {
204
208
return false ;
205
209
}
206
210
@@ -221,11 +225,11 @@ public function countUsersWithAttribute($attr, $existsCheck = false) {
221
225
* @throws \Exception
222
226
*/
223
227
public function detectUserDisplayNameAttribute () {
224
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
225
- ' ldapPort ' ,
226
- ' ldapBase ' ,
227
- ' ldapUserFilter ' ,
228
- ] )) {
228
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
229
+ if ( $ this -> configuration -> usesLdapi () === false ) {
230
+ $ reqs [] = ' ldapPort ' ;
231
+ }
232
+ if (! $ this -> checkRequirements ( $ reqs )) {
229
233
return false ;
230
234
}
231
235
@@ -263,11 +267,11 @@ public function detectUserDisplayNameAttribute() {
263
267
* @return WizardResult|bool
264
268
*/
265
269
public function detectEmailAttribute () {
266
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
267
- ' ldapPort ' ,
268
- ' ldapBase ' ,
269
- ' ldapUserFilter ' ,
270
- ] )) {
270
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
271
+ if ( $ this -> configuration -> usesLdapi () === false ) {
272
+ $ reqs [] = ' ldapPort ' ;
273
+ }
274
+ if (! $ this -> checkRequirements ( $ reqs )) {
271
275
return false ;
272
276
}
273
277
@@ -312,11 +316,11 @@ public function detectEmailAttribute() {
312
316
* @throws \Exception
313
317
*/
314
318
public function determineAttributes () {
315
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
316
- ' ldapPort ' ,
317
- ' ldapBase ' ,
318
- ' ldapUserFilter ' ,
319
- ] )) {
319
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
320
+ if ( $ this -> configuration -> usesLdapi () === false ) {
321
+ $ reqs [] = ' ldapPort ' ;
322
+ }
323
+ if (! $ this -> checkRequirements ( $ reqs )) {
320
324
return false ;
321
325
}
322
326
@@ -341,11 +345,11 @@ public function determineAttributes() {
341
345
* @throws \Exception
342
346
*/
343
347
private function getUserAttributes () {
344
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
345
- ' ldapPort ' ,
346
- ' ldapBase ' ,
347
- ' ldapUserFilter ' ,
348
- ] )) {
348
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
349
+ if ( $ this -> configuration -> usesLdapi () === false ) {
350
+ $ reqs [] = ' ldapPort ' ;
351
+ }
352
+ if (! $ this -> checkRequirements ( $ reqs )) {
349
353
return false ;
350
354
}
351
355
$ cr = $ this ->getConnection ();
@@ -397,10 +401,11 @@ public function determineGroupsForUsers() {
397
401
* @throws \Exception
398
402
*/
399
403
private function determineGroups ($ dbKey , $ confKey , $ testMemberOf = true ) {
400
- if (!$ this ->checkRequirements (['ldapHost ' ,
401
- 'ldapPort ' ,
402
- 'ldapBase ' ,
403
- ])) {
404
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
405
+ if ($ this ->configuration ->usesLdapi () === false ) {
406
+ $ reqs [] = 'ldapPort ' ;
407
+ }
408
+ if (!$ this ->checkRequirements ($ reqs )) {
404
409
return false ;
405
410
}
406
411
$ cr = $ this ->getConnection ();
@@ -477,10 +482,11 @@ public function fetchGroups($dbKey, $confKey) {
477
482
}
478
483
479
484
public function determineGroupMemberAssoc () {
480
- if (!$ this ->checkRequirements (['ldapHost ' ,
481
- 'ldapPort ' ,
482
- 'ldapGroupFilter ' ,
483
- ])) {
485
+ $ reqs = ['ldapHost ' , 'ldapGroupFilter ' ];
486
+ if ($ this ->configuration ->usesLdapi () === false ) {
487
+ $ reqs [] = 'ldapPort ' ;
488
+ }
489
+ if (!$ this ->checkRequirements ($ reqs )) {
484
490
return false ;
485
491
}
486
492
$ attribute = $ this ->detectGroupMemberAssoc ();
@@ -499,10 +505,11 @@ public function determineGroupMemberAssoc() {
499
505
* @throws \Exception
500
506
*/
501
507
public function determineGroupObjectClasses () {
502
- if (!$ this ->checkRequirements (['ldapHost ' ,
503
- 'ldapPort ' ,
504
- 'ldapBase ' ,
505
- ])) {
508
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
509
+ if ($ this ->configuration ->usesLdapi () === false ) {
510
+ $ reqs [] = 'ldapPort ' ;
511
+ }
512
+ if (!$ this ->checkRequirements ($ reqs )) {
506
513
return false ;
507
514
}
508
515
$ cr = $ this ->getConnection ();
@@ -526,10 +533,11 @@ public function determineGroupObjectClasses() {
526
533
* @throws \Exception
527
534
*/
528
535
public function determineUserObjectClasses () {
529
- if (!$ this ->checkRequirements (['ldapHost ' ,
530
- 'ldapPort ' ,
531
- 'ldapBase ' ,
532
- ])) {
536
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
537
+ if ($ this ->configuration ->usesLdapi () === false ) {
538
+ $ reqs [] = 'ldapPort ' ;
539
+ }
540
+ if (!$ this ->checkRequirements ($ reqs )) {
533
541
return false ;
534
542
}
535
543
$ cr = $ this ->getConnection ();
@@ -556,10 +564,11 @@ public function determineUserObjectClasses() {
556
564
* @throws \Exception
557
565
*/
558
566
public function getGroupFilter () {
559
- if (!$ this ->checkRequirements (['ldapHost ' ,
560
- 'ldapPort ' ,
561
- 'ldapBase ' ,
562
- ])) {
567
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
568
+ if ($ this ->configuration ->usesLdapi () === false ) {
569
+ $ reqs [] = 'ldapPort ' ;
570
+ }
571
+ if (!$ this ->checkRequirements ($ reqs )) {
563
572
return false ;
564
573
}
565
574
//make sure the use display name is set
@@ -580,10 +589,11 @@ public function getGroupFilter() {
580
589
* @throws \Exception
581
590
*/
582
591
public function getUserListFilter () {
583
- if (!$ this ->checkRequirements (['ldapHost ' ,
584
- 'ldapPort ' ,
585
- 'ldapBase ' ,
586
- ])) {
592
+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
593
+ if ($ this ->configuration ->usesLdapi () === false ) {
594
+ $ reqs [] = 'ldapPort ' ;
595
+ }
596
+ if (!$ this ->checkRequirements ($ reqs )) {
587
597
return false ;
588
598
}
589
599
//make sure the use display name is set
@@ -606,11 +616,11 @@ public function getUserListFilter() {
606
616
* @throws \Exception
607
617
*/
608
618
public function getUserLoginFilter () {
609
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
610
- ' ldapPort ' ,
611
- ' ldapBase ' ,
612
- ' ldapUserFilter ' ,
613
- ] )) {
619
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
620
+ if ( $ this -> configuration -> usesLdapi () === false ) {
621
+ $ reqs [] = ' ldapPort ' ;
622
+ }
623
+ if (! $ this -> checkRequirements ( $ reqs )) {
614
624
return false ;
615
625
}
616
626
@@ -629,11 +639,11 @@ public function getUserLoginFilter() {
629
639
* @throws \Exception
630
640
*/
631
641
public function testLoginName ($ loginName ) {
632
- if (! $ this -> checkRequirements ( ['ldapHost ' ,
633
- ' ldapPort ' ,
634
- ' ldapBase ' ,
635
- ' ldapLoginFilter ' ,
636
- ] )) {
642
+ $ reqs = ['ldapHost ' , ' ldapBase ' , ' ldapUserFilter ' ];
643
+ if ( $ this -> configuration -> usesLdapi () === false ) {
644
+ $ reqs [] = ' ldapPort ' ;
645
+ }
646
+ if (! $ this -> checkRequirements ( $ reqs )) {
637
647
return false ;
638
648
}
639
649
@@ -722,9 +732,11 @@ public function guessPortAndTLS() {
722
732
* @return WizardResult|false WizardResult on success, false otherwise
723
733
*/
724
734
public function guessBaseDN () {
725
- if (!$ this ->checkRequirements (['ldapHost ' ,
726
- 'ldapPort ' ,
727
- ])) {
735
+ $ reqs = ['ldapHost ' ];
736
+ if ($ this ->configuration ->usesLdapi () === false ) {
737
+ $ reqs [] = 'ldapPort ' ;
738
+ }
739
+ if (!$ this ->checkRequirements ($ reqs )) {
728
740
return false ;
729
741
}
730
742
@@ -1366,6 +1378,8 @@ private function getPortSettingsToTry() {
1366
1378
$ portSettings [] = ['port ' => $ port , 'tls ' => true ];
1367
1379
}
1368
1380
$ portSettings [] = ['port ' => $ port , 'tls ' => false ];
1381
+ } elseif ($ this ->configuration ->usesLdapi ()) {
1382
+ $ portSettings [] = ['port ' => '' , 'tls ' => false ];
1369
1383
}
1370
1384
1371
1385
//default ports
0 commit comments