]> git.mxchange.org Git - friendica.git/commitdiff
Replace Logger with DI::logger() in Security classes
authorArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 12:47:34 +0000 (12:47 +0000)
committerArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 12:47:34 +0000 (12:47 +0000)
src/Security/BasicAuth.php
src/Security/OAuth.php
src/Security/OpenWebAuth.php

index c5da5b9f720fac6f4cde843284e98a66d0d2f6ab..a04e050c6a916c7c1f4b9ea161a54b5682cda6dd 100644 (file)
@@ -9,12 +9,10 @@ namespace Friendica\Security;
 
 use Exception;
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\User;
 use Friendica\Network\HTTPException\UnauthorizedException;
-use Friendica\Util\DateTimeFormat;
 
 /**
  * Authentication via the basic auth method
@@ -75,9 +73,9 @@ class BasicAuth
                                $source = 'Twidere';
                        }
 
-                       Logger::info('Unrecognized user-agent', ['http_user_agent' => $_SERVER['HTTP_USER_AGENT']]);
+                       DI::logger()->info('Unrecognized user-agent', ['http_user_agent' => $_SERVER['HTTP_USER_AGENT']]);
                } else {
-                       Logger::info('Empty user-agent');
+                       DI::logger()->info('Empty user-agent');
                }
 
                if (empty($source)) {
@@ -160,7 +158,7 @@ class BasicAuth
                        if (!$do_login) {
                                return 0;
                        }
-                       Logger::debug('Access denied', ['parameters' => $_SERVER]);
+                       DI::logger()->debug('Access denied', ['parameters' => $_SERVER]);
                        // Checking for commandline for the tests, we have to avoid to send a header
                        if (DI::config()->get('system', 'basicauth') && (php_sapi_name() !== 'cli')) {
                                header('WWW-Authenticate: Basic realm="Friendica"');
index d169cb7eab8964a8e6e8425c0879da61b1b3f58c..d00d27b8d3d5fee0991bd05b5e6699dec866317c 100644 (file)
@@ -7,10 +7,10 @@
 
 namespace Friendica\Security;
 
-use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\User;
 use Friendica\Module\BaseApi;
@@ -85,10 +85,10 @@ class OAuth
 
                $token = DBA::selectFirst('application-view', ['uid', 'id', 'name', 'website', 'created_at', 'read', 'write', 'follow', 'push'], $condition);
                if (!DBA::isResult($token)) {
-                       Logger::notice('Token not found', $condition);
+                       DI::logger()->notice('Token not found', $condition);
                        return [];
                }
-               Logger::debug('Token found', $token);
+               DI::logger()->debug('Token found', $token);
 
                $user = User::getById($token['uid'], ['uid', 'parent-uid', 'last-activity', 'login_date']);
                if (!empty($user)) {
@@ -125,14 +125,14 @@ class OAuth
 
                $application = DBA::selectFirst('application', [], $condition);
                if (!DBA::isResult($application)) {
-                       Logger::warning('Application not found', $condition);
+                       DI::logger()->warning('Application not found', $condition);
                        return [];
                }
 
                // The redirect_uri could contain several URI that are separated by spaces or new lines.
                $uris = explode(' ', str_replace(["\n", "\r", "\t"], ' ', $application['redirect_uri']));
                if (!in_array($redirect_uri, $uris)) {
-                       Logger::warning('Redirection uri does not match', ['redirect_uri' => $redirect_uri, 'application-redirect_uri' => $application['redirect_uri']]);
+                       DI::logger()->warning('Redirection uri does not match', ['redirect_uri' => $redirect_uri, 'application-redirect_uri' => $application['redirect_uri']]);
                        return [];
                }
 
@@ -191,7 +191,7 @@ class OAuth
 
                foreach ([BaseApi::SCOPE_READ, BaseApi::SCOPE_WRITE, BaseApi::SCOPE_FOLLOW, BaseApi::SCOPE_PUSH] as $scope) {
                        if ($fields[$scope] && !$application[$scope]) {
-                               Logger::warning('Requested token scope is not allowed for the application', ['token' => $fields, 'application' => $application]);
+                               DI::logger()->warning('Requested token scope is not allowed for the application', ['token' => $fields, 'application' => $application]);
                        }
                }
 
index 5dd3cf1a27f02f49d8b3ba7c190fe72c9d686280..8ca4baf5d1fd9c8fa1a045a09743eaa1b7fed35c 100644 (file)
@@ -9,7 +9,6 @@ namespace Friendica\Security;
 
 use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -61,31 +60,31 @@ class OpenWebAuth
                // Try to find the public contact entry of the visitor.
                $contact = Contact::getByURL($my_url, null, ['id', 'url', 'gsid']);
                if (empty($contact)) {
-                       Logger::info('No contact record found', ['url' => $my_url]);
+                       DI::logger()->info('No contact record found', ['url' => $my_url]);
                        return;
                }
 
                if (DI::userSession()->getRemoteUserId() && DI::userSession()->getRemoteUserId() == $contact['id']) {
-                       Logger::info('The visitor is already authenticated', ['url' => $my_url]);
+                       DI::logger()->info('The visitor is already authenticated', ['url' => $my_url]);
                        return;
                }
 
                $gserver = DBA::selectFirst('gserver', ['url', 'authredirect'], ['id' => $contact['gsid']]);
                if (empty($gserver) || empty($gserver['authredirect'])) {
-                       Logger::info('No server record found or magic path not defined for server', ['id' => $contact['gsid'], 'gserver' => $gserver]);
+                       DI::logger()->info('No server record found or magic path not defined for server', ['id' => $contact['gsid'], 'gserver' => $gserver]);
                        return;
                }
 
                // Avoid endless loops
                $cachekey = 'zrlInit:' . $my_url;
                if (DI::cache()->get($cachekey)) {
-                       Logger::info('URL ' . $my_url . ' already tried to authenticate.');
+                       DI::logger()->info('URL ' . $my_url . ' already tried to authenticate.');
                        return;
                } else {
                        DI::cache()->set($cachekey, true, Duration::MINUTE);
                }
 
-               Logger::info('Not authenticated. Invoking reverse magic-auth', ['url' => $my_url]);
+               DI::logger()->info('Not authenticated. Invoking reverse magic-auth', ['url' => $my_url]);
 
                // Remove the "addr" parameter from the destination. It is later added as separate parameter again.
                $addr_request = 'addr=' . urlencode($addr);
@@ -97,7 +96,7 @@ class OpenWebAuth
                if ($gserver['url'] != DI::baseUrl() && !strstr($dest, '/magic')) {
                        $magic_path = $gserver['authredirect'] . '?f=&rev=1&owa=1&dest=' . $dest . '&' . $addr_request;
 
-                       Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
+                       DI::logger()->info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
                        System::externalRedirect($magic_path);
                }
        }
@@ -149,7 +148,7 @@ class OpenWebAuth
 
                DI::sysmsg()->addInfo(DI::l10n()->t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHost(), $visitor['name']));
 
-               Logger::info('OpenWebAuth: auth success from ' . $visitor['addr']);
+               DI::logger()->info('OpenWebAuth: auth success from ' . $visitor['addr']);
        }
 
        /**
@@ -166,7 +165,7 @@ class OpenWebAuth
                // Try to find the public contact entry of the visitor.
                $cid = Contact::getIdForURL($handle);
                if (!$cid) {
-                       Logger::info('Handle not found', ['handle' => $handle]);
+                       DI::logger()->info('Handle not found', ['handle' => $handle]);
                        return [];
                }
 
@@ -186,7 +185,7 @@ class OpenWebAuth
 
                $appHelper->setContactId($visitor['id']);
 
-               Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
+               DI::logger()->info('Authenticated visitor', ['url' => $visitor['url']]);
 
                return $visitor;
        }