diff --git a/module/VuFind/src/VuFind/Auth/ChoiceAuthFactory.php b/module/VuFind/src/VuFind/Auth/ChoiceAuthFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..4a298a13e6e5aa27c5d20ff51f52b01b6da42563 --- /dev/null +++ b/module/VuFind/src/VuFind/Auth/ChoiceAuthFactory.php @@ -0,0 +1,70 @@ +<?php +/** + * Factory for ChoiceAuth authentication module. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Auth; + +use Interop\Container\ContainerInterface; + +/** + * Factory for ChoiceAuth authentication module. + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ChoiceAuthFactory implements \Zend\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + $session = new \Zend\Session\Container( + 'ChoiceAuth', $container->get(\Zend\Session\SessionManager::class) + ); + $auth = new $requestedName($session); + $auth->setPluginManager($container->get(PluginManager::class)); + return $auth; + } +} diff --git a/module/VuFind/src/VuFind/Auth/FacebookFactory.php b/module/VuFind/src/VuFind/Auth/FacebookFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..29426d0226c49a6f9289be47d76e40d2af77c233 --- /dev/null +++ b/module/VuFind/src/VuFind/Auth/FacebookFactory.php @@ -0,0 +1,68 @@ +<?php +/** + * Factory for Facebook authentication module. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Auth; + +use Interop\Container\ContainerInterface; + +/** + * Factory for Facebook authentication module. + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class FacebookFactory implements \Zend\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + $session = new \Zend\Session\Container( + 'Facebook', $container->get(\Zend\Session\SessionManager::class) + ); + return new $requestedName($session); + } +} diff --git a/module/VuFind/src/VuFind/Auth/Factory.php b/module/VuFind/src/VuFind/Auth/Factory.php deleted file mode 100644 index e7c773b7ca76fb057a9d6bdbdf819961c8346003..0000000000000000000000000000000000000000 --- a/module/VuFind/src/VuFind/Auth/Factory.php +++ /dev/null @@ -1,149 +0,0 @@ -<?php -/** - * Factory for authentication services. - * - * PHP version 7 - * - * Copyright (C) Villanova University 2014. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * @category VuFind - * @package Authentication - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org/wiki/development Wiki - */ -namespace VuFind\Auth; - -use Zend\ServiceManager\ServiceManager; - -/** - * Factory for authentication services. - * - * @category VuFind - * @package Authentication - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org/wiki/development Wiki - * - * @codeCoverageIgnore - */ -class Factory -{ - /** - * Construct the ChoiceAuth plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return ChoiceAuth - */ - public static function getChoiceAuth(ServiceManager $sm) - { - $container = new \Zend\Session\Container( - 'ChoiceAuth', $sm->get('Zend\Session\SessionManager') - ); - $auth = new ChoiceAuth($container); - $auth->setPluginManager($sm->get('VuFind\Auth\PluginManager')); - return $auth; - } - - /** - * Construct the Facebook plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return Facebook - */ - public static function getFacebook(ServiceManager $sm) - { - $container = new \Zend\Session\Container( - 'Facebook', $sm->get('Zend\Session\SessionManager') - ); - return new Facebook($container); - } - - /** - * Construct the ILS plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return ILS - */ - public static function getILS(ServiceManager $sm) - { - return new ILS( - $sm->get('VuFind\ILS\Connection'), - $sm->get('VuFind\Auth\ILSAuthenticator') - ); - } - - /** - * Construct the MultiAuth plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return MultiAuth - */ - public static function getMultiAuth(ServiceManager $sm) - { - $auth = new MultiAuth(); - $auth->setPluginManager($sm->get('VuFind\Auth\PluginManager')); - return $auth; - } - - /** - * Construct the MultiILS plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return MultiILS - */ - public static function getMultiILS(ServiceManager $sm) - { - return new MultiILS( - $sm->get('VuFind\ILS\Connection'), - $sm->get('VuFind\Auth\ILSAuthenticator') - ); - } - - /** - * Construct the Shibboleth plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return Shibboleth - */ - public static function getShibboleth(ServiceManager $sm) - { - return new Shibboleth( - $sm->get('Zend\Session\SessionManager') - ); - } - - /** - * Construct the AlmaDatabase plugin. - * - * @param ServiceManager $sm Service manager. - * - * @return AlmaDatabase - */ - public static function getAlmaDatabase(ServiceManager $sm) - { - return new AlmaDatabase( - $sm->get('VuFind\ILS\Connection'), - $sm->get('VuFind\Auth\ILSAuthenticator') - ); - } -} diff --git a/module/VuFind/src/VuFind/Auth/ILSFactory.php b/module/VuFind/src/VuFind/Auth/ILSFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..2c6972dc742decd2ada7e9997c67a01f8b488ecf --- /dev/null +++ b/module/VuFind/src/VuFind/Auth/ILSFactory.php @@ -0,0 +1,68 @@ +<?php +/** + * Factory for ILS authentication module (and others with equivalent constructors). + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Auth; + +use Interop\Container\ContainerInterface; + +/** + * Factory for ILS authentication module (and others with equivalent constructors). + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class IlsFactory implements \Zend\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + return new $requestedName( + $container->get(\VuFind\ILS\Connection::class), + $container->get(ILSAuthenticator::class) + ); + } +} diff --git a/module/VuFind/src/VuFind/Auth/MultiAuthFactory.php b/module/VuFind/src/VuFind/Auth/MultiAuthFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..45886fe49947c9b2ae9691e4c47a7e26e748d4b3 --- /dev/null +++ b/module/VuFind/src/VuFind/Auth/MultiAuthFactory.php @@ -0,0 +1,67 @@ +<?php +/** + * Factory for MultiAuth authentication module. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Auth; + +use Interop\Container\ContainerInterface; + +/** + * Factory for MultiAuth authentication module. + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class MultiAuthFactory implements \Zend\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + $auth = new $requestedName(); + $auth->setPluginManager($container->get(PluginManager::class)); + return $auth; + } +} diff --git a/module/VuFind/src/VuFind/Auth/PluginManager.php b/module/VuFind/src/VuFind/Auth/PluginManager.php index f2ba6ecc9ebae9959623d3fa096215181b7e15c0..7daaff81ac0a350b69b2819b742a88399d68deff 100644 --- a/module/VuFind/src/VuFind/Auth/PluginManager.php +++ b/module/VuFind/src/VuFind/Auth/PluginManager.php @@ -27,6 +27,8 @@ */ namespace VuFind\Auth; +use Zend\ServiceManager\Factory\InvokableFactory; + /** * Auth handler plugin manager * @@ -44,20 +46,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ - 'almadatabase' => 'VuFind\Auth\AlmaDatabase', - 'cas' => 'VuFind\Auth\CAS', - 'choiceauth' => 'VuFind\Auth\ChoiceAuth', - 'database' => 'VuFind\Auth\Database', - 'facebook' => 'VuFind\Auth\Facebook', - 'ils' => 'VuFind\Auth\ILS', - 'ldap' => 'VuFind\Auth\LDAP', - 'multiauth' => 'VuFind\Auth\MultiAuth', - 'multiils' => 'VuFind\Auth\MultiILS', - 'shibboleth' => 'VuFind\Auth\Shibboleth', - 'sip2' => 'VuFind\Auth\SIP2', + 'almadatabase' => AlmaDatabase::class, + 'cas' => CAS::class, + 'choiceauth' => ChoiceAuth::class, + 'database' => Database::class, + 'facebook' => Facebook::class, + 'ils' => ILS::class, + 'ldap' => LDAP::class, + 'multiauth' => MultiAuth::class, + 'multiils' => MultiILS::class, + 'shibboleth' => Shibboleth::class, + 'sip2' => SIP2::class, // for legacy 1.x compatibility - 'db' => 'VuFind\Auth\Database', - 'sip' => 'VuFind\Auth\SIP2', + 'db' => Database::class, + 'sip' => SIP2::class, ]; /** @@ -66,17 +68,17 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - 'VuFind\Auth\AlmaDatabase' => 'VuFind\Auth\Factory::getAlmaDatabase', - 'VuFind\Auth\CAS' => 'Zend\ServiceManager\Factory\InvokableFactory', - 'VuFind\Auth\ChoiceAuth' => 'VuFind\Auth\Factory::getChoiceAuth', - 'VuFind\Auth\Database' => 'Zend\ServiceManager\Factory\InvokableFactory', - 'VuFind\Auth\Facebook' => 'VuFind\Auth\Factory::getFacebook', - 'VuFind\Auth\ILS' => 'VuFind\Auth\Factory::getILS', - 'VuFind\Auth\LDAP' => 'Zend\ServiceManager\Factory\InvokableFactory', - 'VuFind\Auth\MultiAuth' => 'VuFind\Auth\Factory::getMultiAuth', - 'VuFind\Auth\MultiILS' => 'VuFind\Auth\Factory::getMultiILS', - 'VuFind\Auth\Shibboleth' => 'VuFind\Auth\Factory::getShibboleth', - 'VuFind\Auth\SIP2' => 'Zend\ServiceManager\Factory\InvokableFactory', + AlmaDatabase::class => ILSFactory::class, + CAS::class => InvokableFactory::class, + ChoiceAuth::class => ChoiceAuthFactory::class, + Database::class => InvokableFactory::class, + Facebook::class => FacebookFactory::class, + ILS::class => ILSFactory::class, + LDAP::class => InvokableFactory::class, + MultiAuth::class => MultiAuthFactory::class, + MultiILS::class => ILSFactory::class, + Shibboleth::class => ShibbolethFactory::class, + SIP2::class => InvokableFactory::class, ]; /** @@ -91,7 +93,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager public function __construct($configOrContainerInstance = null, array $v3config = [] ) { - $this->addAbstractFactory('VuFind\Auth\PluginFactory'); + $this->addAbstractFactory(PluginFactory::class); parent::__construct($configOrContainerInstance, $v3config); } @@ -103,6 +105,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager */ protected function getExpectedInterface() { - return 'VuFind\Auth\AbstractBase'; + return AbstractBase::class; } } diff --git a/module/VuFind/src/VuFind/Auth/ShibbolethFactory.php b/module/VuFind/src/VuFind/Auth/ShibbolethFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..60b4d412a69f8bb7f656455db7348ad0767be32e --- /dev/null +++ b/module/VuFind/src/VuFind/Auth/ShibbolethFactory.php @@ -0,0 +1,67 @@ +<?php +/** + * Factory for Shibboleth authentication module. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\Auth; + +use Interop\Container\ContainerInterface; + +/** + * Factory for Shibboleth authentication module. + * + * @category VuFind + * @package Authentication + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ShibbolethFactory implements \Zend\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + return new $requestedName( + $container->get(\Zend\Session\SessionManager::class) + ); + } +}