aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/admin_audit/lib/Actions/Security.php29
-rw-r--r--apps/admin_audit/lib/AppInfo/Application.php42
-rw-r--r--apps/admin_audit/tests/Actions/SecurityTest.php15
-rw-r--r--apps/dav/lib/HookManager.php7
-rw-r--r--apps/dav/tests/unit/DAV/HookManagerTest.php13
-rw-r--r--apps/systemtags/lib/Search/TagSearchProvider.php10
-rw-r--r--console.php2
-rw-r--r--lib/private/Accounts/Account.php10
-rw-r--r--lib/private/Accounts/AccountManager.php100
-rw-r--r--lib/private/Accounts/AccountProperty.php62
-rw-r--r--lib/private/Accounts/AccountPropertyCollection.php10
-rw-r--r--lib/private/Accounts/Hooks.php12
-rw-r--r--lib/private/Console/Application.php12
-rw-r--r--lib/private/EventDispatcher/EventDispatcher.php2
-rw-r--r--lib/private/Security/IdentityProof/Key.php16
-rw-r--r--lib/private/Security/IdentityProof/Manager.php28
-rw-r--r--lib/private/Security/IdentityProof/Signer.php31
-rw-r--r--lib/private/Security/RateLimiting/Backend/DatabaseBackend.php47
-rw-r--r--lib/private/Security/RateLimiting/Backend/IBackend.php15
-rw-r--r--lib/private/Security/RateLimiting/Backend/MemoryCacheBackend.php43
-rw-r--r--lib/private/Security/RateLimiting/Limiter.php50
-rw-r--r--lib/private/Security/VerificationToken/CleanUpJob.php17
-rw-r--r--lib/private/Security/VerificationToken/VerificationToken.php40
-rw-r--r--lib/public/Dashboard/Model/WidgetItem.php2
24 files changed, 228 insertions, 387 deletions
diff --git a/apps/admin_audit/lib/Actions/Security.php b/apps/admin_audit/lib/Actions/Security.php
index e4831ac6fc1..17cf0c3c2b9 100644
--- a/apps/admin_audit/lib/Actions/Security.php
+++ b/apps/admin_audit/lib/Actions/Security.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
*/
namespace OCA\AdminAudit\Actions;
+use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IUser;
/**
@@ -35,14 +36,14 @@ use OCP\IUser;
*/
class Security extends Action {
/**
- * Log twofactor auth enabled
- *
- * @param IUser $user
- * @param array $params
+ * Logs failed twofactor challenge
*/
- public function twofactorFailed(IUser $user, array $params): void {
- $params['uid'] = $user->getUID();
- $params['displayName'] = $user->getDisplayName();
+ public function twofactorFailed(IUser $user, IProvider $provider): void {
+ $params = [
+ 'displayName' => $user->getDisplayName(),
+ 'uid' => $user->getUID(),
+ 'provider' => $provider->getDisplayName(),
+ ];
$this->log(
'Failed two factor attempt by user %s (%s) with provider %s',
@@ -56,14 +57,14 @@ class Security extends Action {
}
/**
- * Logs unsharing of data
- *
- * @param IUser $user
- * @param array $params
+ * Logs successful twofactor challenge
*/
- public function twofactorSuccess(IUser $user, array $params): void {
- $params['uid'] = $user->getUID();
- $params['displayName'] = $user->getDisplayName();
+ public function twofactorSuccess(IUser $user, IProvider $provider): void {
+ $params = [
+ 'displayName' => $user->getDisplayName(),
+ 'uid' => $user->getUID(),
+ 'provider' => $provider->getDisplayName(),
+ ];
$this->log(
'Successful two factor attempt by user %s (%s) with provider %s',
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php
index 1160d151710..7a4d2d6e3d1 100644
--- a/apps/admin_audit/lib/AppInfo/Application.php
+++ b/apps/admin_audit/lib/AppInfo/Application.php
@@ -57,7 +57,10 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Authentication\TwoFactorAuth\IProvider;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
use OCP\Console\ConsoleEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IPreview;
@@ -65,6 +68,7 @@ use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use OCP\Log\ILogFactory;
+use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Share;
use OCP\Util;
use Psr\Container\ContainerInterface;
@@ -109,8 +113,9 @@ class Application extends App implements IBootstrap {
$this->groupHooks($logger, $serverContainer->get(IGroupManager::class));
$this->authHooks($logger);
- /** @var EventDispatcherInterface $eventDispatcher */
- $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class);
+
+ /** @var IEventDispatcher $eventDispatcher */
+ $eventDispatcher = $serverContainer->get(IEventDispatcher::class);
$this->consoleHooks($logger, $eventDispatcher);
$this->appHooks($logger, $eventDispatcher);
@@ -169,7 +174,7 @@ class Application extends App implements IBootstrap {
}
private function appHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
+ IEventDispatcher $eventDispatcher): void {
$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) {
$appActions = new AppManagement($logger);
$appActions->enableApp($event->getAppID());
@@ -185,27 +190,26 @@ class Application extends App implements IBootstrap {
}
private function consoleHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
- $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) {
+ IEventDispatcher $eventDispatcher): void {
+ $eventDispatcher->addListener(ConsoleEvent::class, function (ConsoleEvent $event) use ($logger) {
$appActions = new Console($logger);
$appActions->runCommand($event->getArguments());
});
}
private function fileHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
+ IEventDispatcher $eventDispatcher): void {
$fileActions = new Files($logger);
$eventDispatcher->addListener(
- IPreview::EVENT,
- function (GenericEvent $event) use ($fileActions) {
- /** @var File $file */
- $file = $event->getSubject();
+ BeforePreviewFetchedEvent::class,
+ function (BeforePreviewFetchedEvent $event) use ($fileActions) {
+ $file = $event->getNode();
$fileActions->preview([
'path' => mb_substr($file->getInternalPath(), 5),
- 'width' => $event->getArguments()['width'],
- 'height' => $event->getArguments()['height'],
- 'crop' => $event->getArguments()['crop'],
- 'mode' => $event->getArguments()['mode']
+ 'width' => $event->getWidth(),
+ 'height' => $event->getHeight(),
+ 'crop' => $event->isCrop(),
+ 'mode' => $event->getMode()
]);
}
);
@@ -267,14 +271,14 @@ class Application extends App implements IBootstrap {
}
private function securityHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
- $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) {
+ IEventDispatcher $eventDispatcher): void {
+ $eventDispatcher->addListener(TwoFactorProviderChallengePassed::class, function (TwoFactorProviderChallengePassed $event) use ($logger) {
$security = new Security($logger);
- $security->twofactorSuccess($event->getSubject(), $event->getArguments());
+ $security->twofactorSuccess($event->getUser(), $event->getProvider());
});
- $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) {
+ $eventDispatcher->addListener(TwoFactorProviderChallengeFailed::class, function (TwoFactorProviderChallengeFailed $event) use ($logger) {
$security = new Security($logger);
- $security->twofactorFailed($event->getSubject(), $event->getArguments());
+ $security->twofactorFailed($event->getUser(), $event->getProvider());
});
}
}
diff --git a/apps/admin_audit/tests/Actions/SecurityTest.php b/apps/admin_audit/tests/Actions/SecurityTest.php
index d45cbb75a64..bba819ad04d 100644
--- a/apps/admin_audit/tests/Actions/SecurityTest.php
+++ b/apps/admin_audit/tests/Actions/SecurityTest.php
@@ -27,8 +27,9 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Tests\Actions;
use OCA\AdminAudit\Actions\Security;
-use OCP\IUser;
use OCA\AdminAudit\AuditLogger;
+use OCP\Authentication\TwoFactorAuth\IProvider;
+use OCP\IUser;
use Test\TestCase;
class SecurityTest extends TestCase {
@@ -60,7 +61,11 @@ class SecurityTest extends TestCase {
['app' => 'admin_audit']
);
- $this->security->twofactorFailed($this->user, ['provider' => 'myprovider']);
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getDisplayName')
+ ->willReturn('myprovider');
+
+ $this->security->twofactorFailed($this->user, $provider);
}
public function testTwofactorSuccess() {
@@ -71,6 +76,10 @@ class SecurityTest extends TestCase {
['app' => 'admin_audit']
);
- $this->security->twofactorSuccess($this->user, ['provider' => 'myprovider']);
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getDisplayName')
+ ->willReturn('myprovider');
+
+ $this->security->twofactorSuccess($this->user, $provider);
}
}
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php
index b69d9b0cd79..ae92a9c9335 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -67,21 +67,16 @@ class HookManager {
/** @var Defaults */
private $themingDefaults;
- /** @var EventDispatcherInterface */
- private $eventDispatcher;
-
public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
CardDavBackend $cardDav,
- Defaults $themingDefaults,
- EventDispatcherInterface $eventDispatcher) {
+ Defaults $themingDefaults) {
$this->userManager = $userManager;
$this->syncService = $syncService;
$this->calDav = $calDav;
$this->cardDav = $cardDav;
$this->themingDefaults = $themingDefaults;
- $this->eventDispatcher = $eventDispatcher;
}
public function setup() {
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php
index eeda27d8aa3..97abe3881c0 100644
--- a/apps/dav/tests/unit/DAV/HookManagerTest.php
+++ b/apps/dav/tests/unit/DAV/HookManagerTest.php
@@ -39,19 +39,14 @@ use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class HookManagerTest extends TestCase {
/** @var IL10N */
private $l10n;
- /** @var EventDispatcherInterface | MockObject */
- private $eventDispatcher;
-
protected function setUp(): void {
parent::setUp();
- $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10n
->expects($this->any())
@@ -106,7 +101,7 @@ class HookManagerTest extends TestCase {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -145,7 +140,7 @@ class HookManagerTest extends TestCase {
$card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1);
$card->expects($this->never())->method('createAddressBook');
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -193,7 +188,7 @@ class HookManagerTest extends TestCase {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -243,7 +238,7 @@ class HookManagerTest extends TestCase {
]);
$card->expects($this->once())->method('deleteAddressBook');
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->preDeleteUser(['uid' => 'newUser']);
$hm->postDeleteUser(['uid' => 'newUser']);
}
diff --git a/apps/systemtags/lib/Search/TagSearchProvider.php b/apps/systemtags/lib/Search/TagSearchProvider.php
index 7a7cb0b061c..5c731e42cc3 100644
--- a/apps/systemtags/lib/Search/TagSearchProvider.php
+++ b/apps/systemtags/lib/Search/TagSearchProvider.php
@@ -113,6 +113,11 @@ class TagSearchProvider implements IProvider {
* @inheritDoc
*/
public function search(IUser $user, ISearchQuery $query): SearchResult {
+ $matchingTags = $this->tagManager->getAllTags(true, $query->getTerm());
+ if (count($matchingTags) === 0) {
+ return SearchResult::complete($this->l10n->t('Tags'), []);
+ }
+
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$fileQuery = new SearchQuery(
new SearchBinaryOperator(SearchBinaryOperator::OPERATOR_OR, [
@@ -133,7 +138,6 @@ class TagSearchProvider implements IProvider {
return $node->getId();
}, $searchResults);
$matchedTags = $this->objectMapper->getTagIdsForObjects($resultIds, 'files');
- $relevantTags = $this->tagManager->getTagsByIds(array_unique($this->flattenArray($matchedTags)));
// prepare direct tag results
$tagResults = array_map(function(ISystemTag $tag) {
@@ -149,9 +153,7 @@ class TagSearchProvider implements IProvider {
'icon-tag'
);
return $searchResultEntry;
- }, array_filter($relevantTags, function($tag) use ($query) {
- return $tag->isUserVisible() && strpos($tag->getName(), $query->getTerm()) !== false;
- }));
+ }, $matchingTags);
// prepare files results
return SearchResult::paginated(
diff --git a/console.php b/console.php
index f9a4689bd58..d30db9adb6e 100644
--- a/console.php
+++ b/console.php
@@ -91,7 +91,7 @@ try {
$application = new Application(
\OC::$server->getConfig(),
- \OC::$server->getEventDispatcher(),
+ \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->getRequest(),
\OC::$server->get(\Psr\Log\LoggerInterface::class),
\OC::$server->query(\OC\MemoryInfo::class)
diff --git a/lib/private/Accounts/Account.php b/lib/private/Accounts/Account.php
index d3287b219d0..22bbe3d11a0 100644
--- a/lib/private/Accounts/Account.php
+++ b/lib/private/Accounts/Account.php
@@ -39,13 +39,11 @@ class Account implements IAccount {
use TAccountsHelper;
/** @var IAccountPropertyCollection[]|IAccountProperty[] */
- private $properties = [];
+ private array $properties = [];
- /** @var IUser */
- private $user;
-
- public function __construct(IUser $user) {
- $this->user = $user;
+ public function __construct(
+ private IUser $user,
+ ) {
}
public function setProperty(string $property, string $value, string $scope, string $verified, string $verificationData = ''): IAccount {
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index e3068a7ff25..43d18a0d941 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -83,40 +83,9 @@ class AccountManager implements IAccountManager {
use TProfileHelper;
- /** @var IDBConnection database connection */
- private $connection;
-
- /** @var IConfig */
- private $config;
-
- /** @var string table name */
- private $table = 'accounts';
-
- /** @var string table name */
- private $dataTable = 'accounts_data';
-
- /** @var EventDispatcherInterface */
- private $eventDispatcher;
-
- /** @var IJobList */
- private $jobList;
-
- /** @var LoggerInterface */
- private $logger;
- /** @var IVerificationToken */
- private $verificationToken;
- /** @var IMailer */
- private $mailer;
- /** @var Defaults */
- private $defaults;
- /** @var IL10N */
- private $l10n;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var ICrypto */
- private $crypto;
- /** @var IFactory */
- private $l10nfactory;
+ private string $table = 'accounts';
+ private string $dataTable = 'accounts_data';
+ private ?IL10N $l10n = null;
private CappedMemoryCache $internalCache;
/**
@@ -138,35 +107,22 @@ class AccountManager implements IAccountManager {
];
public function __construct(
- IDBConnection $connection,
- IConfig $config,
- EventDispatcherInterface $eventDispatcher,
- IJobList $jobList,
- LoggerInterface $logger,
- IVerificationToken $verificationToken,
- IMailer $mailer,
- Defaults $defaults,
- IFactory $factory,
- IURLGenerator $urlGenerator,
- ICrypto $crypto
+ private IDBConnection $connection,
+ private IConfig $config,
+ private EventDispatcherInterface $eventDispatcher,
+ private IJobList $jobList,
+ private LoggerInterface $logger,
+ private IVerificationToken $verificationToken,
+ private IMailer $mailer,
+ private Defaults $defaults,
+ private IFactory $l10nFactory,
+ private IURLGenerator $urlGenerator,
+ private ICrypto $crypto,
) {
- $this->connection = $connection;
- $this->config = $config;
- $this->eventDispatcher = $eventDispatcher;
- $this->jobList = $jobList;
- $this->logger = $logger;
- $this->verificationToken = $verificationToken;
- $this->mailer = $mailer;
- $this->defaults = $defaults;
- $this->urlGenerator = $urlGenerator;
- $this->crypto = $crypto;
- // DIing IL10N results in a dependency loop
- $this->l10nfactory = $factory;
$this->internalCache = new CappedMemoryCache();
}
/**
- * @param string $input
* @return string Provided phone number in E.164 format when it was a valid number
* @throws InvalidArgumentException When the phone number was invalid or no default region is set and the number doesn't start with a country code
*/
@@ -195,9 +151,6 @@ class AccountManager implements IAccountManager {
}
/**
- *
- * @param string $input
- * @return string
* @throws InvalidArgumentException When the website did not have http(s) as protocol or the host name was empty
*/
protected function parseWebsite(string $input): string {
@@ -251,7 +204,7 @@ class AccountManager implements IAccountManager {
}
}
- protected function sanitizePhoneNumberValue(IAccountProperty $property, bool $throwOnData = false) {
+ protected function sanitizePhoneNumberValue(IAccountProperty $property, bool $throwOnData = false): void {
if ($property->getName() !== self::PROPERTY_PHONE) {
if ($throwOnData) {
throw new InvalidArgumentException(sprintf('sanitizePhoneNumberValue can only sanitize phone numbers, %s given', $property->getName()));
@@ -271,7 +224,7 @@ class AccountManager implements IAccountManager {
}
}
- protected function sanitizeWebsite(IAccountProperty $property, bool $throwOnData = false) {
+ protected function sanitizeWebsite(IAccountProperty $property, bool $throwOnData = false): void {
if ($property->getName() !== self::PROPERTY_WEBSITE) {
if ($throwOnData) {
throw new InvalidArgumentException(sprintf('sanitizeWebsite can only sanitize web domains, %s given', $property->getName()));
@@ -313,10 +266,8 @@ class AccountManager implements IAccountManager {
/**
* delete user from accounts table
- *
- * @param IUser $user
*/
- public function deleteUser(IUser $user) {
+ public function deleteUser(IUser $user): void {
$uid = $user->getUID();
$query = $this->connection->getQueryBuilder();
$query->delete($this->table)
@@ -328,8 +279,6 @@ class AccountManager implements IAccountManager {
/**
* delete user from accounts table
- *
- * @param IUser $user
*/
public function deleteUserData(IUser $user): void {
$uid = $user->getUID();
@@ -398,12 +347,10 @@ class AccountManager implements IAccountManager {
}
protected function searchUsersForRelatedCollection(string $property, array $values): array {
- switch ($property) {
- case IAccountManager::PROPERTY_EMAIL:
- return array_flip($this->searchUsers(IAccountManager::COLLECTION_EMAIL, $values));
- default:
- return [];
- }
+ return match ($property) {
+ IAccountManager::PROPERTY_EMAIL => array_flip($this->searchUsers(IAccountManager::COLLECTION_EMAIL, $values)),
+ default => [],
+ };
}
/**
@@ -467,7 +414,7 @@ class AccountManager implements IAccountManager {
]);
if (!$this->l10n) {
- $this->l10n = $this->l10nfactory->get('core');
+ $this->l10n = $this->l10nFactory->get('core');
}
$emailTemplate->setSubject($this->l10n->t('%s email verification', [$this->defaults->getName()]));
@@ -552,9 +499,6 @@ class AccountManager implements IAccountManager {
/**
* add new user to accounts table
- *
- * @param IUser $user
- * @param array $data
*/
protected function insertNewUser(IUser $user, array $data): void {
$uid = $user->getUID();
diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php
index 2023d185a4b..207dc1d139d 100644
--- a/lib/private/Accounts/AccountProperty.php
+++ b/lib/private/Accounts/AccountProperty.php
@@ -32,25 +32,17 @@ use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
class AccountProperty implements IAccountProperty {
- /** @var string */
- private $name;
- /** @var string */
- private $value;
- /** @var string */
- private $scope;
- /** @var string */
- private $verified;
- /** @var string */
- private $verificationData;
- /** @var string */
- private $locallyVerified = IAccountManager::NOT_VERIFIED;
-
- public function __construct(string $name, string $value, string $scope, string $verified, string $verificationData) {
- $this->name = $name;
- $this->value = $value;
+ private string $scope;
+ private string $locallyVerified = IAccountManager::NOT_VERIFIED;
+
+ public function __construct(
+ private string $name,
+ private string $value,
+ string $scope,
+ private string $verified,
+ private string $verificationData,
+ ) {
$this->setScope($scope);
- $this->verified = $verified;
- $this->verificationData = $verificationData;
}
public function jsonSerialize(): array {
@@ -67,9 +59,6 @@ class AccountProperty implements IAccountProperty {
* Set the value of a property
*
* @since 15.0.0
- *
- * @param string $value
- * @return IAccountProperty
*/
public function setValue(string $value): IAccountProperty {
$this->value = $value;
@@ -80,9 +69,6 @@ class AccountProperty implements IAccountProperty {
* Set the scope of a property
*
* @since 15.0.0
- *
- * @param string $scope
- * @return IAccountProperty
*/
public function setScope(string $scope): IAccountProperty {
$newScope = $this->mapScopeToV2($scope);
@@ -102,9 +88,6 @@ class AccountProperty implements IAccountProperty {
* Set the verification status of a property
*
* @since 15.0.0
- *
- * @param string $verified
- * @return IAccountProperty
*/
public function setVerified(string $verified): IAccountProperty {
$this->verified = $verified;
@@ -115,8 +98,6 @@ class AccountProperty implements IAccountProperty {
* Get the name of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getName(): string {
return $this->name;
@@ -126,8 +107,6 @@ class AccountProperty implements IAccountProperty {
* Get the value of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getValue(): string {
return $this->value;
@@ -137,8 +116,6 @@ class AccountProperty implements IAccountProperty {
* Get the scope of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getScope(): string {
return $this->scope;
@@ -149,25 +126,18 @@ class AccountProperty implements IAccountProperty {
return $scope;
}
- switch ($scope) {
- case IAccountManager::VISIBILITY_PRIVATE:
- case '':
- return IAccountManager::SCOPE_LOCAL;
- case IAccountManager::VISIBILITY_CONTACTS_ONLY:
- return IAccountManager::SCOPE_FEDERATED;
- case IAccountManager::VISIBILITY_PUBLIC:
- return IAccountManager::SCOPE_PUBLISHED;
- default:
- return $scope;
- }
+ return match ($scope) {
+ IAccountManager::VISIBILITY_PRIVATE, '' => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::VISIBILITY_CONTACTS_ONLY => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::VISIBILITY_PUBLIC => IAccountManager::SCOPE_PUBLISHED,
+ default => $scope,
+ };
}
/**
* Get the verification status of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getVerified(): string {
return $this->verified;
diff --git a/lib/private/Accounts/AccountPropertyCollection.php b/lib/private/Accounts/AccountPropertyCollection.php
index 1e5d8a5112a..660a245714d 100644
--- a/lib/private/Accounts/AccountPropertyCollection.php
+++ b/lib/private/Accounts/AccountPropertyCollection.php
@@ -32,14 +32,12 @@ use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;
class AccountPropertyCollection implements IAccountPropertyCollection {
- /** @var string */
- protected $collectionName = '';
-
/** @var IAccountProperty[] */
- protected $properties = [];
+ protected array $properties = [];
- public function __construct(string $collectionName) {
- $this->collectionName = $collectionName;
+ public function __construct(
+ protected string $collectionName,
+ ) {
}
public function setProperties(array $properties): IAccountPropertyCollection {
diff --git a/lib/private/Accounts/Hooks.php b/lib/private/Accounts/Hooks.php
index a6c52275d2d..b449c41c1da 100644
--- a/lib/private/Accounts/Hooks.php
+++ b/lib/private/Accounts/Hooks.php
@@ -36,14 +36,10 @@ use Psr\Log\LoggerInterface;
* @template-implements IEventListener<UserChangedEvent>
*/
class Hooks implements IEventListener {
- /** @var IAccountManager */
- private $accountManager;
- /** @var LoggerInterface */
- private $logger;
-
- public function __construct(LoggerInterface $logger, IAccountManager $accountManager) {
- $this->logger = $logger;
- $this->accountManager = $accountManager;
+ public function __construct(
+ private LoggerInterface $logger,
+ private IAccountManager $accountManager,
+ ) {
}
/**
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php
index 94956364390..11515f26866 100644
--- a/lib/private/Console/Application.php
+++ b/lib/private/Console/Application.php
@@ -36,6 +36,7 @@ use OC_App;
use OCP\AppFramework\QueryException;
use OCP\App\IAppManager;
use OCP\Console\ConsoleEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IRequest;
use Psr\Log\LoggerInterface;
@@ -44,13 +45,12 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application {
/** @var IConfig */
private $config;
private SymfonyApplication $application;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var IRequest */
private $request;
@@ -60,7 +60,7 @@ class Application {
private $memoryInfo;
public function __construct(IConfig $config,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
IRequest $request,
LoggerInterface $logger,
MemoryInfo $memoryInfo) {
@@ -204,10 +204,12 @@ class Application {
* @throws \Exception
*/
public function run(InputInterface $input = null, OutputInterface $output = null) {
- $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
+ $event = new ConsoleEvent(
ConsoleEvent::EVENT_RUN,
$this->request->server['argv']
- ));
+ );
+ $this->dispatcher->dispatchTyped($event);
+ $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, $event);
return $this->application->run($input, $output);
}
diff --git a/lib/private/EventDispatcher/EventDispatcher.php b/lib/private/EventDispatcher/EventDispatcher.php
index d64ad88be7e..88c6b2cf32c 100644
--- a/lib/private/EventDispatcher/EventDispatcher.php
+++ b/lib/private/EventDispatcher/EventDispatcher.php
@@ -58,7 +58,7 @@ class EventDispatcher implements IEventDispatcher {
// inject the event dispatcher into the logger
// this is done here because there is a cyclic dependency between the event dispatcher and logger
- if ($this->logger instanceof Log or $this->logger instanceof Log\PsrLoggerAdapter) {
+ if ($this->logger instanceof Log || $this->logger instanceof Log\PsrLoggerAdapter) {
$this->logger->setEventDispatcher($this);
}
}
diff --git a/lib/private/Security/IdentityProof/Key.php b/lib/private/Security/IdentityProof/Key.php
index 349ffd3c15a..bde828a3859 100644
--- a/lib/private/Security/IdentityProof/Key.php
+++ b/lib/private/Security/IdentityProof/Key.php
@@ -27,18 +27,10 @@ declare(strict_types=1);
namespace OC\Security\IdentityProof;
class Key {
- /** @var string */
- private $publicKey;
- /** @var string */
- private $privateKey;
-
- /**
- * @param string $publicKey
- * @param string $privateKey
- */
- public function __construct(string $publicKey, string $privateKey) {
- $this->publicKey = $publicKey;
- $this->privateKey = $privateKey;
+ public function __construct(
+ private string $publicKey,
+ private string $privateKey,
+ ) {
}
public function getPrivate(): string {
diff --git a/lib/private/Security/IdentityProof/Manager.php b/lib/private/Security/IdentityProof/Manager.php
index c92d7390969..49b9bb10c3e 100644
--- a/lib/private/Security/IdentityProof/Manager.php
+++ b/lib/private/Security/IdentityProof/Manager.php
@@ -37,23 +37,15 @@ use OCP\Security\ICrypto;
use Psr\Log\LoggerInterface;
class Manager {
- /** @var IAppData */
- private $appData;
- /** @var ICrypto */
- private $crypto;
- /** @var IConfig */
- private $config;
- private LoggerInterface $logger;
-
- public function __construct(Factory $appDataFactory,
- ICrypto $crypto,
- IConfig $config,
- LoggerInterface $logger
+ private IAppData $appData;
+
+ public function __construct(
+ Factory $appDataFactory,
+ private ICrypto $crypto,
+ private IConfig $config,
+ private LoggerInterface $logger,
) {
$this->appData = $appDataFactory->get('identityproof');
- $this->crypto = $crypto;
- $this->config = $config;
- $this->logger = $logger;
}
/**
@@ -94,7 +86,6 @@ class Manager {
* Note: If a key already exists it will be overwritten
*
* @param string $id key id
- * @return Key
* @throws \RuntimeException
*/
protected function generateKey(string $id): Key {
@@ -117,8 +108,6 @@ class Manager {
/**
* Get key for a specific id
*
- * @param string $id
- * @return Key
* @throws \RuntimeException
*/
protected function retrieveKey(string $id): Key {
@@ -137,8 +126,6 @@ class Manager {
/**
* Get public and private key for $user
*
- * @param IUser $user
- * @return Key
* @throws \RuntimeException
*/
public function getKey(IUser $user): Key {
@@ -149,7 +136,6 @@ class Manager {
/**
* Get instance wide public and private key
*
- * @return Key
* @throws \RuntimeException
*/
public function getSystemKey(): Key {
diff --git a/lib/private/Security/IdentityProof/Signer.php b/lib/private/Security/IdentityProof/Signer.php
index 7431bfe815f..1458390c327 100644
--- a/lib/private/Security/IdentityProof/Signer.php
+++ b/lib/private/Security/IdentityProof/Signer.php
@@ -32,32 +32,16 @@ use OCP\IUser;
use OCP\IUserManager;
class Signer {
- /** @var Manager */
- private $keyManager;
- /** @var ITimeFactory */
- private $timeFactory;
- /** @var IUserManager */
- private $userManager;
-
- /**
- * @param Manager $keyManager
- * @param ITimeFactory $timeFactory
- * @param IUserManager $userManager
- */
- public function __construct(Manager $keyManager,
- ITimeFactory $timeFactory,
- IUserManager $userManager) {
- $this->keyManager = $keyManager;
- $this->timeFactory = $timeFactory;
- $this->userManager = $userManager;
+ public function __construct(
+ private Manager $keyManager,
+ private ITimeFactory $timeFactory,
+ private IUserManager $userManager,
+ ) {
}
/**
* Returns a signed blob for $data
*
- * @param string $type
- * @param array $data
- * @param IUser $user
* @return array ['message', 'signature']
*/
public function sign(string $type, array $data, IUser $user): array {
@@ -79,13 +63,10 @@ class Signer {
/**
* Whether the data is signed properly
*
- * @param array $data
- * @return bool
*/
public function verify(array $data): bool {
- if (isset($data['message'])
+ if (isset($data['message']['signer'])
&& isset($data['signature'])
- && isset($data['message']['signer'])
) {
$location = strrpos($data['message']['signer'], '@');
$userId = substr($data['message']['signer'], 0, $location);
diff --git a/lib/private/Security/RateLimiting/Backend/DatabaseBackend.php b/lib/private/Security/RateLimiting/Backend/DatabaseBackend.php
index d1631a8d0ae..41f50a90b5c 100644
--- a/lib/private/Security/RateLimiting/Backend/DatabaseBackend.php
+++ b/lib/private/Security/RateLimiting/Backend/DatabaseBackend.php
@@ -28,6 +28,7 @@ declare(strict_types=1);
namespace OC\Security\RateLimiting\Backend;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -35,38 +36,22 @@ use OCP\IDBConnection;
class DatabaseBackend implements IBackend {
private const TABLE_NAME = 'ratelimit_entries';
- /** @var IConfig */
- private $config;
- /** @var IDBConnection */
- private $dbConnection;
- /** @var ITimeFactory */
- private $timeFactory;
-
public function __construct(
- IConfig $config,
- IDBConnection $dbConnection,
- ITimeFactory $timeFactory
+ private IConfig $config,
+ private IDBConnection $dbConnection,
+ private ITimeFactory $timeFactory
) {
- $this->config = $config;
- $this->dbConnection = $dbConnection;
- $this->timeFactory = $timeFactory;
}
- /**
- * @param string $methodIdentifier
- * @param string $userIdentifier
- * @return string
- */
- private function hash(string $methodIdentifier,
- string $userIdentifier): string {
+ private function hash(
+ string $methodIdentifier,
+ string $userIdentifier,
+ ): string {
return hash('sha512', $methodIdentifier . $userIdentifier);
}
/**
- * @param string $identifier
- * @param int $seconds
- * @return int
- * @throws \OCP\DB\Exception
+ * @throws Exception
*/
private function getExistingAttemptCount(
string $identifier
@@ -97,8 +82,10 @@ class DatabaseBackend implements IBackend {
/**
* {@inheritDoc}
*/
- public function getAttempts(string $methodIdentifier,
- string $userIdentifier): int {
+ public function getAttempts(
+ string $methodIdentifier,
+ string $userIdentifier,
+ ): int {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
return $this->getExistingAttemptCount($identifier);
}
@@ -106,9 +93,11 @@ class DatabaseBackend implements IBackend {
/**
* {@inheritDoc}
*/
- public function registerAttempt(string $methodIdentifier,
- string $userIdentifier,
- int $period) {
+ public function registerAttempt(
+ string $methodIdentifier,
+ string $userIdentifier,
+ int $period,
+ ): void {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
$deleteAfter = $this->timeFactory->getDateTime()->add(new \DateInterval("PT{$period}S"));
diff --git a/lib/private/Security/RateLimiting/Backend/IBackend.php b/lib/private/Security/RateLimiting/Backend/IBackend.php
index 960bfd2d159..24715391a96 100644
--- a/lib/private/Security/RateLimiting/Backend/IBackend.php
+++ b/lib/private/Security/RateLimiting/Backend/IBackend.php
@@ -39,10 +39,11 @@ interface IBackend {
*
* @param string $methodIdentifier Identifier for the method
* @param string $userIdentifier Identifier for the user
- * @return int
*/
- public function getAttempts(string $methodIdentifier,
- string $userIdentifier): int;
+ public function getAttempts(
+ string $methodIdentifier,
+ string $userIdentifier,
+ ): int;
/**
* Registers an attempt
@@ -51,7 +52,9 @@ interface IBackend {
* @param string $userIdentifier Identifier for the user
* @param int $period Period in seconds how long this attempt should be stored
*/
- public function registerAttempt(string $methodIdentifier,
- string $userIdentifier,
- int $period);
+ public function registerAttempt(
+ string $methodIdentifier,
+ string $userIdentifier,
+ int $period,
+ );
}
diff --git a/lib/private/Security/RateLimiting/Backend/MemoryCacheBackend.php b/lib/private/Security/RateLimiting/Backend/MemoryCacheBackend.php
index 4bcb459c64e..b59178c7d7b 100644
--- a/lib/private/Security/RateLimiting/Backend/MemoryCacheBackend.php
+++ b/lib/private/Security/RateLimiting/Backend/MemoryCacheBackend.php
@@ -42,36 +42,23 @@ use OCP\IConfig;
* @package OC\Security\RateLimiting\Backend
*/
class MemoryCacheBackend implements IBackend {
- /** @var IConfig */
- private $config;
- /** @var ICache */
- private $cache;
- /** @var ITimeFactory */
- private $timeFactory;
+ private ICache $cache;
public function __construct(
- IConfig $config,
+ private IConfig $config,
ICacheFactory $cacheFactory,
- ITimeFactory $timeFactory) {
- $this->config = $config;
+ private ITimeFactory $timeFactory,
+ ) {
$this->cache = $cacheFactory->createDistributed(__CLASS__);
- $this->timeFactory = $timeFactory;
}
- /**
- * @param string $methodIdentifier
- * @param string $userIdentifier
- * @return string
- */
- private function hash(string $methodIdentifier,
- string $userIdentifier): string {
+ private function hash(
+ string $methodIdentifier,
+ string $userIdentifier,
+ ): string {
return hash('sha512', $methodIdentifier . $userIdentifier);
}
- /**
- * @param string $identifier
- * @return array
- */
private function getExistingAttempts(string $identifier): array {
$cachedAttempts = $this->cache->get($identifier);
if ($cachedAttempts === null) {
@@ -89,8 +76,10 @@ class MemoryCacheBackend implements IBackend {
/**
* {@inheritDoc}
*/
- public function getAttempts(string $methodIdentifier,
- string $userIdentifier): int {
+ public function getAttempts(
+ string $methodIdentifier,
+ string $userIdentifier,
+ ): int {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
$existingAttempts = $this->getExistingAttempts($identifier);
@@ -108,9 +97,11 @@ class MemoryCacheBackend implements IBackend {
/**
* {@inheritDoc}
*/
- public function registerAttempt(string $methodIdentifier,
- string $userIdentifier,
- int $period) {
+ public function registerAttempt(
+ string $methodIdentifier,
+ string $userIdentifier,
+ int $period,
+ ): void {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
$existingAttempts = $this->getExistingAttempts($identifier);
$currentTime = $this->timeFactory->getTime();
diff --git a/lib/private/Security/RateLimiting/Limiter.php b/lib/private/Security/RateLimiting/Limiter.php
index 7848a5b75a7..c8c0e2ce101 100644
--- a/lib/private/Security/RateLimiting/Limiter.php
+++ b/lib/private/Security/RateLimiting/Limiter.php
@@ -32,27 +32,21 @@ use OC\Security\RateLimiting\Exception\RateLimitExceededException;
use OCP\IUser;
class Limiter {
- /** @var IBackend */
- private $backend;
-
- /**
- * @param IBackend $backend
- */
- public function __construct(IBackend $backend) {
- $this->backend = $backend;
+ public function __construct(
+ private IBackend $backend,
+ ) {
}
/**
- * @param string $methodIdentifier
- * @param string $userIdentifier
* @param int $period in seconds
- * @param int $limit
* @throws RateLimitExceededException
*/
- private function register(string $methodIdentifier,
- string $userIdentifier,
- int $period,
- int $limit): void {
+ private function register(
+ string $methodIdentifier,
+ string $userIdentifier,
+ int $period,
+ int $limit,
+ ): void {
$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier);
if ($existingAttempts >= $limit) {
throw new RateLimitExceededException();
@@ -64,16 +58,15 @@ class Limiter {
/**
* Registers attempt for an anonymous request
*
- * @param string $identifier
- * @param int $anonLimit
* @param int $anonPeriod in seconds
- * @param string $ip
* @throws RateLimitExceededException
*/
- public function registerAnonRequest(string $identifier,
- int $anonLimit,
- int $anonPeriod,
- string $ip): void {
+ public function registerAnonRequest(
+ string $identifier,
+ int $anonLimit,
+ int $anonPeriod,
+ string $ip,
+ ): void {
$ipSubnet = (new IpAddress($ip))->getSubnet();
$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
@@ -83,16 +76,15 @@ class Limiter {
/**
* Registers attempt for an authenticated request
*
- * @param string $identifier
- * @param int $userLimit
* @param int $userPeriod in seconds
- * @param IUser $user
* @throws RateLimitExceededException
*/
- public function registerUserRequest(string $identifier,
- int $userLimit,
- int $userPeriod,
- IUser $user): void {
+ public function registerUserRequest(
+ string $identifier,
+ int $userLimit,
+ int $userPeriod,
+ IUser $user,
+ ): void {
$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
}
diff --git a/lib/private/Security/VerificationToken/CleanUpJob.php b/lib/private/Security/VerificationToken/CleanUpJob.php
index 4510dcffe0a..1f4af046451 100644
--- a/lib/private/Security/VerificationToken/CleanUpJob.php
+++ b/lib/private/Security/VerificationToken/CleanUpJob.php
@@ -39,18 +39,17 @@ class CleanUpJob extends Job {
protected ?string $userId = null;
protected ?string $subject = null;
protected ?string $pwdPrefix = null;
- private IConfig $config;
- private IVerificationToken $verificationToken;
- private IUserManager $userManager;
- public function __construct(ITimeFactory $time, IConfig $config, IVerificationToken $verificationToken, IUserManager $userManager) {
+ public function __construct(
+ ITimeFactory $time,
+ private IConfig $config,
+ private IVerificationToken $verificationToken,
+ private IUserManager $userManager,
+ ) {
parent::__construct($time);
- $this->config = $config;
- $this->verificationToken = $verificationToken;
- $this->userManager = $userManager;
}
- public function setArgument($argument) {
+ public function setArgument($argument): void {
parent::setArgument($argument);
$args = \json_decode($argument, true);
$this->userId = (string)$args['userId'];
@@ -59,7 +58,7 @@ class CleanUpJob extends Job {
$this->runNotBefore = (int)$args['notBefore'];
}
- protected function run($argument) {
+ protected function run($argument): void {
try {
$user = $this->userManager->get($this->userId);
if ($user === null) {
diff --git a/lib/private/Security/VerificationToken/VerificationToken.php b/lib/private/Security/VerificationToken/VerificationToken.php
index 52c3f62b813..5f606d0e049 100644
--- a/lib/private/Security/VerificationToken/VerificationToken.php
+++ b/lib/private/Security/VerificationToken/VerificationToken.php
@@ -39,29 +39,13 @@ use function json_encode;
class VerificationToken implements IVerificationToken {
protected const TOKEN_LIFETIME = 60 * 60 * 24 * 7;
- /** @var IConfig */
- private $config;
- /** @var ICrypto */
- private $crypto;
- /** @var ITimeFactory */
- private $timeFactory;
- /** @var ISecureRandom */
- private $secureRandom;
- /** @var IJobList */
- private $jobList;
-
public function __construct(
- IConfig $config,
- ICrypto $crypto,
- ITimeFactory $timeFactory,
- ISecureRandom $secureRandom,
- IJobList $jobList
+ private IConfig $config,
+ private ICrypto $crypto,
+ private ITimeFactory $timeFactory,
+ private ISecureRandom $secureRandom,
+ private IJobList $jobList
) {
- $this->config = $config;
- $this->crypto = $crypto;
- $this->timeFactory = $timeFactory;
- $this->secureRandom = $secureRandom;
- $this->jobList = $jobList;
}
/**
@@ -71,7 +55,13 @@ class VerificationToken implements IVerificationToken {
throw new InvalidTokenException($code);
}
- public function check(string $token, ?IUser $user, string $subject, string $passwordPrefix = '', bool $expiresWithLogin = false): void {
+ public function check(
+ string $token,
+ ?IUser $user,
+ string $subject,
+ string $passwordPrefix = '',
+ bool $expiresWithLogin = false,
+ ): void {
if ($user === null || !$user->isEnabled()) {
$this->throwInvalidTokenException(InvalidTokenException::USER_UNKNOWN);
}
@@ -107,7 +97,11 @@ class VerificationToken implements IVerificationToken {
}
}
- public function create(IUser $user, string $subject, string $passwordPrefix = ''): string {
+ public function create(
+ IUser $user,
+ string $subject,
+ string $passwordPrefix = '',
+ ): string {
$token = $this->secureRandom->generate(
21,
ISecureRandom::CHAR_DIGITS.
diff --git a/lib/public/Dashboard/Model/WidgetItem.php b/lib/public/Dashboard/Model/WidgetItem.php
index 2bea9b93226..859a5652351 100644
--- a/lib/public/Dashboard/Model/WidgetItem.php
+++ b/lib/public/Dashboard/Model/WidgetItem.php
@@ -33,7 +33,7 @@ use JsonSerializable;
*
* This class is used by IAPIWidget interface.
* It represents an widget item data that can be provided to clients via the Dashboard API
- * @see IAPIWidget::getWidgetItems
+ * @see IAPIWidget::getItems
*
* @since 22.0.0
*