3737namespace OCA \User_LDAP ;
3838
3939use OC \ServerNotAvailableException ;
40- use OCP \ ILogger ;
40+ use Psr \ Log \ LoggerInterface ;
4141
4242/**
4343 * magic properties (incomplete)
@@ -103,6 +103,9 @@ class Connection extends LDAPUtility {
103103
104104 protected $ bindResult = [];
105105
106+ /** @var LoggerInterface */
107+ protected $ logger ;
108+
106109 /**
107110 * Constructor
108111 * @param ILDAPWrapper $ldap
@@ -122,6 +125,7 @@ public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID =
122125 $ helper = new Helper (\OC ::$ server ->getConfig (), \OC ::$ server ->getDatabaseConnection ());
123126 $ this ->doNotValidate = !in_array ($ this ->configPrefix ,
124127 $ helper ->getServerConfigurationPrefixes ());
128+ $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
125129 }
126130
127131 public function __destruct () {
@@ -208,7 +212,10 @@ public function getConnectionResource() {
208212 $ this ->establishConnection ();
209213 }
210214 if (is_null ($ this ->ldapConnectionRes )) {
211- \OCP \Util::writeLog ('user_ldap ' , 'No LDAP Connection to server ' . $ this ->configuration ->ldapHost , ILogger::ERROR );
215+ $ this ->logger ->error (
216+ 'No LDAP Connection to server ' . $ this ->configuration ->ldapHost ,
217+ ['app ' => 'user_ldap ' ]
218+ );
212219 throw new ServerNotAvailableException ('Connection to LDAP server could not be established ' );
213220 }
214221 return $ this ->ldapConnectionRes ;
@@ -378,10 +385,10 @@ private function doSoftValidation() {
378385 && (!is_null ($ this ->configID ))) {
379386 $ this ->configuration ->$ effectiveSetting = 'auto ' ;
380387 $ this ->configuration ->saveConfiguration ();
381- \ OCP \Util:: writeLog ( ' user_ldap ' ,
382- 'Illegal value for the ' .
383- $ effectiveSetting . ' , ' . ' reset to ' .
384- ' autodetect. ' , ILogger:: INFO );
388+ $ this -> logger -> info (
389+ 'Illegal value for the ' .$ effectiveSetting . ' , reset to autodetect. ' ,
390+ [ ' app ' => ' user_ldap ' ]
391+ );
385392 }
386393 }
387394 }
@@ -404,10 +411,9 @@ private function doSoftValidation() {
404411 if ((stripos ($ this ->configuration ->ldapHost , 'ldaps:// ' ) === 0 )
405412 && $ this ->configuration ->ldapTLS ) {
406413 $ this ->configuration ->ldapTLS = false ;
407- \OCP \Util::writeLog (
408- 'user_ldap ' ,
414+ $ this ->logger ->info (
409415 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS. ' ,
410- ILogger:: INFO
416+ [ ' app ' => ' user_ldap ' ]
411417 );
412418 }
413419 }
@@ -447,10 +453,9 @@ private function doCriticalValidation() {
447453 break ;
448454 }
449455 $ configurationOK = false ;
450- \OCP \Util::writeLog (
451- 'user_ldap ' ,
456+ $ this ->logger ->warning (
452457 $ errorStr .'No ' .$ subj .' given! ' ,
453- ILogger:: WARN
458+ [ ' app ' => ' user_ldap ' ]
454459 );
455460 }
456461 }
@@ -462,11 +467,11 @@ private function doCriticalValidation() {
462467 ($ agent === '' && $ pwd !== '' )
463468 || ($ agent !== '' && $ pwd === '' )
464469 ) {
465- \OCP \Util::writeLog (
466- 'user_ldap ' ,
470+ $ this ->logger ->warning (
467471 $ errorStr .'either no password is given for the user ' .
468472 'agent or a password is given, but not an LDAP agent. ' ,
469- ILogger::WARN );
473+ ['app ' => 'user_ldap ' ]
474+ );
470475 $ configurationOK = false ;
471476 }
472477
@@ -475,20 +480,18 @@ private function doCriticalValidation() {
475480 $ baseGroups = $ this ->configuration ->ldapBaseGroups ;
476481
477482 if (empty ($ base ) && empty ($ baseUsers ) && empty ($ baseGroups )) {
478- \OCP \Util::writeLog (
479- 'user_ldap ' ,
483+ $ this ->logger ->warning (
480484 $ errorStr .'Not a single Base DN given. ' ,
481- ILogger:: WARN
485+ [ ' app ' => ' user_ldap ' ]
482486 );
483487 $ configurationOK = false ;
484488 }
485489
486490 if (mb_strpos ($ this ->configuration ->ldapLoginFilter , '%uid ' , 0 , 'UTF-8 ' )
487491 === false ) {
488- \OCP \Util::writeLog (
489- 'user_ldap ' ,
492+ $ this ->logger ->warning (
490493 $ errorStr .'login filter does not contain %uid place holder. ' ,
491- ILogger:: WARN
494+ [ ' app ' => ' user_ldap ' ]
492495 );
493496 $ configurationOK = false ;
494497 }
@@ -532,34 +535,32 @@ private function establishConnection() {
532535 return false ;
533536 }
534537 if (!$ this ->ignoreValidation && !$ this ->configured ) {
535- \OCP \Util::writeLog (
536- 'user_ldap ' ,
538+ $ this ->logger ->warning (
537539 'Configuration is invalid, cannot connect ' ,
538- ILogger:: WARN
540+ [ ' app ' => ' user_ldap ' ]
539541 );
540542 return false ;
541543 }
542544 if (!$ this ->ldapConnectionRes ) {
543545 if (!$ this ->ldap ->areLDAPFunctionsAvailable ()) {
544546 $ phpLDAPinstalled = false ;
545- \OCP \Util::writeLog (
546- 'user_ldap ' ,
547+ $ this ->logger ->error (
547548 'function ldap_connect is not available. Make sure that the PHP ldap module is installed. ' ,
548- ILogger:: ERROR
549+ [ ' app ' => ' user_ldap ' ]
549550 );
550551
551552 return false ;
552553 }
553554 if ($ this ->configuration ->turnOffCertCheck ) {
554555 if (putenv ('LDAPTLS_REQCERT=never ' )) {
555- \ OCP \Util:: writeLog ( ' user_ldap ' ,
556+ $ this -> logger -> debug (
556557 'Turned off SSL certificate validation successfully. ' ,
557- ILogger::DEBUG );
558+ ['app ' => 'user_ldap ' ]
559+ );
558560 } else {
559- \OCP \Util::writeLog (
560- 'user_ldap ' ,
561+ $ this ->logger ->warning (
561562 'Could not turn off SSL certificate validation. ' ,
562- ILogger:: WARN
563+ [ ' app ' => ' user_ldap ' ]
563564 );
564565 }
565566 }
@@ -669,9 +670,10 @@ public function bind() {
669670 if (!$ ldapLogin ) {
670671 $ errno = $ this ->ldap ->errno ($ cr );
671672
672- \ OCP \Util:: writeLog ( ' user_ldap ' ,
673+ $ this -> logger -> warning (
673674 'Bind failed: ' . $ errno . ': ' . $ this ->ldap ->error ($ cr ),
674- ILogger::WARN );
675+ ['app ' => 'user_ldap ' ]
676+ );
675677
676678 // Set to failure mode, if LDAP error code is not one of
677679 // - LDAP_SUCCESS (0)
0 commit comments