diff --git a/README.md b/README.md index 026af5e..6dca470 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,23 @@ occ config:system:set wordpress_dsn --value "mysql:host=myserverhostname;port=33 Replace the values by your database settings. +The database user only needs `SELECT` on the tables read by the queries +(`wp_users` and `wp_wc_orders` with the default ones) and `UPDATE` on +`wp_users.user_pass`: + +```sql +GRANT SELECT ON woocommerce.wp_users TO 'nextcloud'@'%'; +GRANT SELECT ON woocommerce.wp_wc_orders TO 'nextcloud'@'%'; +GRANT UPDATE (user_pass) ON woocommerce.wp_users TO 'nextcloud'@'%'; +``` + +### Linked accounts + +Only accounts linked to a WordPress user can log in with the WordPress +password, and only their password changes are written back to WordPress. The +WordPress user is the one whose `user_login` is exactly the account uid. See +[Linking existing accounts](#linking-existing-accounts). + ### Custom SQL queries (optional) You can override default SQL queries using the `wordpress_queries` system key, @@ -31,7 +48,7 @@ Supported query keys: Example: ```bash -occ config:system:set wordpress_queries --type json --value '{"get_wordpress_user":"SELECT user_pass AS password, user_login AS uid, display_name AS displayname, 1 AS enabled FROM wp_users WHERE user_login = :username OR user_email = :username","get_disabled_users":"SELECT user_login AS uid FROM wp_users WHERE user_login LIKE :search","set_wordpress_password":"UPDATE wp_users SET user_pass = :hash WHERE user_login = :username"}' +occ config:system:set wordpress_queries --type json --value '{"get_wordpress_user":"SELECT user_pass AS password, user_login AS uid, display_name AS displayname, 1 AS enabled FROM wp_users WHERE user_login = :username","get_disabled_users":"SELECT user_login AS uid FROM wp_users WHERE user_login LIKE :search","set_wordpress_password":"UPDATE wp_users SET user_pass = :hash WHERE user_login = :username"}' ``` The backend expects these named parameters: @@ -46,6 +63,12 @@ An account is linked to WordPress by the user preference `wordpress_login` of the app `wordpress_login_backend`, holding the account uid. Admin Group Manager records it when it creates the account that owns a group. +When upgrading from a version that did not require the link, deploy in this +order, otherwise the existing customers cannot log in: + +1. a version of Admin Group Manager that records the link; +2. this app, then run the command below to link the existing accounts. + To link the accounts created before that, run: ```bash diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e58e76f..e4a6a5b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -6,12 +6,12 @@ namespace OCA\WordPressLoginBackend\AppInfo; -use OCA\WordPressLoginBackend\Listener\BeforePasswordUpdatedListener; +use OCA\WordPressLoginBackend\Listener\PasswordUpdatedListener; use \OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\User\Events\BeforePasswordUpdatedEvent; +use OCP\User\Events\PasswordUpdatedEvent; class Application extends App implements IBootstrap { public const APP_ID = 'wordpress_login_backend'; @@ -28,6 +28,6 @@ public function boot(IBootContext $context): void { } public function register(IRegistrationContext $context): void { - $context->registerEventListener(BeforePasswordUpdatedEvent::class, BeforePasswordUpdatedListener::class); + $context->registerEventListener(PasswordUpdatedEvent::class, PasswordUpdatedListener::class); } } diff --git a/lib/Backend/UserBackend.php b/lib/Backend/UserBackend.php index 64d11a3..6058f01 100644 --- a/lib/Backend/UserBackend.php +++ b/lib/Backend/UserBackend.php @@ -6,7 +6,9 @@ namespace OCA\WordPressLoginBackend\Backend; +use OCA\WordPressLoginBackend\AppInfo\Application; use OCA\WordPressLoginBackend\Config\QueryConfig; +use OCA\WordPressLoginBackend\Db\WordPressUsers; use OCA\WordPressLoginBackend\Helper\HashPassword; use OCP\Cache\CappedMemoryCache; use OCP\IConfig; @@ -28,6 +30,7 @@ public function __construct( private CappedMemoryCache $cache, private IConfig $config, private IDBConnection $dbConn, + private WordPressUsers $wordPressUsers, ) { $this->dsn = (string) $this->config->getSystemValue('wordpress_dsn', ''); $this->queryConfig = new QueryConfig($this->config); @@ -82,7 +85,7 @@ public function checkPassword(string $loginName, string $password) { $hashPassword = new HashPassword(); $isOk = $hashPassword->checkPassword($password, $user['password']); if ($isOk) { - return $loginName; + return $user['uid']; } return false; } @@ -117,27 +120,19 @@ private function loadUser($uid) { return false; } - $db = $this->getDatabase(); - if (!$db) { - $this->cache[$uid] = false; - return false; - } - $statement = $db->prepare($this->queryConfig->getWordPressUserQuery()); - $statement->execute(['username' => $uid]); - $row = $statement->fetch(PDO::FETCH_ASSOC); - - // "uid" is primary key, so there can only be a single result - if ($row !== false) { - $this->cache[$uid] = [ - 'uid' => (string)$row['uid'], - 'displayname' => (string)$row['displayname'], - 'password' => (string)$row['password'], - 'enabled' => (bool)$row['enabled'], - ]; - } else { + $nextcloudUid = (string)$nextcloudUser['uid']; + $linkedLogin = $this->config->getUserValue($nextcloudUid, Application::APP_ID, Application::LINKED_LOGIN_KEY); + $row = $linkedLogin === $nextcloudUid ? $this->wordPressUsers->findByLogin($nextcloudUid) : null; + if ($row === null) { $this->cache[$uid] = false; return false; } + $this->cache[$uid] = [ + 'uid' => (string)$row['uid'], + 'displayname' => (string)$row['displayname'], + 'password' => (string)$row['password'], + 'enabled' => (bool)$row['enabled'], + ]; } return $this->cache[$uid]; diff --git a/lib/Config/QueryConfig.php b/lib/Config/QueryConfig.php index 956b2de..9c85f96 100644 --- a/lib/Config/QueryConfig.php +++ b/lib/Config/QueryConfig.php @@ -31,7 +31,8 @@ class QueryConfig { ELSE 0 END AS enabled FROM wp_users u - WHERE (u.user_login = :username OR u.user_email = :username) + WHERE u.user_login = :username + AND HEX(u.user_login) = HEX(:username) SQL; public const DEFAULT_GET_DISABLED_USERS = <<<'SQL' @@ -39,12 +40,16 @@ class QueryConfig { FROM wp_wc_orders o JOIN wp_users u ON o.customer_id = u.ID WHERE (o.status NOT IN ('wc-active') OR o.type <> 'shop_subscription') - AND (u.user_login LIKE :search OR u.user_email LIKE :search) + AND u.user_login LIKE :search GROUP BY u.user_login SQL; - public const DEFAULT_SET_WORDPRESS_PASSWORD = - 'UPDATE wp_users SET user_pass = :hash WHERE user_login = :username'; + public const DEFAULT_SET_WORDPRESS_PASSWORD = <<<'SQL' + UPDATE wp_users + SET user_pass = :hash + WHERE user_login = :username + AND HEX(user_login) = HEX(:username) + SQL; public function __construct( private IConfig $config, diff --git a/lib/Db/WordPressUsers.php b/lib/Db/WordPressUsers.php index eaaf15f..25334e1 100644 --- a/lib/Db/WordPressUsers.php +++ b/lib/Db/WordPressUsers.php @@ -37,6 +37,17 @@ public function findByLogin(string $login): ?array { return null; } + public function updatePassword(string $login, string $hash): void { + $database = $this->getDatabase(); + if (!$database) { + return; + } + $statement = $database->prepare($this->queryConfig->setWordPressPasswordQuery()); + $statement->bindValue(':username', $login); + $statement->bindValue(':hash', $hash); + $statement->execute(); + } + private function getDatabase(): ?PDO { $dsn = (string)$this->config->getSystemValue('wordpress_dsn', ''); if ($dsn === '') { diff --git a/lib/Listener/BeforePasswordUpdatedListener.php b/lib/Listener/BeforePasswordUpdatedListener.php deleted file mode 100644 index 6a5b338..0000000 --- a/lib/Listener/BeforePasswordUpdatedListener.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -class BeforePasswordUpdatedListener implements IEventListener { - private string $dsn; - private ?PDO $pdo = null; - private QueryConfig $queryConfig; - public function __construct( - private IConfig $config, - ) { - $this->dsn = (string) $this->config->getSystemValue('wordpress_dsn', ''); - $this->queryConfig = new QueryConfig($this->config); - } - - public function handle(Event $event): void { - if (!$event instanceof BeforePasswordUpdatedEvent) { - return; - } - $db = $this->getDatabase(); - if (!$db) { - return; - } - $hashPassword = new HashPassword(); - $username = $event->getUser()->getUID(); - if ($hashPassword->validate($event->getPassword(), $this->getWordPressHash($db, $username))) { - return; - } - $hash = $hashPassword->hashPassword($event->getPassword()); - $statement = $db->prepare($this->queryConfig->setWordPressPasswordQuery()); - $statement->bindValue(':username', $username); - $statement->bindValue(':hash', $hash); - $statement->execute(); - } - - private function getWordPressHash(PDO $db, string $username): string { - $statement = $db->prepare($this->queryConfig->getWordPressUserQuery()); - $statement->execute(['username' => $username]); - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { - if ((string)$row['uid'] === $username) { - return (string)$row['password']; - } - } - return ''; - } - - private function getDatabase(): ?PDO { - if (!$this->dsn) { - return null; - } - if (!$this->pdo instanceof PDO) { - $this->pdo = new PDO($this->dsn); - } - return $this->pdo; - } -} diff --git a/lib/Listener/PasswordUpdatedListener.php b/lib/Listener/PasswordUpdatedListener.php new file mode 100644 index 0000000..dba4e60 --- /dev/null +++ b/lib/Listener/PasswordUpdatedListener.php @@ -0,0 +1,54 @@ + + */ +class PasswordUpdatedListener implements IEventListener { + public function __construct( + private IConfig $config, + private WordPressUsers $wordPressUsers, + private LoggerInterface $logger, + ) { + } + + public function handle(Event $event): void { + if (!$event instanceof PasswordUpdatedEvent) { + return; + } + $username = $event->getUser()->getUID(); + if ($this->config->getUserValue($username, Application::APP_ID, Application::LINKED_LOGIN_KEY) !== $username) { + return; + } + $hashPassword = new HashPassword(); + try { + $wordPressUser = $this->wordPressUsers->findByLogin($username); + if ($wordPressUser === null || $hashPassword->validate($event->getPassword(), (string)$wordPressUser['password'])) { + return; + } + $this->wordPressUsers->updatePassword($username, $hashPassword->hashPassword($event->getPassword())); + } catch (PDOException $exception) { + $this->logger->error('Could not update the WordPress password of {uid}', [ + 'uid' => $username, + 'exception' => $exception, + ]); + } + } +} diff --git a/tests/Unit/Backend/UserBackendTest.php b/tests/Unit/Backend/UserBackendTest.php new file mode 100644 index 0000000..0ca2c5a --- /dev/null +++ b/tests/Unit/Backend/UserBackendTest.php @@ -0,0 +1,150 @@ +databaseFile = tempnam(sys_get_temp_dir(), 'wordpress'); + $this->database = new PDO('sqlite:' . $this->databaseFile); + $this->database->exec('CREATE TABLE wp_users (ID INTEGER PRIMARY KEY, user_login TEXT COLLATE NOCASE, user_email TEXT, user_pass TEXT, display_name TEXT)'); + $this->database->exec('CREATE TABLE wp_wc_orders (customer_id INTEGER, status TEXT, type TEXT)'); + } + + protected function tearDown(): void { + unlink($this->databaseFile); + } + + public function testAuthenticatesALinkedAccount(): void { + $this->createWordPressUser('ana', 'secret'); + $this->nextcloudUids[] = 'ana'; + $this->linkedLogins['ana'] = 'ana'; + + $this->assertSame('ana', $this->backend()->checkPassword('ana', 'secret')); + } + + public function testReturnsTheNextcloudUidWhenTheLoginDiffersInCase(): void { + $this->createWordPressUser('ana', 'secret'); + $this->nextcloudUids[] = 'ana'; + $this->linkedLogins['ana'] = 'ana'; + + $this->assertSame('ana', $this->backend()->checkPassword('ANA', 'secret')); + } + + public function testRefusesAnAccountThatIsNotLinkedToWordPress(): void { + $this->createWordPressUser('ana', 'secret'); + $this->nextcloudUids[] = 'ana'; + + $this->assertFalse($this->backend()->checkPassword('ana', 'secret')); + } + + public function testRefusesAnAccountLinkedToAnotherLogin(): void { + $this->createWordPressUser('ana', 'secret'); + $this->nextcloudUids[] = 'ana'; + $this->linkedLogins['ana'] = 'bruno'; + + $this->assertFalse($this->backend()->checkPassword('ana', 'secret')); + } + + public function testRefusesTheWordPressUserWhoseEmailIsTheUid(): void { + $this->createWordPressUser('bruno', 'password of bruno', 'ana@example.org'); + $this->createWordPressUser('ana@example.org', 'password of ana', 'ana@example.net'); + $this->nextcloudUids[] = 'ana@example.org'; + $this->linkedLogins['ana@example.org'] = 'ana@example.org'; + + $backend = $this->backend(); + + $this->assertFalse($backend->checkPassword('ana@example.org', 'password of bruno')); + $this->assertSame('ana@example.org', $backend->checkPassword('ana@example.org', 'password of ana')); + } + + public function testRefusesAWordPressLoginThatDiffersOnlyInCase(): void { + $this->createWordPressUser('Ana', 'secret'); + $this->nextcloudUids[] = 'ana'; + $this->linkedLogins['ana'] = 'ana'; + + $this->assertFalse($this->backend()->checkPassword('ana', 'secret')); + } + + public function testRefusesALoginMissingFromNextcloud(): void { + $this->createWordPressUser('ana', 'secret'); + $this->linkedLogins['ana'] = 'ana'; + + $this->assertFalse($this->backend()->checkPassword('ana', 'secret')); + } + + private function createWordPressUser(string $login, string $password, ?string $email = null): void { + $statement = $this->database->prepare('INSERT INTO wp_users (user_login, user_email, user_pass, display_name) VALUES (:login, :email, :hash, :login)'); + $statement->execute([ + 'login' => $login, + 'email' => $email ?? $login . '@example.org', + 'hash' => (new HashPassword())->hashPassword($password), + ]); + } + + private function backend(): UserBackend { + $config = $this->createMock(IConfig::class); + $config->method('getSystemValue')->willReturnMap([ + ['wordpress_dsn', '', 'sqlite:' . $this->databaseFile], + ['wordpress_queries', [], []], + ]); + $config->method('getUserValue')->willReturnCallback( + fn (string $userId, string $appName, string $key) => $appName === 'wordpress_login_backend' && $key === 'wordpress_login' + ? ($this->linkedLogins[$userId] ?? '') + : '', + ); + + return new UserBackend(new CappedMemoryCache(), $config, $this->nextcloudDatabase(), new WordPressUsers($config)); + } + + private function nextcloudDatabase(): IDBConnection { + $lowercaseUid = null; + $expression = $this->createMock(IExpressionBuilder::class); + $expression->method('eq')->willReturn(''); + $queryBuilder = $this->createMock(IQueryBuilder::class); + foreach (['select', 'from', 'where', 'setMaxResults'] as $method) { + $queryBuilder->method($method)->willReturnSelf(); + } + $queryBuilder->method('expr')->willReturn($expression); + $queryBuilder->method('createNamedParameter')->willReturnCallback(function (string $value) use (&$lowercaseUid): string { + $lowercaseUid = $value; + return ':uid'; + }); + $queryBuilder->method('executeQuery')->willReturnCallback(function () use (&$lowercaseUid): IResult { + $row = false; + foreach ($this->nextcloudUids as $uid) { + if (mb_strtolower($uid) === $lowercaseUid) { + $row = ['uid' => $uid, 'displayname' => $uid, 'password' => '']; + } + } + $result = $this->createMock(IResult::class); + $result->method('fetch')->willReturn($row); + return $result; + }); + $connection = $this->createMock(IDBConnection::class); + $connection->method('getQueryBuilder')->willReturn($queryBuilder); + return $connection; + } +} diff --git a/tests/Unit/Listener/BeforePasswordUpdatedListenerTest.php b/tests/Unit/Listener/PasswordUpdatedListenerTest.php similarity index 53% rename from tests/Unit/Listener/BeforePasswordUpdatedListenerTest.php rename to tests/Unit/Listener/PasswordUpdatedListenerTest.php index 99b26ec..5e80298 100644 --- a/tests/Unit/Listener/BeforePasswordUpdatedListenerTest.php +++ b/tests/Unit/Listener/PasswordUpdatedListenerTest.php @@ -8,22 +8,26 @@ namespace OCA\WordPressLoginBackend\Tests\Unit\Listener; +use OCA\WordPressLoginBackend\Db\WordPressUsers; use OCA\WordPressLoginBackend\Helper\HashPassword; -use OCA\WordPressLoginBackend\Listener\BeforePasswordUpdatedListener; +use OCA\WordPressLoginBackend\Listener\PasswordUpdatedListener; use OCP\IConfig; use OCP\IUser; -use OCP\User\Events\BeforePasswordUpdatedEvent; +use OCP\User\Events\PasswordUpdatedEvent; use PDO; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; -class BeforePasswordUpdatedListenerTest extends TestCase { +class PasswordUpdatedListenerTest extends TestCase { private string $databaseFile; private PDO $database; + private array $linkedLogins = []; + private array $queries = []; protected function setUp(): void { $this->databaseFile = tempnam(sys_get_temp_dir(), 'wordpress'); $this->database = new PDO('sqlite:' . $this->databaseFile); - $this->database->exec('CREATE TABLE wp_users (ID INTEGER PRIMARY KEY, user_login TEXT, user_email TEXT, user_pass TEXT, display_name TEXT)'); + $this->database->exec('CREATE TABLE wp_users (ID INTEGER PRIMARY KEY, user_login TEXT COLLATE NOCASE, user_email TEXT, user_pass TEXT, display_name TEXT)'); $this->database->exec('CREATE TABLE wp_wc_orders (customer_id INTEGER, status TEXT, type TEXT)'); } @@ -33,6 +37,7 @@ protected function tearDown(): void { public function testWritesTheNewPasswordToWordPress(): void { $this->createWordPressUser('ana', (new HashPassword())->hashPassword('old password')); + $this->linkedLogins['ana'] = 'ana'; $this->changePassword('ana', 'new password'); @@ -42,6 +47,7 @@ public function testWritesTheNewPasswordToWordPress(): void { public function testKeepsTheWordPressHashThatAlreadyMatchesTheNewPassword(): void { $hash = (new HashPassword())->hashPassword('new password'); $this->createWordPressUser('ana', $hash); + $this->linkedLogins['ana'] = 'ana'; $this->changePassword('ana', 'new password'); @@ -51,40 +57,87 @@ public function testKeepsTheWordPressHashThatAlreadyMatchesTheNewPassword(): voi public function testWritesTheNewPasswordWhenAnotherUserHasTheLoginAsEmail(): void { $this->createWordPressUser('bruno', (new HashPassword())->hashPassword('new password'), 'ana@example.org'); $this->createWordPressUser('ana@example.org', (new HashPassword())->hashPassword('old password'), 'ana@example.net'); + $this->linkedLogins['ana@example.org'] = 'ana@example.org'; $this->changePassword('ana@example.org', 'new password'); $this->assertTrue((new HashPassword())->validate('new password', $this->wordPressHashOf('ana@example.org'))); } + public function testKeepsTheHashOfALoginThatDiffersOnlyInCase(): void { + $this->createWordPressUser('ana', (new HashPassword())->hashPassword('old password')); + $this->createWordPressUser('Ana', 'hash of Ana', 'other@example.org'); + $this->linkedLogins['ana'] = 'ana'; + + $this->changePassword('ana', 'new password'); + + $this->assertSame('hash of Ana', $this->wordPressHashOf('Ana')); + } + public function testIgnoresAUserMissingFromWordPress(): void { $this->createWordPressUser('ana', 'hash of ana'); + $this->linkedLogins['bruno'] = 'bruno'; $this->changePassword('bruno', 'new password'); $this->assertSame('hash of ana', $this->wordPressHashOf('ana')); } + public function testIgnoresAnAccountThatIsNotLinkedToWordPress(): void { + $this->createWordPressUser('ana', 'hash of ana'); + + $this->changePassword('ana', 'new password'); + + $this->assertSame('hash of ana', $this->wordPressHashOf('ana')); + } + + public function testIgnoresAnAccountLinkedToAnotherLogin(): void { + $this->createWordPressUser('ana', 'hash of ana'); + $this->linkedLogins['ana'] = 'bruno'; + + $this->changePassword('ana', 'new password'); + + $this->assertSame('hash of ana', $this->wordPressHashOf('ana')); + } + + public function testLogsAFailedUpdateWithoutThrowing(): void { + $this->createWordPressUser('ana', 'hash of ana'); + $this->linkedLogins['ana'] = 'ana'; + $this->queries['set_wordpress_password'] = 'UPDATE missing_table SET user_pass = :hash WHERE user_login = :username'; + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->once())->method('error'); + + $this->changePassword('ana', 'new password', $logger); + + $this->assertSame('hash of ana', $this->wordPressHashOf('ana')); + } + private function createWordPressUser(string $login, string $hash, ?string $email = null): void { $statement = $this->database->prepare('INSERT INTO wp_users (user_login, user_email, user_pass, display_name) VALUES (:login, :email, :hash, :login)'); $statement->execute(['login' => $login, 'email' => $email ?? $login . '@example.org', 'hash' => $hash]); } private function wordPressHashOf(string $login): string { - $statement = $this->database->prepare('SELECT user_pass FROM wp_users WHERE user_login = :login'); + $statement = $this->database->prepare('SELECT user_pass FROM wp_users WHERE user_login = :login COLLATE BINARY'); $statement->execute(['login' => $login]); return (string)$statement->fetchColumn(); } - private function changePassword(string $uid, string $password): void { + private function changePassword(string $uid, string $password, ?LoggerInterface $logger = null): void { $config = $this->createMock(IConfig::class); $config->method('getSystemValue')->willReturnMap([ ['wordpress_dsn', '', 'sqlite:' . $this->databaseFile], - ['wordpress_queries', [], []], + ['wordpress_queries', [], $this->queries], ]); + $config->method('getUserValue')->willReturnCallback( + fn (string $userId, string $appName, string $key) => $appName === 'wordpress_login_backend' && $key === 'wordpress_login' + ? ($this->linkedLogins[$userId] ?? '') + : '', + ); $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn($uid); - (new BeforePasswordUpdatedListener($config))->handle(new BeforePasswordUpdatedEvent($user, $password)); + $listener = new PasswordUpdatedListener($config, new WordPressUsers($config), $logger ?? $this->createMock(LoggerInterface::class)); + $listener->handle(new PasswordUpdatedEvent($user, $password)); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6c90379..f9e3d47 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -52,6 +52,108 @@ public function get($uid); } } +namespace OCP { + use OCP\DB\QueryBuilder\IQueryBuilder; + + if (!interface_exists(IDBConnection::class)) { + interface IDBConnection { + public function getQueryBuilder(): IQueryBuilder; + } + } +} + +namespace OCP\DB { + if (!interface_exists(IResult::class)) { + interface IResult { + public function fetch(int $fetchMode = \PDO::FETCH_ASSOC); + + public function closeCursor(): bool; + } + } +} + +namespace OCP\DB\QueryBuilder { + use OCP\DB\IResult; + + if (!interface_exists(IExpressionBuilder::class)) { + interface IExpressionBuilder { + public function eq($x, $y, $type = null): string; + } + } + + if (!interface_exists(IQueryBuilder::class)) { + interface IQueryBuilder { + public function select(...$selects); + + public function from($from, $alias = null); + + public function where(...$predicates); + + public function expr(): IExpressionBuilder; + + public function createNamedParameter($value, $type = null, $placeHolder = null); + + public function setMaxResults($maxResults); + + public function executeQuery(): IResult; + } + } +} + +namespace OCP\Cache { + if (!class_exists(CappedMemoryCache::class)) { + class CappedMemoryCache implements \ArrayAccess { + private array $cache = []; + + public function offsetExists($offset): bool { + return isset($this->cache[$offset]); + } + + public function offsetGet($offset): mixed { + return $this->cache[$offset]; + } + + public function offsetSet($offset, $value): void { + $this->cache[$offset] = $value; + } + + public function offsetUnset($offset): void { + unset($this->cache[$offset]); + } + } + } +} + +namespace OCP\User\Backend { + if (!class_exists(ABackend::class)) { + abstract class ABackend { + } + } + + if (!interface_exists(ICheckPasswordBackend::class)) { + interface ICheckPasswordBackend { + } + } + + if (!interface_exists(IGetRealUIDBackend::class)) { + interface IGetRealUIDBackend { + } + } + + if (!interface_exists(IProvideEnabledStateBackend::class)) { + interface IProvideEnabledStateBackend { + } + } +} + +namespace Psr\Log { + if (!interface_exists(LoggerInterface::class)) { + interface LoggerInterface { + public function error($message, array $context = []); + } + } +} + namespace OCP\Group { use OCP\IGroup; use OCP\IUser; @@ -96,8 +198,8 @@ public function handle(Event $event): void; use OCP\EventDispatcher\Event; use OCP\IUser; - if (!class_exists(BeforePasswordUpdatedEvent::class)) { - class BeforePasswordUpdatedEvent extends Event { + if (!class_exists(PasswordUpdatedEvent::class)) { + class PasswordUpdatedEvent extends Event { public function __construct( private IUser $user, private string $password,