Skip to content
Snippets Groups Projects
Commit 857e85d4 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Eliminate static authentication factories.

parent 88fd420f
No related merge requests found
<?php <?php
/** /**
* Factory for authentication services. * Factory for ChoiceAuth authentication module.
* *
* PHP version 7 * PHP version 7
* *
* Copyright (C) Villanova University 2014. * Copyright (C) Villanova University 2019.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
...@@ -27,123 +27,44 @@ ...@@ -27,123 +27,44 @@
*/ */
namespace VuFind\Auth; namespace VuFind\Auth;
use Zend\ServiceManager\ServiceManager; use Interop\Container\ContainerInterface;
/** /**
* Factory for authentication services. * Factory for ChoiceAuth authentication module.
* *
* @category VuFind * @category VuFind
* @package Authentication * @package Authentication
* @author Demian Katz <demian.katz@villanova.edu> * @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki * @link https://vufind.org/wiki/development Wiki
*
* @codeCoverageIgnore
*/ */
class Factory class ChoiceAuthFactory implements \Zend\ServiceManager\Factory\FactoryInterface
{ {
/** /**
* Construct the ChoiceAuth plugin. * Create an object
* *
* @param ServiceManager $sm Service manager. * @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
* *
* @return ChoiceAuth * @return object
*/
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 * @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 static function getFacebook(ServiceManager $sm) public function __invoke(ContainerInterface $container, $requestedName,
{ array $options = null
$container = new \Zend\Session\Container( ) {
'Facebook', $sm->get('Zend\Session\SessionManager') if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$session = new \Zend\Session\Container(
'ChoiceAuth', $container->get(\Zend\Session\SessionManager::class)
); );
return new Facebook($container); $auth = new $requestedName($session);
} $auth->setPluginManager($container->get(PluginManager::class));
/**
* 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; 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')
);
}
} }
<?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);
}
}
<?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)
);
}
}
<?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;
}
}
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
*/ */
namespace VuFind\Auth; namespace VuFind\Auth;
use Zend\ServiceManager\Factory\InvokableFactory;
/** /**
* Auth handler plugin manager * Auth handler plugin manager
* *
...@@ -44,20 +46,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -44,20 +46,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
* @var array * @var array
*/ */
protected $aliases = [ protected $aliases = [
'almadatabase' => 'VuFind\Auth\AlmaDatabase', 'almadatabase' => AlmaDatabase::class,
'cas' => 'VuFind\Auth\CAS', 'cas' => CAS::class,
'choiceauth' => 'VuFind\Auth\ChoiceAuth', 'choiceauth' => ChoiceAuth::class,
'database' => 'VuFind\Auth\Database', 'database' => Database::class,
'facebook' => 'VuFind\Auth\Facebook', 'facebook' => Facebook::class,
'ils' => 'VuFind\Auth\ILS', 'ils' => ILS::class,
'ldap' => 'VuFind\Auth\LDAP', 'ldap' => LDAP::class,
'multiauth' => 'VuFind\Auth\MultiAuth', 'multiauth' => MultiAuth::class,
'multiils' => 'VuFind\Auth\MultiILS', 'multiils' => MultiILS::class,
'shibboleth' => 'VuFind\Auth\Shibboleth', 'shibboleth' => Shibboleth::class,
'sip2' => 'VuFind\Auth\SIP2', 'sip2' => SIP2::class,
// for legacy 1.x compatibility // for legacy 1.x compatibility
'db' => 'VuFind\Auth\Database', 'db' => Database::class,
'sip' => 'VuFind\Auth\SIP2', 'sip' => SIP2::class,
]; ];
/** /**
...@@ -66,17 +68,17 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -66,17 +68,17 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
* @var array * @var array
*/ */
protected $factories = [ protected $factories = [
'VuFind\Auth\AlmaDatabase' => 'VuFind\Auth\Factory::getAlmaDatabase', AlmaDatabase::class => ILSFactory::class,
'VuFind\Auth\CAS' => 'Zend\ServiceManager\Factory\InvokableFactory', CAS::class => InvokableFactory::class,
'VuFind\Auth\ChoiceAuth' => 'VuFind\Auth\Factory::getChoiceAuth', ChoiceAuth::class => ChoiceAuthFactory::class,
'VuFind\Auth\Database' => 'Zend\ServiceManager\Factory\InvokableFactory', Database::class => InvokableFactory::class,
'VuFind\Auth\Facebook' => 'VuFind\Auth\Factory::getFacebook', Facebook::class => FacebookFactory::class,
'VuFind\Auth\ILS' => 'VuFind\Auth\Factory::getILS', ILS::class => ILSFactory::class,
'VuFind\Auth\LDAP' => 'Zend\ServiceManager\Factory\InvokableFactory', LDAP::class => InvokableFactory::class,
'VuFind\Auth\MultiAuth' => 'VuFind\Auth\Factory::getMultiAuth', MultiAuth::class => MultiAuthFactory::class,
'VuFind\Auth\MultiILS' => 'VuFind\Auth\Factory::getMultiILS', MultiILS::class => ILSFactory::class,
'VuFind\Auth\Shibboleth' => 'VuFind\Auth\Factory::getShibboleth', Shibboleth::class => ShibbolethFactory::class,
'VuFind\Auth\SIP2' => 'Zend\ServiceManager\Factory\InvokableFactory', SIP2::class => InvokableFactory::class,
]; ];
/** /**
...@@ -91,7 +93,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -91,7 +93,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
public function __construct($configOrContainerInstance = null, public function __construct($configOrContainerInstance = null,
array $v3config = [] array $v3config = []
) { ) {
$this->addAbstractFactory('VuFind\Auth\PluginFactory'); $this->addAbstractFactory(PluginFactory::class);
parent::__construct($configOrContainerInstance, $v3config); parent::__construct($configOrContainerInstance, $v3config);
} }
...@@ -103,6 +105,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -103,6 +105,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
*/ */
protected function getExpectedInterface() protected function getExpectedInterface()
{ {
return 'VuFind\Auth\AbstractBase'; return AbstractBase::class;
} }
} }
<?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)
);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment