From 4c587436054b1332e6c968a7668140aa0bc6fd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 15 Apr 2025 16:52:22 +0200 Subject: [PATCH 1/4] fix: Register the dav plugin through an event listener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sabre plugins from info.xml are loaded only after auth has taken place, this is too late for user_saml. So this goes back to using an event, but uses the modern typed version. Signed-off-by: Côme Chilliet --- appinfo/info.xml | 6 ------ lib/AppInfo/Application.php | 3 +++ lib/Listener/SabrePluginEventListener.php | 26 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 lib/Listener/SabrePluginEventListener.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 2225101ec..0dd691cfd 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -26,7 +26,6 @@ While theoretically any other authentication provider implementing either one of User_SAML - https://portal.nextcloud.com/article/configuring-single-sign-on-10.html @@ -61,9 +60,4 @@ While theoretically any other authentication provider implementing either one of OCA\User_SAML\Settings\Admin OCA\User_SAML\Settings\Section - - - OCA\User_SAML\DavPlugin - - diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 150f395a2..1749a94b6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -16,6 +16,7 @@ use OCA\User_SAML\GroupBackend; use OCA\User_SAML\GroupManager; use OCA\User_SAML\Listener\LoadAdditionalScriptsListener; +use OCA\User_SAML\Listener\SabrePluginEventListener; use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware; use OCA\User_SAML\SAMLSettings; use OCA\User_SAML\UserBackend; @@ -35,6 +36,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\SabrePluginEvent; use OCP\Server; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -50,6 +52,7 @@ public function __construct(array $urlParams = []) { public function register(IRegistrationContext $context): void { $context->registerMiddleware(OnlyLoggedInMiddleware::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, LoadAdditionalScriptsListener::class); + $context->registerEventListener(SabrePluginEvent::class, SabrePluginEventListener::class); $context->registerService(DavPlugin::class, function (ContainerInterface $c) { return new DavPlugin( $c->get(ISession::class), diff --git a/lib/Listener/SabrePluginEventListener.php b/lib/Listener/SabrePluginEventListener.php new file mode 100644 index 000000000..830c07bea --- /dev/null +++ b/lib/Listener/SabrePluginEventListener.php @@ -0,0 +1,26 @@ + */ +class SabrePluginEventListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof SabrePluginEvent) { + return; + } + $event->getServer()->addPlugin(Server::get(DavPlugin::class)); + } +} From 8736286e8842211527614f43f217bb0069b9c98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 15 Apr 2025 17:21:51 +0200 Subject: [PATCH 2/4] chore: Fix psalm issues (require sabre/dav as a dev dep for psalm) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/Listener/SabrePluginEventListener.php | 2 +- tests/psalm-baseline.xml | 11 - tests/stub.phpstub | 6 + vendor-bin/psalm/composer.json | 3 +- vendor-bin/psalm/composer.lock | 447 +++++++++++++++++++++- 5 files changed, 455 insertions(+), 14 deletions(-) diff --git a/lib/Listener/SabrePluginEventListener.php b/lib/Listener/SabrePluginEventListener.php index 830c07bea..0b588c80a 100644 --- a/lib/Listener/SabrePluginEventListener.php +++ b/lib/Listener/SabrePluginEventListener.php @@ -9,7 +9,7 @@ namespace OCA\User_SAML\Listener; -use OCP\DavPlugin; +use OCA\User_SAML\DavPlugin; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\SabrePluginEvent; diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index dd0a1ef0d..a1e48ba4b 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -4,12 +4,6 @@ - SPDX-License-Identifier: AGPL-3.0-or-later --> - - - - - - @@ -29,11 +23,6 @@ - - - - - diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 04451c801..8eebffebe 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -69,6 +69,12 @@ namespace OC\User { } } +namespace OCA\DAV\Connector\Sabre { + class Auth { + public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; + } +} + class OC_User { public static function useBackend($userBackend): void; public static function handleApacheAuth(): void; diff --git a/vendor-bin/psalm/composer.json b/vendor-bin/psalm/composer.json index 3f6744b57..051d53ec8 100644 --- a/vendor-bin/psalm/composer.json +++ b/vendor-bin/psalm/composer.json @@ -1,7 +1,8 @@ { "require-dev": { "nextcloud/ocp": "dev-stable28", - "vimeo/psalm": "^5.26" + "vimeo/psalm": "^5.26", + "sabre/dav": "4.7.0" }, "config": { "platform": { diff --git a/vendor-bin/psalm/composer.lock b/vendor-bin/psalm/composer.lock index 7dfbafb43..3d889007c 100644 --- a/vendor-bin/psalm/composer.lock +++ b/vendor-bin/psalm/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a746ea836f63ffdca84b6be9af2ed4ee", + "content-hash": "82e4e755c70ea5f51c40de5df7ca9b26", "packages": [], "packages-dev": [ { @@ -1214,6 +1214,451 @@ }, "time": "2021-05-03T11:20:27+00:00" }, + { + "name": "sabre/dav", + "version": "4.7.0", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/dav.git", + "reference": "074373bcd689a30bcf5aaa6bbb20a3395964ce7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/dav/zipball/074373bcd689a30bcf5aaa6bbb20a3395964ce7a", + "reference": "074373bcd689a30bcf5aaa6bbb20a3395964ce7a", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-date": "*", + "ext-dom": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-pcre": "*", + "ext-simplexml": "*", + "ext-spl": "*", + "lib-libxml": ">=2.7.0", + "php": "^7.1.0 || ^8.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "sabre/event": "^5.0", + "sabre/http": "^5.0.5", + "sabre/uri": "^2.0", + "sabre/vobject": "^4.2.1", + "sabre/xml": "^2.0.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.19", + "monolog/monolog": "^1.27 || ^2.0", + "phpstan/phpstan": "^0.12 || ^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" + }, + "suggest": { + "ext-curl": "*", + "ext-imap": "*", + "ext-pdo": "*" + }, + "bin": [ + "bin/sabredav", + "bin/naturalselection" + ], + "type": "library", + "autoload": { + "psr-4": { + "Sabre\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + } + ], + "description": "WebDAV Framework for PHP", + "homepage": "http://sabre.io/", + "keywords": [ + "CalDAV", + "CardDAV", + "WebDAV", + "framework", + "iCalendar" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/dav/issues", + "source": "https://github.com/fruux/sabre-dav" + }, + "time": "2024-10-29T11:46:02+00:00" + }, + { + "name": "sabre/event", + "version": "5.1.7", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/event.git", + "reference": "86d57e305c272898ba3c28e9bd3d65d5464587c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/event/zipball/86d57e305c272898ba3c28e9bd3d65d5464587c2", + "reference": "86d57e305c272898ba3c28e9bd3d65d5464587c2", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.17.1||^3.63", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" + }, + "type": "library", + "autoload": { + "files": [ + "lib/coroutine.php", + "lib/Loop/functions.php", + "lib/Promise/functions.php" + ], + "psr-4": { + "Sabre\\Event\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + } + ], + "description": "sabre/event is a library for lightweight event-based programming", + "homepage": "http://sabre.io/event/", + "keywords": [ + "EventEmitter", + "async", + "coroutine", + "eventloop", + "events", + "hooks", + "plugin", + "promise", + "reactor", + "signal" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/event/issues", + "source": "https://github.com/fruux/sabre-event" + }, + "time": "2024-08-27T11:23:05+00:00" + }, + { + "name": "sabre/http", + "version": "5.1.12", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/http.git", + "reference": "dedff73f3995578bc942fa4c8484190cac14f139" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/http/zipball/dedff73f3995578bc942fa4c8484190cac14f139", + "reference": "dedff73f3995578bc942fa4c8484190cac14f139", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-curl": "*", + "ext-mbstring": "*", + "php": "^7.1 || ^8.0", + "sabre/event": ">=4.0 <6.0", + "sabre/uri": "^2.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.17.1||^3.63", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" + }, + "suggest": { + "ext-curl": " to make http requests with the Client class" + }, + "type": "library", + "autoload": { + "files": [ + "lib/functions.php" + ], + "psr-4": { + "Sabre\\HTTP\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + } + ], + "description": "The sabre/http library provides utilities for dealing with http requests and responses. ", + "homepage": "https://github.com/fruux/sabre-http", + "keywords": [ + "http" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/http/issues", + "source": "https://github.com/fruux/sabre-http" + }, + "time": "2024-08-27T16:07:41+00:00" + }, + { + "name": "sabre/uri", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/uri.git", + "reference": "b76524c22de90d80ca73143680a8e77b1266c291" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/uri/zipball/b76524c22de90d80ca73143680a8e77b1266c291", + "reference": "b76524c22de90d80ca73143680a8e77b1266c291", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.63", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", + "phpunit/phpunit": "^9.6" + }, + "type": "library", + "autoload": { + "files": [ + "lib/functions.php" + ], + "psr-4": { + "Sabre\\Uri\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + } + ], + "description": "Functions for making sense out of URIs.", + "homepage": "http://sabre.io/uri/", + "keywords": [ + "rfc3986", + "uri", + "url" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/uri/issues", + "source": "https://github.com/fruux/sabre-uri" + }, + "time": "2024-08-27T12:18:16+00:00" + }, + { + "name": "sabre/vobject", + "version": "4.5.6", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/vobject.git", + "reference": "900266bb3bd448a9f7f41f82344ad0aba237cb27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/vobject/zipball/900266bb3bd448a9f7f41f82344ad0aba237cb27", + "reference": "900266bb3bd448a9f7f41f82344ad0aba237cb27", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^7.1 || ^8.0", + "sabre/xml": "^2.1 || ^3.0 || ^4.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.17.1", + "phpstan/phpstan": "^0.12 || ^1.11", + "phpunit/php-invoker": "^2.0 || ^3.1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" + }, + "suggest": { + "hoa/bench": "If you would like to run the benchmark scripts" + }, + "bin": [ + "bin/vobject", + "bin/generate_vcards" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sabre\\VObject\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + }, + { + "name": "Dominik Tobschall", + "email": "dominik@fruux.com", + "homepage": "http://tobschall.de/", + "role": "Developer" + }, + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net", + "homepage": "http://mnt.io/", + "role": "Developer" + } + ], + "description": "The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects", + "homepage": "http://sabre.io/vobject/", + "keywords": [ + "availability", + "freebusy", + "iCalendar", + "ical", + "ics", + "jCal", + "jCard", + "recurrence", + "rfc2425", + "rfc2426", + "rfc2739", + "rfc4770", + "rfc5545", + "rfc5546", + "rfc6321", + "rfc6350", + "rfc6351", + "rfc6474", + "rfc6638", + "rfc6715", + "rfc6868", + "vCalendar", + "vCard", + "vcf", + "xCal", + "xCard" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/vobject/issues", + "source": "https://github.com/fruux/sabre-vobject" + }, + "time": "2024-10-14T11:53:54+00:00" + }, + { + "name": "sabre/xml", + "version": "2.2.11", + "source": { + "type": "git", + "url": "https://github.com/sabre-io/xml.git", + "reference": "01a7927842abf3e10df3d9c2d9b0cc9d813a3fcc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabre-io/xml/zipball/01a7927842abf3e10df3d9c2d9b0cc9d813a3fcc", + "reference": "01a7927842abf3e10df3d9c2d9b0cc9d813a3fcc", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlreader": "*", + "ext-xmlwriter": "*", + "lib-libxml": ">=2.6.20", + "php": "^7.1 || ^8.0", + "sabre/uri": ">=1.0,<3.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.17.1||3.63.2", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Deserializer/functions.php", + "lib/Serializer/functions.php" + ], + "psr-4": { + "Sabre\\Xml\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + }, + { + "name": "Markus Staab", + "email": "markus.staab@redaxo.de", + "role": "Developer" + } + ], + "description": "sabre/xml is an XML library that you may not hate.", + "homepage": "https://sabre.io/xml/", + "keywords": [ + "XMLReader", + "XMLWriter", + "dom", + "xml" + ], + "support": { + "forum": "https://groups.google.com/group/sabredav-discuss", + "issues": "https://github.com/sabre-io/xml/issues", + "source": "https://github.com/fruux/sabre-xml" + }, + "time": "2024-09-06T07:37:46+00:00" + }, { "name": "sebastian/diff", "version": "4.0.6", From 132081266f4aa5fd1fa3f3f4103fa2e5e5c8ed23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 15 Apr 2025 17:53:45 +0200 Subject: [PATCH 3/4] fix: Listen to the right event for adding a sabre plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/AppInfo/Application.php | 4 ++-- lib/Listener/SabrePluginEventListener.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1749a94b6..491e9e104 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -12,6 +12,7 @@ use OC\Security\CSRF\CsrfTokenManager; use OC\User\LoginException; use OC_User; +use OCA\DAV\Events\SabrePluginAddEvent; use OCA\User_SAML\DavPlugin; use OCA\User_SAML\GroupBackend; use OCA\User_SAML\GroupManager; @@ -36,7 +37,6 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; -use OCP\SabrePluginEvent; use OCP\Server; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -52,7 +52,7 @@ public function __construct(array $urlParams = []) { public function register(IRegistrationContext $context): void { $context->registerMiddleware(OnlyLoggedInMiddleware::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, LoadAdditionalScriptsListener::class); - $context->registerEventListener(SabrePluginEvent::class, SabrePluginEventListener::class); + $context->registerEventListener(SabrePluginAddEvent::class, SabrePluginEventListener::class); $context->registerService(DavPlugin::class, function (ContainerInterface $c) { return new DavPlugin( $c->get(ISession::class), diff --git a/lib/Listener/SabrePluginEventListener.php b/lib/Listener/SabrePluginEventListener.php index 0b588c80a..c30724ecd 100644 --- a/lib/Listener/SabrePluginEventListener.php +++ b/lib/Listener/SabrePluginEventListener.php @@ -9,16 +9,16 @@ namespace OCA\User_SAML\Listener; +use OCA\DAV\Events\SabrePluginAddEvent; use OCA\User_SAML\DavPlugin; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\SabrePluginEvent; use OCP\Server; -/** @template-implements IEventListener */ +/** @template-implements IEventListener */ class SabrePluginEventListener implements IEventListener { public function handle(Event $event): void { - if (!$event instanceof SabrePluginEvent) { + if (!$event instanceof SabrePluginAddEvent) { return; } $event->getServer()->addPlugin(Server::get(DavPlugin::class)); From 07d874d4b874acfb04e37b596efa338dcbd3b0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 15 Apr 2025 17:55:41 +0200 Subject: [PATCH 4/4] chore: Add missing stub from dav application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/stub.phpstub | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 8eebffebe..40d5235bf 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -75,6 +75,14 @@ namespace OCA\DAV\Connector\Sabre { } } +namespace OCA\DAV\Events { + use OCP\EventDispatcher\Event; + use Sabre\DAV\Server; + class SabrePluginAddEvent extends Event { + public function getServer(): Server; + } +} + class OC_User { public static function useBackend($userBackend): void; public static function handleApacheAuth(): void;