Commit 5c57ded8 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections pour passer à ZF3.

parent e0827096
Pipeline #3939 passed with stage
in 19 seconds
......@@ -90,7 +90,7 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
*/
private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl)
{
/* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */
/* @var $router \Zend\Router\Http\TreeRouteStack */
$router = $sl->get('router');
// si l'auth CAS est activée, modif de la route de connexion pour zapper le formulaire d'auth maison.
......
......@@ -5,7 +5,7 @@ namespace UnicaenAuth\Assertion;
use BjyAuthorize\Service\Authorize;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\Plugin\FlashMessenger;
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger;
use Zend\Mvc\MvcEvent;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Assertion\AssertionInterface;
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Authentication\Adapter;
use Interop\Container\ContainerInterface;
use UnicaenApp\Exception\LogicException;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
......@@ -15,28 +16,22 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class AbstractFactory implements AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName);
return $this->canCreate($serviceLocator, $requestedName);
}
/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return \ZfcUser\Authentication\Adapter\AbstractAdapter
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->__invoke($serviceLocator, $requestedName);
}
public function canCreate(ContainerInterface $container, $requestedName)
{
return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName);
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
switch ($requestedName) {
case __NAMESPACE__ . '\Ldap':
......@@ -61,9 +56,9 @@ class AbstractFactory implements AbstractFactoryInterface
if ($adapter instanceof EventManagerAwareInterface) {
/** @var EventManager $eventManager */
$eventManager = $serviceLocator->get('event_manager');
$eventManager = $container->get('event_manager');
$adapter->setEventManager($eventManager);
$userService = $serviceLocator->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */
$userService = $container->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */
$eventManager->attach('userAuthenticated', [$userService, 'userAuthenticated'], 100);
}
......
......@@ -12,7 +12,7 @@ use Zend\Authentication\Result as AuthenticationResult;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Zend\Router\Http\TreeRouteStack;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use ZfcUser\Authentication\Adapter\AbstractAdapter;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
......
......@@ -2,9 +2,10 @@
namespace UnicaenAuth\Authentication;
use Interop\Container\ContainerInterface;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Authentication\AuthenticationService;
/**
* Description of AuthenticationServiceFactory
......@@ -13,17 +14,16 @@ use Zend\Authentication\AuthenticationService;
*/
class AuthenticationServiceFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return AuthenticationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new AuthenticationService(
$serviceLocator->get('UnicaenAuth\Authentication\Storage\Chain'),
$serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain')
$container->get('UnicaenAuth\Authentication\Storage\Chain'),
$container->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
}
}
\ No newline at end of file
......@@ -5,8 +5,8 @@ namespace UnicaenAuth\Authentication;
use Zend\Http\PhpEnvironment\Request;
use Zend\Http\PhpEnvironment\Response;
use Zend\Mvc\Application;
use Zend\Mvc\Router\Exception;
use Zend\Mvc\Router\RouteInterface;
use Zend\Router\Exception;
use Zend\Router\RouteInterface;
use ZfcUser\Options\ModuleOptions;
/**
......
......@@ -2,30 +2,29 @@
namespace UnicaenAuth\Authentication;
use Interop\Container\ContainerInterface;
use Zend\Mvc\Application;
use Zend\Mvc\Router\RouteInterface;
use Zend\Router\RouteInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Options\ModuleOptions;
class RedirectCallbackFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{ return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var RouteInterface $router */
$router = $serviceLocator->get('Router');
$router = $container->get('Router');
/* @var Application $application */
$application = $serviceLocator->get('Application');
$application = $container->get('Application');
/* @var ModuleOptions $options */
$options = $serviceLocator->get('zfcuser_module_options');
$options = $container->get('zfcuser_module_options');
return new RedirectCallback($application, $router, $options);
}
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Authentication\Storage;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -21,18 +22,17 @@ class ChainServiceFactory implements FactoryInterface
protected $storages = [];
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$chain = new Chain();
/** @var ModuleOptions $options */
$options = $serviceLocator->get('unicaen-auth_module_options');
$options = $container->get('unicaen-auth_module_options');
// retrait du fournisseur Ldap si l'auth LDAP est désactivée
if (isset($options->getLdap()['enabled']) && ! $options->getLdap()['enabled']) {
......@@ -43,7 +43,7 @@ class ChainServiceFactory implements FactoryInterface
krsort($storages);
foreach ($storages as $priority => $name) {
$storage = $serviceLocator->get($name);
$storage = $container->get($name);
$chain->getEventManager()->attach('read', [$storage, 'read'], $priority);
$chain->getEventManager()->attach('write', [$storage, 'write'], $priority);
$chain->getEventManager()->attach('clear', [$storage, 'clear'], $priority);
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Mouchard;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,17 +13,16 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class MouchardCompleterAuthFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return MouchardCompleterAuth
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator);
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$mouchardCompleterAuth = new MouchardCompleterAuth();
$serviceUserContext = $serviceLocator->get('UnicaenAuth\Service\UserContext');
$serviceUserContext = $container->get('UnicaenAuth\Service\UserContext');
$mouchardCompleterAuth->setServiceUserContext($serviceUserContext);
return $mouchardCompleterAuth;
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Options;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,15 +13,14 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class ModuleOptionsFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Configuration');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('Configuration');
$moduleConfig = isset($config['unicaen-auth']) ? $config['unicaen-auth'] : [];
$moduleConfig = array_merge($config['zfcuser'], $moduleConfig);
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -17,8 +18,13 @@ class BasicServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$user = $serviceLocator->get('zfcuser_user_service');
$config = $serviceLocator->get('BjyAuthorize\Config');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$user = $container->get('zfcuser_user_service');
$config = $container->get('BjyAuthorize\Config');
$identityProvider = new Basic($user->getAuthService());
$identityProvider->setDefaultRole($config['default_role']);
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,21 +13,20 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class ChainServiceFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$chain = new Chain();
$chain->setServiceLocator($serviceLocator);
$chain->setServiceLocator($container);
$providers = $this->computeProviders($serviceLocator);
$providers = $this->computeProviders($container);
foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name);
$provider = $container->get($name);
$chain->getEventManager()->attach('getIdentityRoles', [$provider, 'injectIdentityRoles'], $priority);
}
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use UnicaenApp\Options\ModuleOptions;
use Zend\Ldap\Ldap;
use Zend\ServiceManager\FactoryInterface;
......@@ -19,18 +20,23 @@ class DbServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$user = $serviceLocator->get('zfcuser_user_service');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$user = $container->get('zfcuser_user_service');
$identityProvider = new Db($user->getAuthService());
$unicaenAppOptions = $serviceLocator->get('unicaen-app_module_options');
$unicaenAppOptions = $container->get('unicaen-app_module_options');
/* @var $unicaenAppOptions ModuleOptions */
$ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']);
$identityProvider->setLdap($ldap);
$identityProvider->setServiceRole($serviceLocator->get('UnicaenAuth\Service\Role'));
$identityProvider->setServiceRole($container->get('UnicaenAuth\Service\Role'));
$config = $serviceLocator->get('BjyAuthorize\Config');
$config = $container->get('BjyAuthorize\Config');
$identityProvider->setDefaultRole($config['default_role']);
$identityProvider->setAuthenticatedRole($config['authenticated_role']);
......
......@@ -2,9 +2,9 @@
namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use UnicaenAuth\Acl\NamedRole;
/**
* LDAP identity provider factory
......@@ -19,10 +19,15 @@ class LdapServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('BjyAuthorize\Config');
$user = $serviceLocator->get('zfcuser_user_service');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('BjyAuthorize\Config');
$user = $container->get('zfcuser_user_service');
$simpleIdentityProvider = new Ldap($user->getAuthService());
$simpleIdentityProvider->setDefaultRole($config['default_role']);
$simpleIdentityProvider->setAuthenticatedRole($config['authenticated_role']);
......
......@@ -3,6 +3,7 @@
namespace UnicaenAuth\Provider\Role;
use BjyAuthorize\Exception\InvalidArgumentException;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -15,23 +16,26 @@ class ConfigServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*
* @return \BjyAuthorize\Provider\Role\Config
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('BjyAuthorize\Config');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('BjyAuthorize\Config');
if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Config'])) {
throw new InvalidArgumentException(
'Config for "UnicaenAuth\Provider\Role\Config" not set'
);
}
$providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Config'];
/* @var $mapper \UnicaenApp\Mapper\Ldap\Group */
$mapper = $serviceLocator->get('ldap_group_mapper');
$mapper = $container->get('ldap_group_mapper');
$service = new Config($mapper, $providerConfig);
......
......@@ -2,7 +2,7 @@
namespace UnicaenAuth\Provider\Role;
use BjyAuthorize\Exception\InvalidArgumentException;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Service\RoleService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -14,12 +14,15 @@ class DbRoleServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*
* @return DbRole
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$serviceRole = $serviceLocator->get('UnicaenAuth\Service\Role');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$serviceRole = $container->get('UnicaenAuth\Service\Role');
/* @var $serviceRole RoleService */
return new DbRole($serviceRole->getRepo());
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Role;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -12,26 +13,25 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/
class UsernameServiceFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Username
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('BjyAuthorize\Config');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('BjyAuthorize\Config');
if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Username'])) {
throw new InvalidArgumentException(
throw new \InvalidArgumentException(
'Config for "UnicaenAuth\Provider\Role\Username" not set'
);
}
$providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Username'];
$authService = $serviceLocator->get('zfcuser_auth_service'); /* @var $authService \Zend\Authentication\AuthenticationService */
$authService = $container->get('zfcuser_auth_service'); /* @var $authService \Zend\Authentication\AuthenticationService */
return new Username($authService, $providerConfig);
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
namespace UnicaenAuth\Service;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -20,11 +21,13 @@ class AuthorizeServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*
* @return \Application\Service\Authorize
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new AuthorizeService($serviceLocator->get('BjyAuthorize\Config'), $serviceLocator);
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new AuthorizeService($container->get('BjyAuthorize\Config'), $container);
}
}
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Service;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Entity\Db\Privilege;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -10,7 +11,12 @@ class PrivilegeServiceFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('Config');
if (! isset($config['unicaen-auth']['privilege_entity_class'])) {
// throw new InvalidArgumentException("La classe de l'entité privilège n'a pas été trouvée dans la config");
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Service;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Entity\Db\Role;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -10,7 +11,12 @@ class RoleServiceFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');