1919 * @author Tobias Perschon <[email protected] > 2020 * @author Victor Dubiniuk <[email protected] > 2121 * @author Xuanwo <[email protected] > 22+ * @author Vincent Van Houtte <[email protected] > 2223 *
2324 * @license AGPL-3.0
2425 *
@@ -97,7 +98,10 @@ public function __destruct() {
9798 * @throws \Exception
9899 */
99100 public function countEntries (string $ filter , string $ type ): int {
100- $ reqs = ['ldapHost ' , 'ldapPort ' , 'ldapBase ' ];
101+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
102+ if (!$ this ->configuration ->usesLdapi ()) {
103+ $ reqs [] = 'ldapPort ' ;
104+ }
101105 if ($ type === 'users ' ) {
102106 $ reqs [] = 'ldapUserFilter ' ;
103107 }
@@ -196,11 +200,11 @@ public function countInBaseDN() {
196200 * @return int|bool
197201 */
198202 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 ()) {
205+ $ reqs [] = ' ldapPort ' ;
206+ }
207+ if (! $ this -> checkRequirements ( $ reqs )) {
204208 return false ;
205209 }
206210
@@ -221,11 +225,11 @@ public function countUsersWithAttribute($attr, $existsCheck = false) {
221225 * @throws \Exception
222226 */
223227 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 ()) {
230+ $ reqs [] = ' ldapPort ' ;
231+ }
232+ if (! $ this -> checkRequirements ( $ reqs )) {
229233 return false ;
230234 }
231235
@@ -263,11 +267,11 @@ public function detectUserDisplayNameAttribute() {
263267 * @return WizardResult|bool
264268 */
265269 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 ()) {
272+ $ reqs [] = ' ldapPort ' ;
273+ }
274+ if (! $ this -> checkRequirements ( $ reqs )) {
271275 return false ;
272276 }
273277
@@ -312,11 +316,11 @@ public function detectEmailAttribute() {
312316 * @throws \Exception
313317 */
314318 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 ()) {
321+ $ reqs [] = ' ldapPort ' ;
322+ }
323+ if (! $ this -> checkRequirements ( $ reqs )) {
320324 return false ;
321325 }
322326
@@ -341,11 +345,11 @@ public function determineAttributes() {
341345 * @throws \Exception
342346 */
343347 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 ()) {
350+ $ reqs [] = ' ldapPort ' ;
351+ }
352+ if (! $ this -> checkRequirements ( $ reqs )) {
349353 return false ;
350354 }
351355 $ cr = $ this ->getConnection ();
@@ -397,10 +401,11 @@ public function determineGroupsForUsers() {
397401 * @throws \Exception
398402 */
399403 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 ()) {
406+ $ reqs [] = 'ldapPort ' ;
407+ }
408+ if (!$ this ->checkRequirements ($ reqs )) {
404409 return false ;
405410 }
406411 $ cr = $ this ->getConnection ();
@@ -477,10 +482,11 @@ public function fetchGroups($dbKey, $confKey) {
477482 }
478483
479484 public function determineGroupMemberAssoc () {
480- if (!$ this ->checkRequirements (['ldapHost ' ,
481- 'ldapPort ' ,
482- 'ldapGroupFilter ' ,
483- ])) {
485+ $ reqs = ['ldapHost ' , 'ldapGroupFilter ' ];
486+ if (!$ this ->configuration ->usesLdapi ()) {
487+ $ reqs [] = 'ldapPort ' ;
488+ }
489+ if (!$ this ->checkRequirements ($ reqs )) {
484490 return false ;
485491 }
486492 $ attribute = $ this ->detectGroupMemberAssoc ();
@@ -499,10 +505,11 @@ public function determineGroupMemberAssoc() {
499505 * @throws \Exception
500506 */
501507 public function determineGroupObjectClasses () {
502- if (!$ this ->checkRequirements (['ldapHost ' ,
503- 'ldapPort ' ,
504- 'ldapBase ' ,
505- ])) {
508+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
509+ if (!$ this ->configuration ->usesLdapi ()) {
510+ $ reqs [] = 'ldapPort ' ;
511+ }
512+ if (!$ this ->checkRequirements ($ reqs )) {
506513 return false ;
507514 }
508515 $ cr = $ this ->getConnection ();
@@ -526,10 +533,11 @@ public function determineGroupObjectClasses() {
526533 * @throws \Exception
527534 */
528535 public function determineUserObjectClasses () {
529- if (!$ this ->checkRequirements (['ldapHost ' ,
530- 'ldapPort ' ,
531- 'ldapBase ' ,
532- ])) {
536+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
537+ if (!$ this ->configuration ->usesLdapi ()) {
538+ $ reqs [] = 'ldapPort ' ;
539+ }
540+ if (!$ this ->checkRequirements ($ reqs )) {
533541 return false ;
534542 }
535543 $ cr = $ this ->getConnection ();
@@ -556,10 +564,11 @@ public function determineUserObjectClasses() {
556564 * @throws \Exception
557565 */
558566 public function getGroupFilter () {
559- if (!$ this ->checkRequirements (['ldapHost ' ,
560- 'ldapPort ' ,
561- 'ldapBase ' ,
562- ])) {
567+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
568+ if (!$ this ->configuration ->usesLdapi ()) {
569+ $ reqs [] = 'ldapPort ' ;
570+ }
571+ if (!$ this ->checkRequirements ($ reqs )) {
563572 return false ;
564573 }
565574 //make sure the use display name is set
@@ -580,10 +589,11 @@ public function getGroupFilter() {
580589 * @throws \Exception
581590 */
582591 public function getUserListFilter () {
583- if (!$ this ->checkRequirements (['ldapHost ' ,
584- 'ldapPort ' ,
585- 'ldapBase ' ,
586- ])) {
592+ $ reqs = ['ldapHost ' , 'ldapBase ' ];
593+ if (!$ this ->configuration ->usesLdapi ()) {
594+ $ reqs [] = 'ldapPort ' ;
595+ }
596+ if (!$ this ->checkRequirements ($ reqs )) {
587597 return false ;
588598 }
589599 //make sure the use display name is set
@@ -606,11 +616,11 @@ public function getUserListFilter() {
606616 * @throws \Exception
607617 */
608618 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 ()) {
621+ $ reqs [] = ' ldapPort ' ;
622+ }
623+ if (! $ this -> checkRequirements ( $ reqs )) {
614624 return false ;
615625 }
616626
@@ -629,11 +639,11 @@ public function getUserLoginFilter() {
629639 * @throws \Exception
630640 */
631641 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 ()) {
644+ $ reqs [] = ' ldapPort ' ;
645+ }
646+ if (! $ this -> checkRequirements ( $ reqs )) {
637647 return false ;
638648 }
639649
@@ -722,9 +732,11 @@ public function guessPortAndTLS() {
722732 * @return WizardResult|false WizardResult on success, false otherwise
723733 */
724734 public function guessBaseDN () {
725- if (!$ this ->checkRequirements (['ldapHost ' ,
726- 'ldapPort ' ,
727- ])) {
735+ $ reqs = ['ldapHost ' ];
736+ if (!$ this ->configuration ->usesLdapi ()) {
737+ $ reqs [] = 'ldapPort ' ;
738+ }
739+ if (!$ this ->checkRequirements ($ reqs )) {
728740 return false ;
729741 }
730742
@@ -1366,6 +1378,8 @@ private function getPortSettingsToTry() {
13661378 $ portSettings [] = ['port ' => $ port , 'tls ' => true ];
13671379 }
13681380 $ portSettings [] = ['port ' => $ port , 'tls ' => false ];
1381+ } elseif ($ this ->configuration ->usesLdapi ()) {
1382+ $ portSettings [] = ['port ' => '' , 'tls ' => false ];
13691383 }
13701384
13711385 //default ports
0 commit comments