Skip to content

Commit b4d91bc

Browse files
authored
Merge pull request #943 from nextcloud/fix/fix-sabre-plugin-registering
fix: Register the dav plugin through an event listener
2 parents 138bcbc + 07d874d commit b4d91bc

File tree

7 files changed

+491
-19
lines changed

7 files changed

+491
-19
lines changed

appinfo/info.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ While theoretically any other authentication provider implementing either one of
2626
<namespace>User_SAML</namespace>
2727
<types>
2828
<authentication/>
29-
<dav/>
3029
</types>
3130
<documentation>
3231
<admin>https://portal.nextcloud.com/article/configuring-single-sign-on-10.html</admin>
@@ -61,9 +60,4 @@ While theoretically any other authentication provider implementing either one of
6160
<admin>OCA\User_SAML\Settings\Admin</admin>
6261
<admin-section>OCA\User_SAML\Settings\Section</admin-section>
6362
</settings>
64-
<sabre>
65-
<plugins>
66-
<plugin>OCA\User_SAML\DavPlugin</plugin>
67-
</plugins>
68-
</sabre>
6963
</info>

lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
use OC\Security\CSRF\CsrfTokenManager;
1313
use OC\User\LoginException;
1414
use OC_User;
15+
use OCA\DAV\Events\SabrePluginAddEvent;
1516
use OCA\User_SAML\DavPlugin;
1617
use OCA\User_SAML\GroupBackend;
1718
use OCA\User_SAML\GroupManager;
1819
use OCA\User_SAML\Listener\LoadAdditionalScriptsListener;
20+
use OCA\User_SAML\Listener\SabrePluginEventListener;
1921
use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware;
2022
use OCA\User_SAML\SAMLSettings;
2123
use OCA\User_SAML\UserBackend;
@@ -50,6 +52,7 @@ public function __construct(array $urlParams = []) {
5052
public function register(IRegistrationContext $context): void {
5153
$context->registerMiddleware(OnlyLoggedInMiddleware::class);
5254
$context->registerEventListener(BeforeTemplateRenderedEvent::class, LoadAdditionalScriptsListener::class);
55+
$context->registerEventListener(SabrePluginAddEvent::class, SabrePluginEventListener::class);
5356
$context->registerService(DavPlugin::class, function (ContainerInterface $c) {
5457
return new DavPlugin(
5558
$c->get(ISession::class),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\User_SAML\Listener;
11+
12+
use OCA\DAV\Events\SabrePluginAddEvent;
13+
use OCA\User_SAML\DavPlugin;
14+
use OCP\EventDispatcher\Event;
15+
use OCP\EventDispatcher\IEventListener;
16+
use OCP\Server;
17+
18+
/** @template-implements IEventListener<SabrePluginAddEvent|Event> */
19+
class SabrePluginEventListener implements IEventListener {
20+
public function handle(Event $event): void {
21+
if (!$event instanceof SabrePluginAddEvent) {
22+
return;
23+
}
24+
$event->getServer()->addPlugin(Server::get(DavPlugin::class));
25+
}
26+
}

tests/psalm-baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
- SPDX-License-Identifier: AGPL-3.0-or-later
55
-->
66
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
7-
<file src="lib/AppInfo/Application.php">
8-
<MissingDependency>
9-
<code><![CDATA[DavPlugin]]></code>
10-
<code><![CDATA[DavPlugin]]></code>
11-
</MissingDependency>
12-
</file>
137
<file src="lib/Controller/SAMLController.php">
148
<RedundantCondition>
159
<code><![CDATA[!$userExists]]></code>
@@ -29,11 +23,6 @@
2923
<code><![CDATA[ClientFlowLoginV2Controller]]></code>
3024
</UndefinedClass>
3125
</file>
32-
<file src="lib/DavPlugin.php">
33-
<UndefinedClass>
34-
<code><![CDATA[ServerPlugin]]></code>
35-
</UndefinedClass>
36-
</file>
3726
<file src="lib/Db/ConfigurationsMapper.php">
3827
<MissingTemplateParam>
3928
<code><![CDATA[ConfigurationsMapper]]></code>

tests/stub.phpstub

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ namespace OC\User {
6969
}
7070
}
7171

72+
namespace OCA\DAV\Connector\Sabre {
73+
class Auth {
74+
public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
75+
}
76+
}
77+
78+
namespace OCA\DAV\Events {
79+
use OCP\EventDispatcher\Event;
80+
use Sabre\DAV\Server;
81+
class SabrePluginAddEvent extends Event {
82+
public function getServer(): Server;
83+
}
84+
}
85+
7286
class OC_User {
7387
public static function useBackend($userBackend): void;
7488
public static function handleApacheAuth(): void;

vendor-bin/psalm/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"require-dev": {
33
"nextcloud/ocp": "dev-stable28",
4-
"vimeo/psalm": "^5.26"
4+
"vimeo/psalm": "^5.26",
5+
"sabre/dav": "4.7.0"
56
},
67
"config": {
78
"platform": {

0 commit comments

Comments
 (0)