diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-06-24 15:24:16 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-06-24 15:39:52 +0200 |
commit | a9cfa72d1cf5eccb352b34eb823559ac52f8e22c (patch) | |
tree | 29335b912f39ca2f780a2c904d4b0cb97c533920 /apps/federation/lib/Controller | |
parent | b282fe1e6f5587a6440d170df245ad5acb8dc976 (diff) | |
download | nextcloud-server-a9cfa72d1cf5eccb352b34eb823559ac52f8e22c.tar.gz nextcloud-server-a9cfa72d1cf5eccb352b34eb823559ac52f8e22c.zip |
Summer cleanup of the federation app
- Use IEventDispatcher instead of deprecated symfony dispatcher
- Use LoggerInterface where possible
- Use php 7.4 properties
- Add type hinting where possible
- Move federation hooks to a seperate listener
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/federation/lib/Controller')
-rw-r--r-- | apps/federation/lib/Controller/OCSAuthAPIController.php | 90 | ||||
-rw-r--r-- | apps/federation/lib/Controller/SettingsController.php | 44 |
2 files changed, 37 insertions, 97 deletions
diff --git a/apps/federation/lib/Controller/OCSAuthAPIController.php b/apps/federation/lib/Controller/OCSAuthAPIController.php index dd9b94d0027..5a976720b04 100644 --- a/apps/federation/lib/Controller/OCSAuthAPIController.php +++ b/apps/federation/lib/Controller/OCSAuthAPIController.php @@ -30,14 +30,14 @@ namespace OCA\Federation\Controller; use OCA\Federation\DbHandler; use OCA\Federation\TrustedServers; -use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCSController; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; -use OCP\ILogger; use OCP\IRequest; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; /** * Class OCSAuthAPI @@ -47,45 +47,21 @@ use OCP\Security\ISecureRandom; * @package OCA\Federation\Controller */ class OCSAuthAPIController extends OCSController { + private ISecureRandom $secureRandom; + private IJobList $jobList; + private TrustedServers $trustedServers; + private DbHandler $dbHandler; + private LoggerInterface $logger; + private ITimeFactory $timeFactory; - /** @var ISecureRandom */ - private $secureRandom; - - /** @var IJobList */ - private $jobList; - - /** @var TrustedServers */ - private $trustedServers; - - /** @var DbHandler */ - private $dbHandler; - - /** @var ILogger */ - private $logger; - - /** @var ITimeFactory */ - private $timeFactory; - - /** - * OCSAuthAPI constructor. - * - * @param string $appName - * @param IRequest $request - * @param ISecureRandom $secureRandom - * @param IJobList $jobList - * @param TrustedServers $trustedServers - * @param DbHandler $dbHandler - * @param ILogger $logger - * @param ITimeFactory $timeFactory - */ public function __construct( - $appName, + string $appName, IRequest $request, ISecureRandom $secureRandom, IJobList $jobList, TrustedServers $trustedServers, DbHandler $dbHandler, - ILogger $logger, + LoggerInterface $logger, ITimeFactory $timeFactory ) { parent::__construct($appName, $request); @@ -99,48 +75,36 @@ class OCSAuthAPIController extends OCSController { } /** + * Request received to ask remote server for a shared secret, for legacy end-points + * * @NoCSRFRequired * @PublicPage - * - * request received to ask remote server for a shared secret, for legacy end-points - * - * @param string $url - * @param string $token - * @return Http\DataResponse * @throws OCSForbiddenException */ - public function requestSharedSecretLegacy($url, $token) { + public function requestSharedSecretLegacy(string $url, string $token): DataResponse { return $this->requestSharedSecret($url, $token); } /** + * Create shared secret and return it, for legacy end-points + * * @NoCSRFRequired * @PublicPage - * - * create shared secret and return it, for legacy end-points - * - * @param string $url - * @param string $token - * @return Http\DataResponse * @throws OCSForbiddenException */ - public function getSharedSecretLegacy($url, $token) { + public function getSharedSecretLegacy(string $url, string $token): DataResponse { return $this->getSharedSecret($url, $token); } /** + * Request received to ask remote server for a shared secret + * * @NoCSRFRequired * @PublicPage - * - * request received to ask remote server for a shared secret - * - * @param string $url - * @param string $token - * @return Http\DataResponse * @throws OCSForbiddenException */ - public function requestSharedSecret($url, $token) { + public function requestSharedSecret(string $url, string $token): DataResponse { if ($this->trustedServers->isTrustedServer($url) === false) { $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); throw new OCSForbiddenException(); @@ -166,21 +130,17 @@ class OCSAuthAPIController extends OCSController { ] ); - return new Http\DataResponse(); + return new DataResponse(); } /** + * Create shared secret and return it + * * @NoCSRFRequired * @PublicPage - * - * create shared secret and return it - * - * @param string $url - * @param string $token - * @return Http\DataResponse * @throws OCSForbiddenException */ - public function getSharedSecret($url, $token) { + public function getSharedSecret(string $url, string $token): DataResponse { if ($this->trustedServers->isTrustedServer($url) === false) { $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); throw new OCSForbiddenException(); @@ -199,12 +159,12 @@ class OCSAuthAPIController extends OCSController { $this->trustedServers->addSharedSecret($url, $sharedSecret); - return new Http\DataResponse([ + return new DataResponse([ 'sharedSecret' => $sharedSecret ]); } - protected function isValidToken($url, $token) { + protected function isValidToken(string $url, string $token): bool { $storedToken = $this->dbHandler->getToken($url); return hash_equals($storedToken, $token); } diff --git a/apps/federation/lib/Controller/SettingsController.php b/apps/federation/lib/Controller/SettingsController.php index c60a7d31d7c..8abc2f8af57 100644 --- a/apps/federation/lib/Controller/SettingsController.php +++ b/apps/federation/lib/Controller/SettingsController.php @@ -31,20 +31,10 @@ use OCP\IL10N; use OCP\IRequest; class SettingsController extends Controller { + private IL10N $l; + private TrustedServers $trustedServers; - /** @var IL10N */ - private $l; - - /** @var TrustedServers */ - private $trustedServers; - - /** - * @param string $AppName - * @param IRequest $request - * @param IL10N $l10n - * @param TrustedServers $trustedServers - */ - public function __construct($AppName, + public function __construct(string $AppName, IRequest $request, IL10N $l10n, TrustedServers $trustedServers @@ -59,31 +49,25 @@ class SettingsController extends Controller { * Add server to the list of trusted Nextclouds. * * @AuthorizedAdminSetting(settings=OCA\Federation\Settings\Admin) - * @param string $url - * @return DataResponse * @throws HintException */ - public function addServer($url) { + public function addServer(string $url): DataResponse { $this->checkServer($url); $id = $this->trustedServers->addServer($url); - return new DataResponse( - [ - 'url' => $url, - 'id' => $id, - 'message' => $this->l->t('Added to the list of trusted servers') - ] - ); + return new DataResponse([ + 'url' => $url, + 'id' => $id, + 'message' => $this->l->t('Added to the list of trusted servers') + ]); } /** * Add server to the list of trusted Nextclouds. * * @AuthorizedAdminSetting(settings=OCA\Federation\Settings\Admin) - * @param int $id - * @return DataResponse */ - public function removeServer($id) { + public function removeServer(int $id): DataResponse { $this->trustedServers->removeServer($id); return new DataResponse(); } @@ -92,23 +76,19 @@ class SettingsController extends Controller { * Check if the server should be added to the list of trusted servers or not. * * @AuthorizedAdminSetting(settings=OCA\Federation\Settings\Admin) - * @param string $url - * @return bool * @throws HintException */ - protected function checkServer($url) { + protected function checkServer(string $url): void { if ($this->trustedServers->isTrustedServer($url) === true) { $message = 'Server is already in the list of trusted servers.'; $hint = $this->l->t('Server is already in the list of trusted servers.'); throw new HintException($message, $hint); } - if ($this->trustedServers->isOwnCloudServer($url) === false) { + if ($this->trustedServers->isNextcloudServer($url) === false) { $message = 'No server to federate with found'; $hint = $this->l->t('No server to federate with found'); throw new HintException($message, $hint); } - - return true; } } |