diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index aeeda81263609ddcc25e3246752af3b290a3fd5c..904f72b88e6e6662796a51100d72135bf6d99b49 100644 --- a/module/VuFind/src/VuFind/Auth/AbstractBase.php +++ b/module/VuFind/src/VuFind/Auth/AbstractBase.php @@ -28,7 +28,9 @@ */ namespace VuFind\Auth; use VuFind\Config\Reader as ConfigReader, - VuFind\Exception\Auth as AuthException; + VuFind\Exception\Auth as AuthException, + Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Abstract authentication base class @@ -40,7 +42,7 @@ use VuFind\Config\Reader as ConfigReader, * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -abstract class AbstractBase +abstract class AbstractBase implements ServiceLocatorAwareInterface { protected $configValidated = false; protected $config = null; @@ -169,4 +171,37 @@ abstract class AbstractBase // By default, account creation is not supported. return false; } + + /** + * Get access to the user table. + * + * @return \VuFind\Db\Table\User + */ + public function getUserTable() + { + return new \VuFind\Db\Table\User(); + } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return AbstractBase + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Auth/Database.php b/module/VuFind/src/VuFind/Auth/Database.php index c1f4b57fc180fd3e741343d3dab968b1cf8baea9..14293e7618e44803a336593e5121f8fcf9bfcef6 100644 --- a/module/VuFind/src/VuFind/Auth/Database.php +++ b/module/VuFind/src/VuFind/Auth/Database.php @@ -28,7 +28,7 @@ * @link http://vufind.org/wiki/building_an_authentication_handler Wiki */ namespace VuFind\Auth; -use VuFind\Db\Table\User as UserTable, VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * Database authentication class @@ -65,8 +65,7 @@ class Database extends AbstractBase } // Validate the credentials: - $table = new UserTable(); - $user = $table->getByUsername($this->username, false); + $user = $this->getUserTable()->getByUsername($this->username, false); if (!is_object($user) || !$user->checkPassword($this->password)) { throw new AuthException('authentication_error_invalid'); } @@ -116,7 +115,7 @@ class Database extends AbstractBase } // Make sure we have a unique username - $table = new UserTable(); + $table = $this->getUserTable(); if ($table->getByUsername($params['username'], false)) { throw new AuthException('That username is already taken'); } diff --git a/module/VuFind/src/VuFind/Auth/ILS.php b/module/VuFind/src/VuFind/Auth/ILS.php index 68b3e98aa0bb3f7f0266391e06c4c7a5f1ad6201..4df3e73d00a8f70a137fd51236748edc4b1e5b0b 100644 --- a/module/VuFind/src/VuFind/Auth/ILS.php +++ b/module/VuFind/src/VuFind/Auth/ILS.php @@ -28,7 +28,7 @@ */ namespace VuFind\Auth; use VuFind\Connection\Manager as ConnectionManager, - VuFind\Db\Table\User as UserTable, VuFind\Exception\Auth as AuthException; + VuFind\Exception\Auth as AuthException; /** * ILS authentication module. @@ -123,8 +123,7 @@ class ILS extends AbstractBase } // Check to see if we already have an account for this user: - $table = new UserTable(); - $user = $table->getByUsername($info[$usernameField]); + $user = $this->getUserTable()->getByUsername($info[$usernameField]); // No need to store the ILS password in VuFind's main password field: $user->password = ""; diff --git a/module/VuFind/src/VuFind/Auth/LDAP.php b/module/VuFind/src/VuFind/Auth/LDAP.php index b730af25dfafab3b56a07cff683354aed81ade1a..33a9b729e68758fc24ec39b785fdb4ccc4d23c44 100644 --- a/module/VuFind/src/VuFind/Auth/LDAP.php +++ b/module/VuFind/src/VuFind/Auth/LDAP.php @@ -27,7 +27,7 @@ * @link http://vufind.org/wiki/building_an_authentication_handler Wiki */ namespace VuFind\Auth; -use VuFind\Db\Table\User as UserTable, VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * LDAP authentication class @@ -194,8 +194,7 @@ class LDAP extends AbstractBase ); // User object to populate from LDAP: - $table = new UserTable(); - $user = $table->getByUsername($this->username); + $user = $this->getUserTable()->getByUsername($this->username); // Loop through LDAP response and map fields to database object based // on configuration settings: diff --git a/module/VuFind/src/VuFind/Auth/SIP2.php b/module/VuFind/src/VuFind/Auth/SIP2.php index 9f520c4960c1bc558e6cd1605595f0fb6e1b74c8..36a761c23c18183c7f57f51cc9b906311fefabce 100644 --- a/module/VuFind/src/VuFind/Auth/SIP2.php +++ b/module/VuFind/src/VuFind/Auth/SIP2.php @@ -27,7 +27,7 @@ * @link http://vufind.org/wiki/building_an_authentication_handler Wiki */ namespace VuFind\Auth; -use VuFind\Db\Table\User as UserTable, VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * SIP2 authentication module. @@ -128,8 +128,7 @@ class SIP2 extends AbstractBase */ protected function processSIP2User($info, $username, $password) { - $table = new UserTable(); - $user = $table->getByUsername($info['variable']['AA'][0]); + $user = $this->getUserTable()->getByUsername($info['variable']['AA'][0]); // This could potentially be different depending on the ILS. Name could be // Bob Wicksall or Wicksall, Bob. This is currently assuming Wicksall, Bob diff --git a/module/VuFind/src/VuFind/Auth/Shibboleth.php b/module/VuFind/src/VuFind/Auth/Shibboleth.php index aee35e1e4baee3d449d5680f9224d6e3b77a021a..4df21a651764672f8ccc739d241e8d52ee6f7d87 100644 --- a/module/VuFind/src/VuFind/Auth/Shibboleth.php +++ b/module/VuFind/src/VuFind/Auth/Shibboleth.php @@ -27,7 +27,7 @@ * @link http://www.vufind.org Main Page */ namespace VuFind\Auth; -use VuFind\Db\Table\User as UserTable, VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * Shibboleth authentication module. @@ -92,8 +92,7 @@ class Shibboleth extends AbstractBase } // If we made it this far, we should log in the user! - $table = new UserTable(); - $user = $table->getByUsername($username); + $user = $this->getUserTable()->getByUsername($username); // Has the user configured attributes to use for populating the user table? $attribsToCheck = array(