Skip to content

Commit

Permalink
Merge pull request #80 from creative-commoners/pulls/2.2/remove-self
Browse files Browse the repository at this point in the history
ENH Use class name instead of self
  • Loading branch information
GuySartorelli authored Jun 17, 2024
2 parents 40aeb78 + b200f00 commit 853ce93
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/Authenticators/LDAPAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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',
Expand All @@ -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;
Expand All @@ -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'
) {
Expand Down Expand Up @@ -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(
[
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Control/LDAPDebugController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Model/LDAPGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Model/LDAPUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
12 changes: 6 additions & 6 deletions src/Services/LDAPService.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static function get_cache()
*/
public static function flush()
{
$cache = self::get_cache();
$cache = LDAPService::get_cache();
$cache->clear();
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand All @@ -310,7 +310,7 @@ public function getNestedGroups($dn, $attributes = [])
}
}

self::$_cache_nested_groups[$dn] = $results;
LDAPService::$_cache_nested_groups[$dn] = $results;
return $results;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/php/Model/LDAPFakeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 853ce93

Please sign in to comment.