diff --git a/module/VuFind/src/VuFind/Auth/ILS.php b/module/VuFind/src/VuFind/Auth/ILS.php index 6c90a281d65089843fb7172b19ff14accdf20398..cec73bffa180d62ecca611ce10d77e988c4bbdae 100644 --- a/module/VuFind/src/VuFind/Auth/ILS.php +++ b/module/VuFind/src/VuFind/Auth/ILS.php @@ -140,7 +140,7 @@ class ILS extends AbstractBase try { return false !== $this->getCatalog()->checkFunction( 'changePassword', - ['patron' => $this->getLoggedInPatron()] + ['patron' => $this->authenticator->getStoredCatalogCredentials()] ); } catch (ILSException $e) { return false; @@ -273,7 +273,7 @@ class ILS extends AbstractBase * * @throws AuthException * - * @return array Patron + * @return array|null Patron or null if no credentials exist */ protected function getLoggedInPatron() { diff --git a/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php b/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php index ef26a071d3512b6832e35181bb4ec6aa55c7e017..a6109d1cede3c97e8c73639bce76e2f6c00a849a 100644 --- a/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php +++ b/module/VuFind/src/VuFind/Auth/ILSAuthenticator.php @@ -72,6 +72,28 @@ class ILSAuthenticator $this->catalog = $catalog; } + /** + * Get stored catalog credentials for the current user. + * + * Returns associative array of cat_username and cat_password if they are + * available, false otherwise. This method does not verify that the credentials + * are valid. + * + * @return array|bool + */ + public function getStoredCatalogCredentials() + { + // Fail if no username is found, but allow a missing password (not every ILS + // requires a password to connect). + if (($user = $this->auth->isLoggedIn()) && !empty($user->cat_username)) { + return [ + 'cat_username' => $user->cat_username, + 'cat_password' => $user->cat_password + ]; + } + return false; + } + /** * Log the current user into the catalog using stored credentials; if this * fails, clear the user's stored credentials so they can enter new, corrected @@ -85,9 +107,7 @@ class ILSAuthenticator { // Fail if no username is found, but allow a missing password (not every ILS // requires a password to connect). - if (($user = $this->auth->isLoggedIn()) - && isset($user->cat_username) && !empty($user->cat_username) - ) { + if (($user = $this->auth->isLoggedIn()) && !empty($user->cat_username)) { // Do we have a previously cached ILS account? if (isset($this->ilsAccount[$user->cat_username])) { return $this->ilsAccount[$user->cat_username]; diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index 5dd56520f21f3b0f5a4e4424881b1bfb66e5ccd6..de118570516fa9a6a8340d5b011b5b14e31148a9 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -1178,7 +1178,7 @@ class MultiBackend extends AbstractBase } if (!$source) { try { - $patron = $this->ilsAuth->storedCatalogLogin(); + $patron = $this->ilsAuth->getStoredCatalogCredentials(); if ($patron && isset($patron['cat_username'])) { $source = $this->getSource($patron['cat_username']); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php index ff03cb55c522430877a4707d77bb9d5807719fc3..d76649dc19a19c94f43edd53e09f69ff9b161db6 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php @@ -2321,6 +2321,11 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ->will( $this->returnValue($this->getPatron('username', $userSource)) ); + $mockAuth->expects($this->any()) + ->method('getStoredCatalogCredentials') + ->will( + $this->returnValue($this->getPatron('username', $userSource)) + ); } return $mockAuth; }