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

Eliminate static permission provider factories.

parent 02115425
No related merge requests found
<?php
/**
* Factory for instantiating permission providers with authorization service.
*
* 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 Authorization
* @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\Role\PermissionProvider;
use Interop\Container\ContainerInterface;
use ZfcRbac\Service\AuthorizationService;
/**
* Factory for instantiating permission providers with authorization service.
*
* @category VuFind
* @package Authorization
* @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 InjectAuthorizationServiceFactory
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
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
return new $requestedName($container->get(AuthorizationService::class));
}
}
<?php
/**
* Factory for instantiating permission providers with request object.
*
* 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 Authorization
* @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\Role\PermissionProvider;
use Interop\Container\ContainerInterface;
/**
* Factory for instantiating permission providers with request object.
*
* @category VuFind
* @package Authorization
* @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 InjectRequestFactory 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
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
return new $requestedName($container->get('Request'));
}
}
<?php <?php
/** /**
* Permission Provider Factory Class * Factory for instantiating IpRange permission provider.
* *
* 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,
...@@ -23,104 +23,48 @@ ...@@ -23,104 +23,48 @@
* @package Authorization * @package Authorization
* @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:plugins:hierarchy_components Wiki * @link https://vufind.org/wiki/development Wiki
*/ */
namespace VuFind\Role\PermissionProvider; namespace VuFind\Role\PermissionProvider;
use Zend\ServiceManager\ServiceManager; use Interop\Container\ContainerInterface;
/** /**
* Permission Provider Factory Class * Factory for instantiating IpRange permission provider.
* *
* @category VuFind * @category VuFind
* @package Authorization * @package Authorization
* @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:plugins:hierarchy_components Wiki * @link https://vufind.org/wiki/development Wiki
*
* @codeCoverageIgnore
*/ */
class Factory class IpRangeFactory implements \Zend\ServiceManager\Factory\FactoryInterface
{ {
/** /**
* Factory for IpRange * Create an object
*
* @param ServiceManager $sm Service manager.
*
* @return IpRange
*/
public static function getIpRange(ServiceManager $sm)
{
return new IpRange(
$sm->get('Request'),
$sm->get('VuFind\Net\IpAddressUtils')
);
}
/**
* Factory for IpRegEx
*
* @param ServiceManager $sm Service manager.
*
* @return IpRegEx
*/
public static function getIpRegEx(ServiceManager $sm)
{
return new IpRegEx($sm->get('Request'));
}
/**
* Factory for ServerParam
*
* @param ServiceManager $sm Service manager.
*
* @return ServerParam
*/
public static function getServerParam(ServiceManager $sm)
{
return new ServerParam($sm->get('Request'));
}
/**
* Factory for Shibboleth
*
* @param ServiceManager $sm Service manager.
*
* @return Shibboleth
*/
public static function getShibboleth(ServiceManager $sm)
{
return new Shibboleth(
$sm->get('Request'),
$sm->get('VuFind\Config\PluginManager')->get('config')
);
}
/**
* Factory for Username
* *
* @param ServiceManager $sm Service manager. * @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
* *
* @return Username * @return object
*/
public static function getUsername(ServiceManager $sm)
{
return new Username(
$sm->get('ZfcRbac\Service\AuthorizationService')
);
}
/**
* Factory for User
* *
* @param ServiceManager $sm Service manager. * @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
* *
* @return User * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
public static function getUser(ServiceManager $sm) public function __invoke(ContainerInterface $container, $requestedName,
{ array $options = null
return new User( ) {
$sm->get('ZfcRbac\Service\AuthorizationService') if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
return new $requestedName(
$container->get('Request'),
$container->get(\VuFind\Net\IpAddressUtils::class)
); );
} }
} }
...@@ -44,13 +44,13 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -44,13 +44,13 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
* @var array * @var array
*/ */
protected $aliases = [ protected $aliases = [
'ipRange' => 'VuFind\Role\PermissionProvider\IpRange', 'ipRange' => IpRange::class,
'ipRegEx' => 'VuFind\Role\PermissionProvider\IpRegEx', 'ipRegEx' => IpRegEx::class,
'role' => 'VuFind\Role\PermissionProvider\Role', 'role' => Role::class,
'serverParam' => 'VuFind\Role\PermissionProvider\ServerParam', 'serverParam' => ServerParam::class,
'shibboleth' => 'VuFind\Role\PermissionProvider\Shibboleth', 'shibboleth' => Shibboleth::class,
'user' => 'VuFind\Role\PermissionProvider\User', 'user' => User::class,
'username' => 'VuFind\Role\PermissionProvider\Username', 'username' => Username::class,
]; ];
/** /**
...@@ -59,20 +59,13 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -59,20 +59,13 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
* @var array * @var array
*/ */
protected $factories = [ protected $factories = [
'VuFind\Role\PermissionProvider\IpRange' => IpRange::class => IpRangeFactory::class,
'VuFind\Role\PermissionProvider\Factory::getIpRange', IpRegEx::class => InjectRequestFactory::class,
'VuFind\Role\PermissionProvider\IpRegEx' => Role::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
'VuFind\Role\PermissionProvider\Factory::getIpRegEx', ServerParam::class => InjectRequestFactory::class,
'VuFind\Role\PermissionProvider\Role' => Shibboleth::class => ShibbolethFactory::class,
'Zend\ServiceManager\Factory\InvokableFactory', User::class => InjectAuthorizationServiceFactory::class,
'VuFind\Role\PermissionProvider\ServerParam' => Username::class => InjectAuthorizationServiceFactory::class,
'VuFind\Role\PermissionProvider\Factory::getServerParam',
'VuFind\Role\PermissionProvider\Shibboleth' =>
'VuFind\Role\PermissionProvider\Factory::getShibboleth',
'VuFind\Role\PermissionProvider\User' =>
'VuFind\Role\PermissionProvider\Factory::getUser',
'VuFind\Role\PermissionProvider\Username' =>
'VuFind\Role\PermissionProvider\Factory::getUsername',
]; ];
/** /**
...@@ -83,6 +76,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager ...@@ -83,6 +76,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
*/ */
protected function getExpectedInterface() protected function getExpectedInterface()
{ {
return 'VuFind\Role\PermissionProvider\PermissionProviderInterface'; return PermissionProviderInterface::class;
} }
} }
<?php
/**
* Factory for instantiating Shibboleth permission provider.
*
* 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 Authorization
* @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\Role\PermissionProvider;
use Interop\Container\ContainerInterface;
/**
* Factory for instantiating Shibboleth permission provider.
*
* @category VuFind
* @package Authorization
* @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
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$cfg = $container->get(\VuFind\Config\PluginManager::class)->get('config');
return new $requestedName($container->get('Request'), $cfg);
}
}
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