diff --git a/src/Authenticators/LDAPAuthenticator.php b/src/Authenticators/LDAPAuthenticator.php index a97374b..d498c35 100644 --- a/src/Authenticators/LDAPAuthenticator.php +++ b/src/Authenticators/LDAPAuthenticator.php @@ -60,7 +60,7 @@ class LDAPAuthenticator extends MemberAuthenticator */ public static function get_name() { - return Config::inst()->get(self::class, 'name'); + return Config::inst()->get(LDAPAuthenticator::class, 'name'); } /** @@ -86,7 +86,7 @@ public function authenticate(array $data, HTTPRequest $request, ValidationResult $service = Injector::inst()->get(LDAPService::class); $login = trim($data['Login'] ?? ''); if (Email::is_valid_address($login)) { - if (Config::inst()->get(self::class, 'allow_email_login') != 'yes') { + if (Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') != 'yes') { $result->addError( _t( __CLASS__ . '.PLEASEUSEUSERNAME', @@ -99,7 +99,7 @@ public function authenticate(array $data, HTTPRequest $request, ValidationResult // No user found with this email. if (!$username) { - if (Config::inst()->get(self::class, 'fallback_authenticator') === 'yes') { + if (Config::inst()->get(LDAPAuthenticator::class, 'fallback_authenticator') === 'yes') { if ($fallbackMember = $this->fallbackAuthenticate($data, $request)) { { return $fallbackMember; @@ -122,7 +122,7 @@ public function authenticate(array $data, HTTPRequest $request, ValidationResult * Try the fallback method if admin or it failed for anything other than invalid credentials * This is to avoid having an unhandled exception error thrown by PasswordEncryptor::create_for_algorithm() */ - if (Config::inst()->get(self::class, 'fallback_authenticator') === 'yes') { + if (Config::inst()->get(LDAPAuthenticator::class, 'fallback_authenticator') === 'yes') { if (!in_array($serviceAuthenticationResult['code'], [Result::FAILURE_CREDENTIAL_INVALID]) || $username === 'admin' ) { @@ -176,7 +176,7 @@ protected function fallbackAuthenticate($data, HTTPRequest $request) if (array_key_exists('Login', $data ?? []) && !array_key_exists('Email', $data ?? [])) { $data['Email'] = $data['Login']; } - $authenticatorClass = Config::inst()->get(self::class, 'fallback_authenticator_class'); + $authenticatorClass = Config::inst()->get(LDAPAuthenticator::class, 'fallback_authenticator_class'); if ($authenticator = Injector::inst()->get($authenticatorClass)) { $result = call_user_func( [ @@ -226,7 +226,7 @@ public function checkPassword(Member $member, $password, ValidationResult &$resu $service = Injector::inst()->get(LDAPService::class); // Support email or username - $handle = Config::inst()->get(self::class, 'allow_email_login') === 'yes' ? 'Email' : 'Username'; + $handle = Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') === 'yes' ? 'Email' : 'Username'; $ldapResult = $service->authenticate($member->{$handle}, $password); diff --git a/src/Control/LDAPDebugController.php b/src/Control/LDAPDebugController.php index 271bb2f..837582f 100644 --- a/src/Control/LDAPDebugController.php +++ b/src/Control/LDAPDebugController.php @@ -60,7 +60,7 @@ protected function init() */ public function index(HTTPRequest $request) { - return $this->renderWith([self::class]); + return $this->renderWith([LDAPDebugController::class]); } public function Options() diff --git a/src/Model/LDAPGateway.php b/src/Model/LDAPGateway.php index e4f42e9..6fd7b39 100644 --- a/src/Model/LDAPGateway.php +++ b/src/Model/LDAPGateway.php @@ -86,7 +86,7 @@ protected function search($filter, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_S } /** - * Processes results from either self::search() or self::searchAll(), expecting eitheran array of records + * Processes results from either LDAPGateway::search() or LDAPGateway::searchAll(), expecting eitheran array of records * * @param Iterator $records * @return array diff --git a/src/Model/LDAPUtil.php b/src/Model/LDAPUtil.php index bf2af5b..e61bf60 100644 --- a/src/Model/LDAPUtil.php +++ b/src/Model/LDAPUtil.php @@ -94,7 +94,7 @@ public static function bin_to_str_sid($binsid) $result = "$rev-$auth"; for ($x = 0; $x < $subcount; $x++) { - $subauth[$x] = hexdec(self::little_endian(substr($hex_sid ?? '', 16 + ($x * 8), 8)) ?? ''); + $subauth[$x] = hexdec(LDAPUtil::little_endian(substr($hex_sid ?? '', 16 + ($x * 8), 8)) ?? ''); $result .= '-' . $subauth[$x]; } diff --git a/src/Services/LDAPService.php b/src/Services/LDAPService.php index 2d8f019..a3bc970 100644 --- a/src/Services/LDAPService.php +++ b/src/Services/LDAPService.php @@ -133,7 +133,7 @@ public static function get_cache() */ public static function flush() { - $cache = self::get_cache(); + $cache = LDAPService::get_cache(); $cache->clear(); } @@ -230,7 +230,7 @@ public function authenticate($username, $password) */ public function getNodes($cached = true, $attributes = []) { - $cache = self::get_cache(); + $cache = LDAPService::get_cache(); $cacheKey = 'nodes' . md5(implode('', $attributes)); $results = $cache->has($cacheKey); @@ -260,7 +260,7 @@ public function getNodes($cached = true, $attributes = []) public function getGroups($cached = true, $attributes = [], $indexBy = 'dn') { $searchLocations = $this->config()->groups_search_locations ?: [null]; - $cache = self::get_cache(); + $cache = LDAPService::get_cache(); $cacheKey = 'groups' . md5(implode('', array_merge($searchLocations, $attributes))); $results = $cache->has($cacheKey); @@ -297,8 +297,8 @@ public function getGroups($cached = true, $attributes = [], $indexBy = 'dn') */ public function getNestedGroups($dn, $attributes = []) { - if (isset(self::$_cache_nested_groups[$dn])) { - return self::$_cache_nested_groups[$dn]; + if (isset(LDAPService::$_cache_nested_groups[$dn])) { + return LDAPService::$_cache_nested_groups[$dn]; } $searchLocations = $this->config()->groups_search_locations ?: [null]; @@ -310,7 +310,7 @@ public function getNestedGroups($dn, $attributes = []) } } - self::$_cache_nested_groups[$dn] = $results; + LDAPService::$_cache_nested_groups[$dn] = $results; return $results; } diff --git a/tests/php/Model/LDAPFakeGateway.php b/tests/php/Model/LDAPFakeGateway.php index 989cfb9..b257fc0 100644 --- a/tests/php/Model/LDAPFakeGateway.php +++ b/tests/php/Model/LDAPFakeGateway.php @@ -13,7 +13,7 @@ public function __construct() { // thumbnail images are raw JPEG/JFIF files, but that's not important // for this test, as long as the binary content are the same - self::$data['users']['456']['thumbnailphoto'] = base64_decode(self::$data['users']['456']['thumbnailphoto'] ?? ''); + LDAPFakeGateway::$data['users']['456']['thumbnailphoto'] = base64_decode(LDAPFakeGateway::$data['users']['456']['thumbnailphoto'] ?? ''); } private static $data = [ @@ -111,7 +111,7 @@ public function getNodes($baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attri public function getGroups($baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attributes = [], $sort = '') { if (isset($baseDn)) { - return !empty(self::$data['groups'][$baseDn]) ? self::$data['groups'][$baseDn] : null; + return !empty(LDAPFakeGateway::$data['groups'][$baseDn]) ? LDAPFakeGateway::$data['groups'][$baseDn] : null; } } @@ -140,7 +140,7 @@ public function getUsers($baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attri public function getUserByGUID($guid, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attributes = []) { - return [self::$data['users'][$guid]]; + return [LDAPFakeGateway::$data['users'][$guid]]; } public function update($dn, array $attributes) @@ -161,7 +161,7 @@ public function add($dn, array $attributes) protected function search($filter, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attributes = [], $sort = '') { - $records = self::$data; + $records = LDAPFakeGateway::$data; $results = []; foreach ($records as $record) { foreach ($record as $attribute => $value) { @@ -201,7 +201,7 @@ protected function search($filter, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_S public function getUserByEmail($email, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attributes = []) { $result = []; - foreach (self::$data['users'] as $guid => $info) { + foreach (LDAPFakeGateway::$data['users'] as $guid => $info) { if ($info['mail'] == $email) { $result[] = $info; break; @@ -224,7 +224,7 @@ public function getUserByEmail($email, $baseDn = null, $scope = Ldap::SEARCH_SCO public function getUserByUsername($username, $baseDn = null, $scope = Ldap::SEARCH_SCOPE_SUB, $attributes = []) { $result = []; - foreach (self::$data['users'] as $guid => $info) { + foreach (LDAPFakeGateway::$data['users'] as $guid => $info) { if ($info['userprincipalname'] == $username) { $result[] = $info; break;