diff --git a/module/VuFind/src/VuFind/Auth/EmailAuthenticator.php b/module/VuFind/src/VuFind/Auth/EmailAuthenticator.php index 5a313a0cdbdf..006b8a1f896e 100644 --- a/module/VuFind/src/VuFind/Auth/EmailAuthenticator.php +++ b/module/VuFind/src/VuFind/Auth/EmailAuthenticator.php @@ -70,7 +70,7 @@ class EmailAuthenticator implements \VuFind\I18n\Translator\TranslatorAwareInter * @param \VuFind\Mailer\Mailer $mailer Mailer * @param PhpRenderer $viewRenderer View Renderer * @param UserIpReader $userIpReader User IP address reader - * @param \VuFind\Config\Config $config Configuration + * @param array $config Configuration * @param AuthHashServiceInterface $authHashService AuthHash database service */ public function __construct( @@ -79,7 +79,7 @@ public function __construct( protected \VuFind\Mailer\Mailer $mailer, protected PhpRenderer $viewRenderer, protected UserIpReader $userIpReader, - protected \VuFind\Config\Config $config, + protected array $config, protected AuthHashServiceInterface $authHashService ) { } @@ -113,7 +113,7 @@ public function sendAuthenticationLink( $templateParams = [] ) { // Make sure we've waited long enough - $recoveryInterval = $this->config->Authentication->recover_interval ?? 60; + $recoveryInterval = $this->config['Authentication']['recover_interval'] ?? 60; $sessionId = $this->sessionManager->getId(); if ( @@ -145,7 +145,7 @@ public function sendAuthenticationLink( $viewParams['url'] = $serverHelper( $urlHelper($linkRoute, $routeParams, ['query' => $urlParams]) ); - $viewParams['title'] = $this->config->Site->title; + $viewParams['title'] = $this->config['Site']['title'] ?? ''; $message = $this->viewRenderer->render($template, $viewParams); $from = $this->getEmailSenderAddress($this->config, $email); @@ -236,7 +236,7 @@ public function sendAuthenticationCode( $templateParams = [] ): int { // Make sure we've waited long enough - $recoveryInterval = $this->config->Authentication->recover_interval ?? 60; + $recoveryInterval = $this->config['Authentication']['recover_interval'] ?? 60; $sessionId = $this->sessionManager->getId(); if ( @@ -260,7 +260,7 @@ public function sendAuthenticationCode( $viewParams = $templateParams; $viewParams['code'] = $otp; - $viewParams['title'] = $this->config->Site->title ?? ''; + $viewParams['title'] = $this->config['Site']['title'] ?? ''; $message = $this->viewRenderer->render($template, $viewParams); $from = $this->getEmailSenderAddress($this->config, $email); @@ -310,7 +310,7 @@ public function verifyAuthenticationCode( throw $e; } // Check the maximum attempt limit: - $maxAttempts = max($this->config->Authentication->otp_max_attempts ?? 3, 1); + $maxAttempts = max($this->config['Authentication']['otp_max_attempts'] ?? 3, 1); if ($attempts > $maxAttempts) { throw new AuthException('authentication_error_expired'); } diff --git a/module/VuFind/src/VuFind/Auth/EmailAuthenticatorFactory.php b/module/VuFind/src/VuFind/Auth/EmailAuthenticatorFactory.php index e61276f392d7..d73865ec7bb5 100644 --- a/module/VuFind/src/VuFind/Auth/EmailAuthenticatorFactory.php +++ b/module/VuFind/src/VuFind/Auth/EmailAuthenticatorFactory.php @@ -73,7 +73,7 @@ public function __invoke( $container->get(\VuFind\Mailer\Mailer::class), $container->get('ViewRenderer'), $container->get(\VuFind\Net\UserIpReader::class), - $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigObject('config'), + $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigArray('config'), $container->get(\VuFind\Db\Service\PluginManager::class) ->get(\VuFind\Db\Service\AuthHashServiceInterface::class) ); diff --git a/module/VuFind/src/VuFind/Auth/LoginTokenManager.php b/module/VuFind/src/VuFind/Auth/LoginTokenManager.php index 379cd94120f3..c6d23085c3c6 100644 --- a/module/VuFind/src/VuFind/Auth/LoginTokenManager.php +++ b/module/VuFind/src/VuFind/Auth/LoginTokenManager.php @@ -36,7 +36,6 @@ use Laminas\Session\SessionManager; use Laminas\View\Renderer\RendererInterface; use Psr\Log\LoggerAwareInterface; -use VuFind\Config\Config; use VuFind\Config\Feature\EmailSettingsTrait; use VuFind\Cookie\CookieManager; use VuFind\Db\Entity\UserEntityInterface; @@ -104,7 +103,7 @@ class LoginTokenManager implements LoggerAwareInterface, TranslatorAwareInterfac /** * LoginToken constructor. * - * @param Config $config Configuration + * @param array $config Configuration * @param UserServiceInterface $userService User database service * @param LoginTokenServiceInterface $loginTokenService Login Token database service * @param CookieManager $cookieManager Cookie manager @@ -114,7 +113,7 @@ class LoginTokenManager implements LoggerAwareInterface, TranslatorAwareInterfac * @param callable $browscapCB Callback for creating Browscap */ public function __construct( - protected Config $config, + protected array $config, protected UserServiceInterface $userService, protected LoginTokenServiceInterface $loginTokenService, protected CookieManager $cookieManager, @@ -273,7 +272,7 @@ public function deleteUserLoginTokens($userId) */ public function getCookieLifetime(): int { - return (int)($this->config->Authentication->persistent_login_lifetime ?? 14); + return (int)($this->config['Authentication']['persistent_login_lifetime'] ?? 14); } /** @@ -332,7 +331,7 @@ protected function createOrRotateToken( $userId = $user->getId(); try { if ($series) { - $lenient = ($this->config->Authentication->lenient_token_rotation ?? true); + $lenient = ($this->config['Authentication']['lenient_token_rotation'] ?? true); $this->loginTokenService->deleteBySeries($series, $lenient ? $currentTokenId : null); $this->debug("Updating login token $token series $series for user {$userId}"); } else { @@ -364,16 +363,16 @@ protected function createOrRotateToken( */ protected function sendLoginTokenWarningEmail(UserEntityInterface $user) { - if (!($this->config->Authentication->send_login_warnings ?? true)) { + if (!($this->config['Authentication']['send_login_warnings'] ?? true)) { return; } - $title = $this->config->Site->title ?? ''; + $title = $this->config['Site']['title'] ?? ''; if ($toAddr = $user->getEmail()) { $message = $this->viewRenderer->render( 'Email/login-warning.phtml', compact('title') ); - $subject = $this->config->Authentication->persistent_login_warning_email_subject + $subject = $this->config['Authentication']['persistent_login_warning_email_subject'] ?? 'persistent_login_warning_email_subject'; try { diff --git a/module/VuFind/src/VuFind/Auth/LoginTokenManagerFactory.php b/module/VuFind/src/VuFind/Auth/LoginTokenManagerFactory.php index 54e2f1fcd8f2..3c01f2b2d231 100644 --- a/module/VuFind/src/VuFind/Auth/LoginTokenManagerFactory.php +++ b/module/VuFind/src/VuFind/Auth/LoginTokenManagerFactory.php @@ -82,7 +82,7 @@ public function __invoke( $dbServiceManager = $container->get(\VuFind\Db\Service\PluginManager::class); return new $requestedName( - $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigObject('config'), + $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigArray('config'), $dbServiceManager->get(UserServiceInterface::class), $dbServiceManager->get(LoginTokenServiceInterface::class), $container->get(\VuFind\Cookie\CookieManager::class), diff --git a/module/VuFind/src/VuFind/Auth/Manager.php b/module/VuFind/src/VuFind/Auth/Manager.php index 12909e4bbc2b..87e61b2e6359 100644 --- a/module/VuFind/src/VuFind/Auth/Manager.php +++ b/module/VuFind/src/VuFind/Auth/Manager.php @@ -121,7 +121,7 @@ class Manager implements IdentityProviderInterface, LoggerAwareInterface /** * Constructor. * - * @param Config $config VuFind configuration + * @param array $config VuFind configuration * @param UserServiceInterface $userService User database service * @param UserSessionPersistenceInterface $userSession User session persistence service * @param SessionManager $sessionManager Session manager @@ -134,7 +134,7 @@ class Manager implements IdentityProviderInterface, LoggerAwareInterface * @param AuditEventServiceInterface $auditEventService Event database service */ public function __construct( - protected Config $config, + protected array $config, protected UserServiceInterface $userService, protected UserSessionPersistenceInterface $userSession, protected SessionManager $sessionManager, @@ -148,7 +148,7 @@ public function __construct( ) { // Initialize active authentication setting (defaulting to Database // if no setting passed in): - $method = $this->getPreAuthenticationData()['authMethod'] ?? $config->Authentication->method ?? 'Database'; + $method = $this->getPreAuthenticationData()['authMethod'] ?? $config['Authentication']['method'] ?? 'Database'; // Set the active authentication method and force it legal: $this->setAuthMethod($method, true); } @@ -204,7 +204,7 @@ protected function makeAuth(string $method): AuthInterface throw new \Exception("Illegal authentication method: $method"); } $auth = $this->pluginManager->get($method); - $auth->setConfig($this->config); + $auth->setConfig(new Config($this->config)); return $auth; } @@ -231,7 +231,7 @@ public function supportsCreation(?string $authMethod = null): bool */ public function supportsRecovery(?string $authMethod = null, ?string $target = null): bool { - return ($this->config->Authentication->recover_password ?? false) + return ($this->config['Authentication']['recover_password'] ?? false) && $this->getAuth($authMethod)->supportsPasswordRecovery($target); } @@ -269,7 +269,7 @@ public function getPasswordRecoveryData(array $params): ?array */ public function supportsEmailChange(?string $authMethod = null): bool { - return $this->config->Authentication->change_email ?? false; + return $this->config['Authentication']['change_email'] ?? false; } /** @@ -282,7 +282,7 @@ public function supportsEmailChange(?string $authMethod = null): bool */ public function supportsPasswordChange(?string $authMethod = null): bool { - return ($this->config->Authentication->change_password ?? false) + return ($this->config['Authentication']['change_password'] ?? false) && $this->getAuth($authMethod)->supportsPasswordChange(); } @@ -296,7 +296,7 @@ public function supportsPasswordChange(?string $authMethod = null): bool */ public function supportsConnectingLibraryCard(?string $authMethod = null): bool { - return ($this->config->Catalog->auth_based_library_cards ?? false) + return ($this->config['Catalog']['auth_based_library_cards'] ?? false) && $this->getAuth($authMethod)->supportsConnectingLibraryCard(); } @@ -309,10 +309,10 @@ public function supportsConnectingLibraryCard(?string $authMethod = null): bool */ public function supportsPersistentLogin(?string $authMethod = null): bool { - if (!empty($this->config->Authentication->persistent_login)) { + if (!empty($this->config['Authentication']['persistent_login'])) { return in_array( strtolower($authMethod ?? $this->getSelectedAuthMethod() ?? ''), - explode(',', strtolower($this->config->Authentication->persistent_login)) + explode(',', strtolower($this->config['Authentication']['persistent_login'])) ); } return false; @@ -325,7 +325,7 @@ public function supportsPersistentLogin(?string $authMethod = null): bool */ public function getPersistentLoginLifetime(): int { - return $this->config->Authentication->persistent_login_lifetime ?? 14; + return $this->config['Authentication']['persistent_login_lifetime'] ?? 14; } /** @@ -516,7 +516,7 @@ public function loginEnabled(): bool { if (null === $this->hideLogin) { // Assume login is enabled unless explicitly turned off: - $this->hideLogin = ($this->config->Authentication->hideLogin ?? false); + $this->hideLogin = ($this->config['Authentication']['hideLogin'] ?? false); if (!$this->hideLogin) { try { @@ -544,7 +544,7 @@ public function loginEnabled(): bool public function ajaxEnabled(): bool { // Assume ajax is enabled unless explicitly turned off: - return $this->config->Authentication->enableAjax ?? true; + return $this->config['Authentication']['enableAjax'] ?? true; } /** @@ -555,7 +555,7 @@ public function ajaxEnabled(): bool public function dropdownEnabled(): bool { // Assume dropdown is disabled unless explicitly turned on: - return $this->config->Authentication->enableDropdown ?? false; + return $this->config['Authentication']['enableDropdown'] ?? false; } /** @@ -740,7 +740,7 @@ public function checkForExpiredCredentials(): bool */ public function inPrivacyMode(): bool { - return $this->config->Authentication->privacy ?? false; + return $this->config['Authentication']['privacy'] ?? false; } /** @@ -838,7 +838,7 @@ public function updateEmail(UserEntityInterface $user, string $email): void { // Depending on verification setting, either do a direct update or else // put the new address into a pending state. - if ($this->config->Authentication->verify_email ?? false) { + if ($this->config['Authentication']['verify_email'] ?? false) { // If new email address is the current address, just reset any pending // email address: $user->setPendingEmail($email === $user->getEmail() ? '' : $email); @@ -996,7 +996,7 @@ public function login(Request $request): ?UserEntityInterface // Attempt catalog login so that any bad credentials are cleared before further processing // (avoids e.g. multiple login attempts by account AJAX checks). if ( - ($this->config->Catalog->checkILSCredentialsOnLogin ?? true) + ($this->config['Catalog']['checkILSCredentialsOnLogin'] ?? true) && $this->ilsAuthenticator && $this->allowsUserIlsLogin() && ($catUsername = $user->getCatUsername()) @@ -1225,7 +1225,7 @@ protected function updateUser(UserEntityInterface $user, ?string $authMethod): v */ public function allowsUserIlsLogin(): bool { - return $this->config->Catalog->allowUserLogin ?? true; + return $this->config['Catalog']['allowUserLogin'] ?? true; } /** diff --git a/module/VuFind/src/VuFind/Auth/ManagerFactory.php b/module/VuFind/src/VuFind/Auth/ManagerFactory.php index 6227f40b23f9..1954fd381ac9 100644 --- a/module/VuFind/src/VuFind/Auth/ManagerFactory.php +++ b/module/VuFind/src/VuFind/Auth/ManagerFactory.php @@ -69,7 +69,7 @@ public function __invoke( throw new \Exception('Unexpected options passed to factory.'); } // Load dependencies: - $config = $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigObject('config'); + $config = $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigArray('config'); $dbServiceManager = $container->get(\VuFind\Db\Service\PluginManager::class); $userService = $dbServiceManager->get(\VuFind\Db\Service\UserServiceInterface::class); $sessionManager = $container->get(\Laminas\Session\SessionManager::class); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/EmailAuthenticatorTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/EmailAuthenticatorTest.php index 25fe078ee537..3ad5b4cb76a9 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/EmailAuthenticatorTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/EmailAuthenticatorTest.php @@ -37,7 +37,6 @@ use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\Exception; use VuFind\Auth\EmailAuthenticator; -use VuFind\Config\Config; use VuFind\Db\Entity\AuthHashEntityInterface; use VuFind\Db\Service\AuthHashServiceInterface; use VuFind\Mailer\Mailer; @@ -89,7 +88,7 @@ protected function getEmailAuthenticator( $mailer ?? $this->createStub(Mailer::class), $renderer ?? $this->createStub(PhpRenderer::class), $userIpReader ?? $this->createStub(UserIpReader::class), - new Config($config), + $config, $authHashService ?? $this->createStub(AuthHashServiceInterface::class) ); $authenticator->setTranslator($this->getMockTranslator([])); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/LoginTokenManagerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/LoginTokenManagerTest.php index c4951dbd7777..0f3cf2f9cda1 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/LoginTokenManagerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/LoginTokenManagerTest.php @@ -35,7 +35,6 @@ use Laminas\Session\SessionManager; use PHPUnit\Framework\MockObject\MockObject; use VuFind\Auth\LoginTokenManager; -use VuFind\Config\Config; use VuFind\Cookie\CookieManager; use VuFind\Db\Entity\LoginTokenEntityInterface; use VuFind\Db\Entity\UserEntityInterface; @@ -193,7 +192,7 @@ protected function getCookieManager(array $cookies): CookieManager */ protected function getLoginToken($cookieManager, $tokenTable, $userTable, $browscapOk) { - $config = new Config([]); + $config = []; $saveHandler = $this->createMock(SaveHandlerInterface::class); $sessionManager = $this->createMock(SessionManager::class); $sessionManager->method('getSaveHandler')->willReturn($saveHandler); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php index 515ea460cad1..ea8ade83009a 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php @@ -35,7 +35,6 @@ use VuFind\Auth\Manager; use VuFind\Auth\PluginManager; use VuFind\Auth\UserSessionPersistenceInterface; -use VuFind\Config\Config; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Db\Service\UserServiceInterface; @@ -561,7 +560,6 @@ protected function getManager( ?SessionManager $sessionManager = null, ?PluginManager $pm = null ): Manager { - $config = new Config($config); $cookies = new \VuFind\Cookie\CookieManager([]); $csrf = new \VuFind\Validator\SessionCsrf( [