diff --git a/lib/Command/ConfigCreate.php b/lib/Command/ConfigCreate.php index d25f11532..3b9d9953a 100644 --- a/lib/Command/ConfigCreate.php +++ b/lib/Command/ConfigCreate.php @@ -13,11 +13,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ConfigCreate extends Base { - private SAMLSettings $samlSettings; - public function __construct(SAMLSettings $samlSettings) { + public function __construct( + private SAMLSettings $samlSettings, + ) { parent::__construct(); - $this->samlSettings = $samlSettings; } protected function configure(): void { diff --git a/lib/Command/ConfigDelete.php b/lib/Command/ConfigDelete.php index eba270cc2..090e39345 100644 --- a/lib/Command/ConfigDelete.php +++ b/lib/Command/ConfigDelete.php @@ -15,11 +15,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ConfigDelete extends Base { - private SAMLSettings $samlSettings; - public function __construct(SAMLSettings $samlSettings) { + public function __construct( + private SAMLSettings $samlSettings, + ) { parent::__construct(); - $this->samlSettings = $samlSettings; } protected function configure(): void { diff --git a/lib/Command/ConfigGet.php b/lib/Command/ConfigGet.php index 501f83434..998f8c5c8 100644 --- a/lib/Command/ConfigGet.php +++ b/lib/Command/ConfigGet.php @@ -14,11 +14,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ConfigGet extends Base { - private SAMLSettings $samlSettings; - public function __construct(SAMLSettings $samlSettings) { + public function __construct( + private SAMLSettings $samlSettings, + ) { parent::__construct(); - $this->samlSettings = $samlSettings; } protected function configure(): void { diff --git a/lib/Command/ConfigSet.php b/lib/Command/ConfigSet.php index d903a06c6..88e8aaa84 100644 --- a/lib/Command/ConfigSet.php +++ b/lib/Command/ConfigSet.php @@ -16,11 +16,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ConfigSet extends Base { - private SAMLSettings $samlSettings; - public function __construct(SAMLSettings $samlSettings) { + public function __construct( + private SAMLSettings $samlSettings, + ) { parent::__construct(); - $this->samlSettings = $samlSettings; } protected function configure(): void { diff --git a/lib/Command/GetMetadata.php b/lib/Command/GetMetadata.php index ae4bbc808..fa67e144c 100644 --- a/lib/Command/GetMetadata.php +++ b/lib/Command/GetMetadata.php @@ -17,13 +17,10 @@ class GetMetadata extends Command { use TXmlHelper; - private SAMLSettings $SAMLSettings; - public function __construct( - SAMLSettings $SAMLSettings, + private SAMLSettings $samlSettings, ) { parent::__construct(); - $this->SAMLSettings = $SAMLSettings; } protected function configure(): void { @@ -49,7 +46,11 @@ protected function configure(): void { protected function execute(InputInterface $input, OutputInterface $output): int { $idp = (int)$input->getArgument('idp'); - $settings = new Settings($this->SAMLSettings->getOneLoginSettingsArray($idp)); + $settingsArray = $this->samlSettings->getOneLoginSettingsArray($idp); + if ($settingsArray === null) { + throw new \InvalidArgumentException('Settings cannot be null'); + } + $settings = new Settings($settingsArray); $metadata = $settings->getSPMetadata(); $errors = $this->callWithXmlEntityLoader(function () use ($settings, $metadata) { return $settings->validateMetadata($metadata); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index be3bfd5ff..74064a46e 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -17,24 +17,14 @@ class SettingsController extends Controller { - /** @var IConfig */ - private $config; - /** @var Admin */ - private $admin; - /** @var SAMLSettings */ - private $samlSettings; - public function __construct( $appName, IRequest $request, - IConfig $config, - Admin $admin, - SAMLSettings $samlSettings, + private IConfig $config, + private Admin $admin, + private SAMLSettings $samlSettings, ) { parent::__construct($appName, $request); - $this->config = $config; - $this->admin = $admin; - $this->samlSettings = $samlSettings; } public function getSamlProviderIds(): DataResponse { diff --git a/lib/Controller/TimezoneController.php b/lib/Controller/TimezoneController.php index 0518addcd..366ab0a6d 100644 --- a/lib/Controller/TimezoneController.php +++ b/lib/Controller/TimezoneController.php @@ -16,22 +16,14 @@ class TimezoneController extends Controller { - /** @var IConfig */ - private $config; - /** @var string */ - private $userId; - /** @var ISession */ - private $session; - - public function __construct($appName, + public function __construct( + $appName, IRequest $request, - IConfig $config, - $userId, - ISession $session) { + private IConfig $config, + private $userId, + private ISession $session, + ) { parent::__construct($appName, $request); - $this->config = $config; - $this->userId = $userId; - $this->session = $session; } /** diff --git a/lib/DavPlugin.php b/lib/DavPlugin.php index 17e98572a..1d8337f45 100644 --- a/lib/DavPlugin.php +++ b/lib/DavPlugin.php @@ -15,22 +15,17 @@ use Sabre\HTTP\ResponseInterface; class DavPlugin extends ServerPlugin { - private $session; - private $config; - private $auth; /** @var Server */ private $server; - /** @var SAMLSettings */ - private $samlSettings; - public function __construct(ISession $session, IConfig $config, array $auth, SAMLSettings $samlSettings) { - $this->session = $session; - $this->config = $config; - $this->auth = $auth; - $this->samlSettings = $samlSettings; + public function __construct( + private ISession $session, + private IConfig $config, + private array $auth, + private SAMLSettings $samlSettings, + ) { } - public function initialize(Server $server) { // before auth $server->on('beforeMethod:*', [$this, 'beforeMethod'], 9); diff --git a/lib/GroupManager.php b/lib/GroupManager.php index 0b3c3468f..7bb031328 100644 --- a/lib/GroupManager.php +++ b/lib/GroupManager.php @@ -20,46 +20,22 @@ use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; +use OCP\Server; +use Psr\Log\LoggerInterface; class GroupManager { public const LOCAL_GROUPS_CHECK_FOR_MIGRATION = 'localGroupsCheckForMigration'; public const STATE_MIGRATION_PHASE_EXPIRED = 'EXPIRED'; - /** - * @var IDBConnection $db - */ - protected $db; - - /** @var IGroupManager */ - private $groupManager; - /** @var GroupBackend */ - private $ownGroupBackend; - /** @var IConfig */ - private $config; - /** @var IEventDispatcher */ - private $dispatcher; - /** @var IJobList */ - private $jobList; - /** @var SAMLSettings */ - private $settings; - - public function __construct( - IDBConnection $db, - IGroupManager $groupManager, - GroupBackend $ownGroupBackend, - IConfig $config, - IEventDispatcher $dispatcher, - IJobList $jobList, - SAMLSettings $settings, + protected IDBConnection $db, + private IGroupManager $groupManager, + private GroupBackend $ownGroupBackend, + private IConfig $config, + private IEventDispatcher $dispatcher, + private IJobList $jobList, + private SAMLSettings $settings, ) { - $this->db = $db; - $this->groupManager = $groupManager; - $this->ownGroupBackend = $ownGroupBackend; - $this->config = $config; - $this->dispatcher = $dispatcher; - $this->jobList = $jobList; - $this->settings = $settings; } /** @@ -70,7 +46,7 @@ public function __construct( private function getGroupsToRemove(array $samlGroupNames, array $assignedGroups): array { $groupsToRemove = []; foreach ($assignedGroups as $group) { - \OCP\Log\logger('user_saml')->debug('Checking group {group} for removal', ['group' => $group->getGID()]); + Server::get(LoggerInterface::class)->debug('Checking group {group} for removal', ['app' => 'user_saml', 'group' => $group->getGID()]); if (in_array($group->getGID(), $samlGroupNames, true)) { continue; } @@ -92,7 +68,7 @@ private function getGroupsToRemove(array $samlGroupNames, array $assignedGroups) private function getGroupsToAdd(array $samlGroupNames, array $assignedGroupIds): array { $groupsToAdd = []; foreach ($samlGroupNames as $groupName) { - \OCP\Log\logger('user_saml')->debug('Checking group {group} for addition', ['group' => $groupName]); + Server::get(LoggerInterface::class)->debug('Checking group {group} for addition', ['app' => 'user_saml', 'group' => $groupName]); $group = $this->groupManager->get($groupName); // if user is not assigned to the group or the provided group has a non SAML backend if (!in_array($groupName, $assignedGroupIds) || !$this->hasSamlBackend($group)) { @@ -298,9 +274,9 @@ protected function mayModifyGroup(?IGroup $group): bool { && $this->isGroupInTransitionList($group->getGID()); if ($isInTransition) { - \OCP\Log\logger('user_saml')->debug('Checking group {group} for foreign members', ['group' => $group->getGID()]); + Server::get(LoggerInterface::class)->debug('Checking group {group} for foreign members', ['app' => 'user_saml', 'group' => $group->getGID()]); $hasOnlySamlUsers = !$this->hasGroupForeignMembers($group); - \OCP\Log\logger('user_saml')->debug('Completed checking group {group} for foreign members', ['group' => $group->getGID()]); + Server::get(LoggerInterface::class)->debug('Completed checking group {group} for foreign members', ['app' => 'user_saml', 'group' => $group->getGID()]); if (!$hasOnlySamlUsers) { $this->updateCandidatePool([$group->getGID()]); } diff --git a/lib/Jobs/MigrateGroups.php b/lib/Jobs/MigrateGroups.php index 46923e2b7..b3c11f209 100644 --- a/lib/Jobs/MigrateGroups.php +++ b/lib/Jobs/MigrateGroups.php @@ -32,33 +32,16 @@ class MigrateGroups extends QueuedJob { protected const BATCH_SIZE = 1000; - /** @var IConfig */ - private $config; - /** @var IGroupManager */ - private $groupManager; - /** @var IDBConnection */ - private $dbc; - /** @var GroupBackend */ - private $ownGroupBackend; - /** @var LoggerInterface */ - private $logger; - public function __construct( protected GroupMigration $groupMigration, protected GroupManager $ownGroupManager, - IConfig $config, - IGroupManager $groupManager, - IDBConnection $dbc, - GroupBackend $ownGroupBackend, - LoggerInterface $logger, + private IConfig $config, + private IGroupManager $groupManager, + private IDBConnection $dbc, + private GroupBackend $ownGroupBackend, + private LoggerInterface $logger, ITimeFactory $timeFactory, ) { - parent::__construct($timeFactory); - $this->config = $config; - $this->groupManager = $groupManager; - $this->dbc = $dbc; - $this->ownGroupBackend = $ownGroupBackend; - $this->logger = $logger; } protected function run($argument) { diff --git a/lib/Middleware/OnlyLoggedInMiddleware.php b/lib/Middleware/OnlyLoggedInMiddleware.php index 5d46b73fa..715cd0665 100644 --- a/lib/Middleware/OnlyLoggedInMiddleware.php +++ b/lib/Middleware/OnlyLoggedInMiddleware.php @@ -19,21 +19,12 @@ * @package OCA\User_SAML\MiddleWare */ class OnlyLoggedInMiddleware extends Middleware { - /** @var IControllerMethodReflector */ - private $reflector; - /** @var IUserSession */ - private $userSession; - /** @var IURLGenerator */ - private $urlGenerator; public function __construct( - IControllerMethodReflector $reflector, - IUserSession $userSession, - IURLGenerator $urlGenerator, + private IControllerMethodReflector $reflector, + private IUserSession $userSession, + private IURLGenerator $urlGenerator, ) { - $this->reflector = $reflector; - $this->userSession = $userSession; - $this->urlGenerator = $urlGenerator; } /** diff --git a/lib/Migration/RememberLocalGroupsForPotentialMigrations.php b/lib/Migration/RememberLocalGroupsForPotentialMigrations.php index 9594eecb8..af751b197 100644 --- a/lib/Migration/RememberLocalGroupsForPotentialMigrations.php +++ b/lib/Migration/RememberLocalGroupsForPotentialMigrations.php @@ -18,17 +18,10 @@ class RememberLocalGroupsForPotentialMigrations implements IRepairStep { - /** @var IGroupManager */ - private $groupManager; - /** @var IConfig */ - private $config; - public function __construct( - IGroupManager $groupManager, - IConfig $config, + private IGroupManager $groupManager, + private IConfig $config, ) { - $this->groupManager = $groupManager; - $this->config = $config; } public function getName(): string { diff --git a/lib/SAMLSettings.php b/lib/SAMLSettings.php index d1063804e..9b96d4594 100644 --- a/lib/SAMLSettings.php +++ b/lib/SAMLSettings.php @@ -65,29 +65,17 @@ class SAMLSettings { public const DEFAULT_GROUP_PREFIX = 'SAML_'; - /** @var IURLGenerator */ - private $urlGenerator; - /** @var IConfig */ - private $config; - /** @var ISession */ - private $session; /** @var array> */ private $configurations = []; /** @var int */ private $configurationsLoadedState = self::LOADED_NONE; - /** @var ConfigurationsMapper */ - private $mapper; public function __construct( - IURLGenerator $urlGenerator, - IConfig $config, - ISession $session, - ConfigurationsMapper $mapper, + private IURLGenerator $urlGenerator, + private IConfig $config, + private ISession $session, + private ConfigurationsMapper $mapper, ) { - $this->urlGenerator = $urlGenerator; - $this->config = $config; - $this->session = $session; - $this->mapper = $mapper; } /** @@ -132,7 +120,7 @@ public function getOneLoginSettingsArray(int $idp): array { $settings = [ 'strict' => true, - 'debug' => $this->config->getSystemValue('debug', false), + 'debug' => $this->config->getSystemValueBool('debug', false), 'baseurl' => $this->urlGenerator->linkToRouteAbsolute('user_saml.SAML.base'), 'security' => [ 'nameIdEncrypted' => ($this->configurations[$idp]['security-nameIdEncrypted'] ?? '0') === '1', diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 051c3ebe4..93138ea59 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -15,25 +15,13 @@ use OneLogin\Saml2\Constants; class Admin implements ISettings { - /** @var IL10N */ - private $l10n; - /** @var Defaults */ - private $defaults; - /** @var IConfig */ - private $config; - /** @var SAMLSettings */ - private $samlSettings; public function __construct( - IL10N $l10n, - Defaults $defaults, - IConfig $config, - SAMLSettings $samlSettings, + private IL10N $l10n, + private Defaults $defaults, + private IConfig $config, + private SAMLSettings $samlSettings, ) { - $this->l10n = $l10n; - $this->defaults = $defaults; - $this->config = $config; - $this->samlSettings = $samlSettings; } /** diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index 1b194a738..99ee4a59d 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -11,19 +11,11 @@ use OCP\Settings\IIconSection; class Section implements IIconSection { - /** @var IL10N */ - private $l; - /** @var IURLGenerator */ - private $url; - /** - * @param IL10N $l - * @param IURLGenerator $url - */ - public function __construct(IL10N $l, - IURLGenerator $url) { - $this->l = $l; - $this->url = $url; + public function __construct( + private IL10N $l, + private IURLGenerator $url, + ) { } /** diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 015ce5960..d997ba8b9 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -29,51 +29,21 @@ use Psr\Log\LoggerInterface; class UserBackend extends ABackend implements IApacheBackend, IUserBackend, IGetDisplayNameBackend, ICountUsersBackend, IGetHomeBackend { - /** @var IConfig */ - private $config; - /** @var IURLGenerator */ - private $urlGenerator; - /** @var ISession */ - private $session; - /** @var IDBConnection */ - private $db; - /** @var IUserManager */ - private $userManager; - /** @var GroupManager */ - private $groupManager; /** @var \OCP\UserInterface[] */ private static $backends = []; - /** @var SAMLSettings */ - private $settings; - /** @var LoggerInterface */ - private $logger; - /** @var UserData */ - private $userData; - /** @var IEventDispatcher */ - private $eventDispatcher; public function __construct( - IConfig $config, - IURLGenerator $urlGenerator, - ISession $session, - IDBConnection $db, - IUserManager $userManager, - GroupManager $groupManager, - SAMLSettings $settings, - LoggerInterface $logger, - UserData $userData, - IEventDispatcher $eventDispatcher, + private IConfig $config, + private IURLGenerator $urlGenerator, + private ISession $session, + private IDBConnection $db, + private IUserManager $userManager, + private GroupManager $groupManager, + private SAMLSettings $settings, + private LoggerInterface $logger, + private UserData $userData, + private IEventDispatcher $eventDispatcher, ) { - $this->config = $config; - $this->urlGenerator = $urlGenerator; - $this->session = $session; - $this->db = $db; - $this->userManager = $userManager; - $this->groupManager = $groupManager; - $this->settings = $settings; - $this->logger = $logger; - $this->userData = $userData; - $this->eventDispatcher = $eventDispatcher; } /** @@ -88,7 +58,7 @@ protected function userExistsInDatabase(string $uid): bool { ->from('user_saml_users') ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) ->setMaxResults(1); - $result = $qb->execute(); + $result = $qb->executeQuery(); $users = $result->fetchAll(); $result->closeCursor(); @@ -122,7 +92,7 @@ public function createUserIfNotExists(string $uid, array $attributes = []): void && !(strlen($home) > 3 && ctype_alpha($home[0]) && $home[1] === ':' && ($home[2] === '\\' || $home[2] === '/')) ) { - $home = $this->config->getSystemValue('datadirectory', + $home = $this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $home; } @@ -134,7 +104,7 @@ public function createUserIfNotExists(string $uid, array $attributes = []): void foreach ($values as $column => $value) { $qb->setValue($column, $qb->createNamedParameter($value)); } - $qb->execute(); + $qb->executeStatement(); $this->initializeHomeDir($uid); } @@ -294,7 +264,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) { ->setMaxResults($limit) ->setFirstResult($offset); - $result = $query->execute(); + $result = $query->executeQuery(); $displayNames = []; while ($row = $result->fetch()) { $displayNames[(string)$row['uid']] = (string)$row['displayname']; @@ -617,7 +587,7 @@ public function countUsers() { $query = $this->db->getQueryBuilder(); $query->select($query->func()->count('uid')) ->from('user_saml_users'); - $result = $query->execute(); + $result = $query->executeQuery(); return $result->fetchColumn(); } diff --git a/lib/UserData.php b/lib/UserData.php index dcc190553..13f15c5b4 100644 --- a/lib/UserData.php +++ b/lib/UserData.php @@ -14,14 +14,11 @@ class UserData { private $uid; /** @var array */ private $attributes; - /** @var UserResolver */ - private $userResolver; - /** @var SAMLSettings */ - private $samlSettings; - - public function __construct(UserResolver $userResolver, SAMLSettings $samlSettings) { - $this->userResolver = $userResolver; - $this->samlSettings = $samlSettings; + + public function __construct( + private UserResolver $userResolver, + private SAMLSettings $samlSettings, + ) { } public function setAttributes(array $attributes): void {