Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(authentication): Use constructor property promotion #50303

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1504,24 +1504,6 @@
<code><![CDATA[setType]]></code>
</UndefinedMagicMethod>
</file>
<file src="lib/private/Authentication/TwoFactorAuth/ProviderSet.php">
<InvalidArgument>
<code><![CDATA[$this->providers]]></code>
</InvalidArgument>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->providers]]></code>
<code><![CDATA[[]]]></code>
</InvalidPropertyAssignmentValue>
<InvalidReturnStatement>
<code><![CDATA[$this->providers]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[IProvider[]]]></code>
</InvalidReturnType>
<UndefinedInterfaceMethod>
<code><![CDATA[$this->providers]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/Cache/CappedMemoryCache.php">
<MissingTemplateParam>
<code><![CDATA[\ArrayAccess]]></code>
Expand Down
7 changes: 3 additions & 4 deletions lib/private/Authentication/Events/ARemoteWipeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
use OCP\EventDispatcher\Event;

abstract class ARemoteWipeEvent extends Event {
/** @var IToken */
private $token;

public function __construct(IToken $token) {
public function __construct(
private IToken $token,
) {
parent::__construct();
$this->token = $token;
}

public function getToken(): IToken {
Expand Down
10 changes: 4 additions & 6 deletions lib/private/Authentication/Events/LoginFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
use OCP\EventDispatcher\Event;

class LoginFailed extends Event {
private string $loginName;
private ?string $password;

public function __construct(string $loginName, ?string $password) {
public function __construct(
private string $loginName,
private ?string $password,
) {
parent::__construct();

$this->loginName = $loginName;
$this->password = $password;
}

public function getLoginName(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use Throwable;

class InvalidProviderException extends Exception {
public function __construct(string $providerId, ?Throwable $previous = null) {
public function __construct(
string $providerId,
?Throwable $previous = null,
) {
parent::__construct("The provider '$providerId' does not exist'", 0, $previous);
}
}
14 changes: 5 additions & 9 deletions lib/private/Authentication/Listeners/LoginFailedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@
* @template-implements IEventListener<\OC\Authentication\Events\LoginFailed>
*/
class LoginFailedListener implements IEventListener {
/** @var IEventDispatcher */
private $dispatcher;

/** @var IUserManager */
private $userManager;

public function __construct(IEventDispatcher $dispatcher, IUserManager $userManager) {
$this->dispatcher = $dispatcher;
$this->userManager = $userManager;
public function __construct(
private IEventDispatcher $dispatcher,
private IUserManager $userManager,
) {
}

public function handle(Event $event): void {
if (!($event instanceof LoginFailed)) {
if (!$event instanceof LoginFailed) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeActivityListener implements IEventListener {
/** @var IActvityManager */
private $activityManager;

/** @var LoggerInterface */
private $logger;

public function __construct(IActvityManager $activityManager,
LoggerInterface $logger) {
$this->activityManager = $activityManager;
$this->logger = $logger;
public function __construct(
private IActvityManager $activityManager,
private LoggerInterface $logger,
) {
}

public function handle(Event $event): void {
Expand All @@ -42,11 +37,12 @@ public function handle(Event $event): void {
}

private function publishActivity(string $event, IToken $token): void {
$tokenId = $token->getUID();
$activity = $this->activityManager->generateEvent();
$activity->setApp('core')
->setType('security')
->setAuthor($token->getUID())
->setAffectedUser($token->getUID())
->setAuthor($tokenId)
->setAffectedUser($tokenId)
->setSubject($event, [
'name' => $token->getName(),
]);
Expand Down
19 changes: 5 additions & 14 deletions lib/private/Authentication/Listeners/RemoteWipeEmailListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,17 @@
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeEmailListener implements IEventListener {
/** @var IMailer */
private $mailer;

/** @var IUserManager */
private $userManager;

/** @var IL10N */
private $l10n;

/** @var LoggerInterface */
private $logger;

public function __construct(IMailer $mailer,
IUserManager $userManager,
public function __construct(
private IMailer $mailer,
private IUserManager $userManager,
IL10nFactory $l10nFactory,
LoggerInterface $logger) {
$this->mailer = $mailer;
$this->userManager = $userManager;
private LoggerInterface $logger,
) {
$this->l10n = $l10nFactory->get('core');
$this->logger = $logger;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeNotificationsListener implements IEventListener {
/** @var INotificationManager */
private $notificationManager;

/** @var ITimeFactory */
private $timeFactory;

public function __construct(INotificationManager $notificationManager,
ITimeFactory $timeFactory) {
$this->notificationManager = $notificationManager;
$this->timeFactory = $timeFactory;
public function __construct(
private INotificationManager $notificationManager,
private ITimeFactory $timeFactory,
) {
}

public function handle(Event $event): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
* @template-implements IEventListener<\OCP\User\Events\UserDeletedEvent>
*/
class UserDeletedStoreCleanupListener implements IEventListener {
/** @var Registry */
private $registry;

public function __construct(Registry $registry) {
$this->registry = $registry;
public function __construct(
private Registry $registry,
) {
}

public function handle(Event $event): void {
if (!($event instanceof UserDeletedEvent)) {
if (!$event instanceof UserDeletedEvent) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@
* @template-implements IEventListener<\OCP\User\Events\UserDeletedEvent>
*/
class UserDeletedTokenCleanupListener implements IEventListener {
/** @var Manager */
private $manager;

/** @var LoggerInterface */
private $logger;

public function __construct(Manager $manager,
LoggerInterface $logger) {
$this->manager = $manager;
$this->logger = $logger;
public function __construct(
private Manager $manager,
private LoggerInterface $logger,
) {
}

public function handle(Event $event): void {
if (!($event instanceof UserDeletedEvent)) {
if (!$event instanceof UserDeletedEvent) {
// Unrelated
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

/** @template-implements IEventListener<UserDeletedEvent> */
class UserDeletedWebAuthnCleanupListener implements IEventListener {
/** @var PublicKeyCredentialMapper */
private $credentialMapper;

public function __construct(PublicKeyCredentialMapper $credentialMapper) {
$this->credentialMapper = $credentialMapper;
public function __construct(
private PublicKeyCredentialMapper $credentialMapper,
) {
}

public function handle(Event $event): void {
if (!($event instanceof UserDeletedEvent)) {
if (!$event instanceof UserDeletedEvent) {
return;
}

$this->credentialMapper->deleteByUid($event->getUser()->getUID());
$uid = $event->getUser()->getUID();
$this->credentialMapper->deleteByUid($uid);
}
}
12 changes: 6 additions & 6 deletions lib/private/Authentication/Listeners/UserLoggedInListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
* @template-implements IEventListener<\OCP\User\Events\PostLoginEvent>
*/
class UserLoggedInListener implements IEventListener {
/** @var Manager */
private $manager;

public function __construct(Manager $manager) {
$this->manager = $manager;
public function __construct(
private Manager $manager,
) {
}

public function handle(Event $event): void {
if (!($event instanceof PostLoginEvent)) {
if (!$event instanceof PostLoginEvent) {
return;
}

Expand All @@ -39,6 +38,7 @@ public function handle(Event $event): void {
return;
}

$this->manager->updatePasswords($event->getUser()->getUID(), $event->getPassword());
$uid = $event->getUser()->getUID();
$this->manager->updatePasswords($uid, $event->getPassword());
}
}
3 changes: 1 addition & 2 deletions lib/private/Authentication/Login/ALoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public function setNext(ALoginCommand $next): ALoginCommand {
protected function processNextOrFinishSuccessfully(LoginData $loginData): LoginResult {
if ($this->next !== null) {
return $this->next->process($loginData);
} else {
return LoginResult::success($loginData);
}
return LoginResult::success($loginData);
}

abstract public function process(LoginData $loginData): LoginResult;
Expand Down
72 changes: 13 additions & 59 deletions lib/private/Authentication/Login/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,21 @@
namespace OC\Authentication\Login;

class Chain {
/** @var PreLoginHookCommand */
private $preLoginHookCommand;

/** @var UserDisabledCheckCommand */
private $userDisabledCheckCommand;

/** @var UidLoginCommand */
private $uidLoginCommand;

/** @var EmailLoginCommand */
private $emailLoginCommand;

/** @var LoggedInCheckCommand */
private $loggedInCheckCommand;

/** @var CompleteLoginCommand */
private $completeLoginCommand;

/** @var CreateSessionTokenCommand */
private $createSessionTokenCommand;

/** @var ClearLostPasswordTokensCommand */
private $clearLostPasswordTokensCommand;

/** @var UpdateLastPasswordConfirmCommand */
private $updateLastPasswordConfirmCommand;

/** @var SetUserTimezoneCommand */
private $setUserTimezoneCommand;

/** @var TwoFactorCommand */
private $twoFactorCommand;

/** @var FinishRememberedLoginCommand */
private $finishRememberedLoginCommand;

public function __construct(PreLoginHookCommand $preLoginHookCommand,
UserDisabledCheckCommand $userDisabledCheckCommand,
UidLoginCommand $uidLoginCommand,
EmailLoginCommand $emailLoginCommand,
LoggedInCheckCommand $loggedInCheckCommand,
CompleteLoginCommand $completeLoginCommand,
CreateSessionTokenCommand $createSessionTokenCommand,
ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
SetUserTimezoneCommand $setUserTimezoneCommand,
TwoFactorCommand $twoFactorCommand,
FinishRememberedLoginCommand $finishRememberedLoginCommand,
public function __construct(
private PreLoginHookCommand $preLoginHookCommand,
private UserDisabledCheckCommand $userDisabledCheckCommand,
private UidLoginCommand $uidLoginCommand,
private EmailLoginCommand $emailLoginCommand,
private LoggedInCheckCommand $loggedInCheckCommand,
private CompleteLoginCommand $completeLoginCommand,
private CreateSessionTokenCommand $createSessionTokenCommand,
private ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
private UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
private SetUserTimezoneCommand $setUserTimezoneCommand,
private TwoFactorCommand $twoFactorCommand,
private FinishRememberedLoginCommand $finishRememberedLoginCommand,
) {
$this->preLoginHookCommand = $preLoginHookCommand;
$this->userDisabledCheckCommand = $userDisabledCheckCommand;
$this->uidLoginCommand = $uidLoginCommand;
$this->emailLoginCommand = $emailLoginCommand;
$this->loggedInCheckCommand = $loggedInCheckCommand;
$this->completeLoginCommand = $completeLoginCommand;
$this->createSessionTokenCommand = $createSessionTokenCommand;
$this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
$this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
$this->setUserTimezoneCommand = $setUserTimezoneCommand;
$this->twoFactorCommand = $twoFactorCommand;
$this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
}

public function process(LoginData $loginData): LoginResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
use OCP\IConfig;

class ClearLostPasswordTokensCommand extends ALoginCommand {
/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
$this->config = $config;
public function __construct(
private IConfig $config,
) {
}

/**
Expand Down
Loading
Loading