diff --git a/lib/Service/LdapService.php b/lib/Service/LdapService.php
index e074d0546..13b27b2d5 100644
--- a/lib/Service/LdapService.php
+++ b/lib/Service/LdapService.php
@@ -10,8 +10,9 @@
namespace OCA\UserOIDC\Service;
use OCP\App\IAppManager;
-use OCP\AppFramework\QueryException;
use OCP\IUser;
+use OCP\Server;
+use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
class LdapService {
@@ -29,8 +30,6 @@ public function isLDAPEnabled(): bool {
/**
* @param IUser $user
* @return bool
- * @throws \Psr\Container\ContainerExceptionInterface
- * @throws \Psr\Container\NotFoundExceptionInterface
*/
public function isLdapDeletedUser(IUser $user): bool {
if (!$this->isLDAPEnabled()) {
@@ -43,9 +42,8 @@ public function isLdapDeletedUser(IUser $user): bool {
}
try {
- /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
- $dui = \OC::$server->get(\OCA\User_LDAP\User\DeletedUsersIndex::class);
- } catch (QueryException $e) {
+ $dui = Server::get(\OCA\User_LDAP\User\DeletedUsersIndex::class);
+ } catch (ContainerExceptionInterface $e) {
$this->logger->debug('\OCA\User_LDAP\User\DeletedUsersIndex class not found');
return false;
}
@@ -71,10 +69,9 @@ public function isLdapDeletedUser(IUser $user): bool {
*/
public function syncUser(string $userId): void {
try {
- /** @var \OCA\User_LDAP\User_Proxy */
- $ldapUserProxy = \OC::$server->get(\OCA\User_LDAP\User_Proxy::class);
+ $ldapUserProxy = Server::get(\OCA\User_LDAP\User_Proxy::class);
$ldapUserProxy->loginName2UserName($userId);
- } catch (QueryException $e) {
+ } catch (ContainerExceptionInterface $e) {
$this->logger->debug('\OCA\User_LDAP\User_Proxy class not found');
}
}
diff --git a/lib/User/Backend.php b/lib/User/Backend.php
index 2a99bb38b..31b0317ed 100644
--- a/lib/User/Backend.php
+++ b/lib/User/Backend.php
@@ -34,6 +34,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Server;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICountUsersBackend;
use OCP\User\Backend\ICustomLogout;
@@ -163,12 +164,7 @@ public function isSessionActive(): bool {
* {@inheritdoc}
*/
public function getLogoutUrl(): string {
- return $this->urlGenerator->linkToRouteAbsolute(
- 'user_oidc.login.singleLogoutService',
- [
- 'requesttoken' => \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(),
- ]
- );
+ return $this->urlGenerator->linkToRouteAbsolute('user_oidc.login.singleLogoutService');
}
/**
@@ -282,7 +278,7 @@ public function getCurrentUserId(): string {
// find user id through different token validation methods
foreach ($this->tokenValidators as $validatorClass) {
/** @var IBearerTokenValidator $validator */
- $validator = \OC::$server->get($validatorClass);
+ $validator = Server::get($validatorClass);
try {
$tokenUserId = $validator->isValidBearerToken($provider, $headerToken);
} catch (Throwable|Exception $e) {
@@ -428,7 +424,7 @@ private function provisionUser(
string $provisioningStrategyClass, Provider $provider, string $tokenUserId, string $headerToken,
?IUser $existingUser,
): ?IUser {
- $provisioningStrategy = \OC::$server->get($provisioningStrategyClass);
+ $provisioningStrategy = Server::get($provisioningStrategyClass);
return $provisioningStrategy->provisionUser($provider, $tokenUserId, $headerToken, $existingUser);
}
}
diff --git a/lib/User/Validator/SelfEncodedValidator.php b/lib/User/Validator/SelfEncodedValidator.php
index 99235936a..d9f4b8d0e 100644
--- a/lib/User/Validator/SelfEncodedValidator.php
+++ b/lib/User/Validator/SelfEncodedValidator.php
@@ -17,6 +17,7 @@
use OCA\UserOIDC\Vendor\Firebase\JWT\JWT;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Throwable;
@@ -33,7 +34,7 @@ public function __construct(
public function isValidBearerToken(Provider $provider, string $bearerToken): ?string {
/** @var ProviderService $providerService */
- $providerService = \OC::$server->get(ProviderService::class);
+ $providerService = Server::get(ProviderService::class);
$providerId = $provider->getId();
$uidAttribute = $providerService->getSetting($providerId, ProviderService::SETTING_MAPPING_UID, ProviderService::SETTING_MAPPING_UID_DEFAULT);
diff --git a/psalm.xml b/psalm.xml
index 749664361..41798efa8 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -72,6 +72,7 @@
+
diff --git a/tests/integration/Test.php b/tests/integration/Test.php
index 62ba2f6c7..33ee60516 100644
--- a/tests/integration/Test.php
+++ b/tests/integration/Test.php
@@ -12,8 +12,10 @@
use GuzzleHttp\RedirectMiddleware;
use OCA\UserOIDC\Db\ProviderMapper;
use OCA\UserOIDC\Service\ProviderService;
+use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IUserManager;
+use OCP\Server;
/**
* @group DB
@@ -28,7 +30,8 @@ class Test extends \Test\TestCase {
public function setUp(): void {
parent::setUp();
- \OC::$server->getAppManager()->enableApp('user_oidc');
+ $appManager = Server::get(IAppManager::class);
+ $appManager->enableApp('user_oidc');
if (getenv('IDP_URL')) {
$this->oidcIdp = getenv('IDP_URL');
@@ -39,7 +42,7 @@ public function setUp(): void {
}
$this->newClient();
- $this->providerService = \OC::$server->get(ProviderService::class);
+ $this->providerService = Server::get(ProviderService::class);
$this->providerService->setSetting(1, ProviderService::SETTING_UNIQUE_UID, '1');
$this->providerService->setSetting(1, ProviderService::SETTING_MAPPING_UID, '');
}
@@ -53,7 +56,7 @@ public function tearDown(): void {
private function cleanupUser(string $userId): void {
/** @var IUserManager $userManager */
- $userManager = \OC::$server->get(IUserManager::class);
+ $userManager = Server::get(IUserManager::class);
if ($userManager->userExists($userId)) {
$user = $userManager->get($userId);
$user->delete();
@@ -134,7 +137,7 @@ private function getUserHtmlData($response) {
public function testDisabledAutoProvision() {
sleep(5);
/** @var IUserManager $userManager */
- $userManager = \OC::$server->get(IUserManager::class);
+ $userManager = Server::get(IUserManager::class);
if (!$userManager->userExists('keycloak1')) {
$localUser = $userManager->createUser('keycloak1', 'passwordKeycloak1Local');
} else {
@@ -145,7 +148,7 @@ public function testDisabledAutoProvision() {
$localUser->setDisplayName('Local name');
/** @var IConfig $config */
- $config = \OC::$server->get(IConfig::class);
+ $config = Server::get(IConfig::class);
$config->setSystemValue('user_oidc', [ 'auto_provision' => false ]);
$this->providerService->setSetting(1, ProviderService::SETTING_UNIQUE_UID, '0');
@@ -179,7 +182,7 @@ public function testDisabledAutoProvision() {
public function testUnreachable() {
$provider = $this->providerService->getProviderByIdentifier('nextcloudci');
/** @var ProviderMapper $mapper */
- $mapper = \OC::$server->get(ProviderMapper::class);
+ $mapper = Server::get(ProviderMapper::class);
$previousDiscovery = $provider->getDiscoveryEndpoint();
diff --git a/tests/stubs/oca_user_ldap.php b/tests/stubs/oca_user_ldap.php
new file mode 100644
index 000000000..1e9f96bfa
--- /dev/null
+++ b/tests/stubs/oca_user_ldap.php
@@ -0,0 +1,40 @@
+
+ */
+ public function getUsers(): array {
+ return [];
+ }
+}
+
+namespace OCA\User_LDAP;
+
+class User_Proxy {
+ /**
+ * @return mixed
+ */
+ public function loginName2UserName(string $userId) {
+ return null;
+ }
+}