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 ...@@ -90,7 +90,7 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
*/ */
private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl) private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl)
{ {
/* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */ /* @var $router \Zend\Router\Http\TreeRouteStack */
$router = $sl->get('router'); $router = $sl->get('router');
// si l'auth CAS est activée, modif de la route de connexion pour zapper le formulaire d'auth maison. // 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; ...@@ -5,7 +5,7 @@ namespace UnicaenAuth\Assertion;
use BjyAuthorize\Service\Authorize; use BjyAuthorize\Service\Authorize;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait; use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use Zend\Mvc\Application; use Zend\Mvc\Application;
use Zend\Mvc\Controller\Plugin\FlashMessenger; use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger;
use Zend\Mvc\MvcEvent; use Zend\Mvc\MvcEvent;
use Zend\Permissions\Acl\Acl; use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\Permissions\Acl\Assertion\AssertionInterface;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Authentication\Adapter; namespace UnicaenAuth\Authentication\Adapter;
use Interop\Container\ContainerInterface;
use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\LogicException;
use Zend\EventManager\EventManager; use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerAwareInterface;
...@@ -15,28 +16,22 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -15,28 +16,22 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/ */
class AbstractFactory implements AbstractFactoryInterface 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) 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) 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) { switch ($requestedName) {
case __NAMESPACE__ . '\Ldap': case __NAMESPACE__ . '\Ldap':
...@@ -61,9 +56,9 @@ class AbstractFactory implements AbstractFactoryInterface ...@@ -61,9 +56,9 @@ class AbstractFactory implements AbstractFactoryInterface
if ($adapter instanceof EventManagerAwareInterface) { if ($adapter instanceof EventManagerAwareInterface) {
/** @var EventManager $eventManager */ /** @var EventManager $eventManager */
$eventManager = $serviceLocator->get('event_manager'); $eventManager = $container->get('event_manager');
$adapter->setEventManager($eventManager); $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); $eventManager->attach('userAuthenticated', [$userService, 'userAuthenticated'], 100);
} }
......
...@@ -12,7 +12,7 @@ use Zend\Authentication\Result as AuthenticationResult; ...@@ -12,7 +12,7 @@ use Zend\Authentication\Result as AuthenticationResult;
use Zend\EventManager\EventManager; use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface; use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Router\Http\TreeRouteStack; use Zend\Router\Http\TreeRouteStack;
use Zend\ServiceManager\ServiceLocatorAwareTrait; use Zend\ServiceManager\ServiceLocatorAwareTrait;
use ZfcUser\Authentication\Adapter\AbstractAdapter; use ZfcUser\Authentication\Adapter\AbstractAdapter;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace UnicaenAuth\Authentication; namespace UnicaenAuth\Authentication;
use Interop\Container\ContainerInterface;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Authentication\AuthenticationService;
/** /**
* Description of AuthenticationServiceFactory * Description of AuthenticationServiceFactory
...@@ -13,17 +14,16 @@ use Zend\Authentication\AuthenticationService; ...@@ -13,17 +14,16 @@ use Zend\Authentication\AuthenticationService;
*/ */
class AuthenticationServiceFactory implements FactoryInterface class AuthenticationServiceFactory implements FactoryInterface
{ {
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return AuthenticationService
*/
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{ {
return new AuthenticationService( return new AuthenticationService(
$serviceLocator->get('UnicaenAuth\Authentication\Storage\Chain'), $container->get('UnicaenAuth\Authentication\Storage\Chain'),
$serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain') $container->get('ZfcUser\Authentication\Adapter\AdapterChain')
); );
} }
} }
\ No newline at end of file
...@@ -5,8 +5,8 @@ namespace UnicaenAuth\Authentication; ...@@ -5,8 +5,8 @@ namespace UnicaenAuth\Authentication;
use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Request;
use Zend\Http\PhpEnvironment\Response; use Zend\Http\PhpEnvironment\Response;
use Zend\Mvc\Application; use Zend\Mvc\Application;
use Zend\Mvc\Router\Exception; use Zend\Router\Exception;
use Zend\Mvc\Router\RouteInterface; use Zend\Router\RouteInterface;
use ZfcUser\Options\ModuleOptions; use ZfcUser\Options\ModuleOptions;
/** /**
......
...@@ -2,30 +2,29 @@ ...@@ -2,30 +2,29 @@
namespace UnicaenAuth\Authentication; namespace UnicaenAuth\Authentication;
use Interop\Container\ContainerInterface;
use Zend\Mvc\Application; use Zend\Mvc\Application;
use Zend\Mvc\Router\RouteInterface; use Zend\Router\RouteInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Options\ModuleOptions; use ZfcUser\Options\ModuleOptions;
class RedirectCallbackFactory implements FactoryInterface class RedirectCallbackFactory implements FactoryInterface
{ {
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{ return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{ {
/* @var RouteInterface $router */ /* @var RouteInterface $router */
$router = $serviceLocator->get('Router'); $router = $container->get('Router');
/* @var Application $application */ /* @var Application $application */
$application = $serviceLocator->get('Application'); $application = $container->get('Application');
/* @var ModuleOptions $options */ /* @var ModuleOptions $options */
$options = $serviceLocator->get('zfcuser_module_options'); $options = $container->get('zfcuser_module_options');
return new RedirectCallback($application, $router, $options); return new RedirectCallback($application, $router, $options);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Authentication\Storage; namespace UnicaenAuth\Authentication\Storage;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Options\ModuleOptions;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -21,18 +22,17 @@ class ChainServiceFactory implements FactoryInterface ...@@ -21,18 +22,17 @@ class ChainServiceFactory implements FactoryInterface
protected $storages = []; protected $storages = [];
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{ {
$chain = new Chain(); $chain = new Chain();
/** @var ModuleOptions $options */ /** @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 // retrait du fournisseur Ldap si l'auth LDAP est désactivée
if (isset($options->getLdap()['enabled']) && ! $options->getLdap()['enabled']) { if (isset($options->getLdap()['enabled']) && ! $options->getLdap()['enabled']) {
...@@ -43,7 +43,7 @@ class ChainServiceFactory implements FactoryInterface ...@@ -43,7 +43,7 @@ class ChainServiceFactory implements FactoryInterface
krsort($storages); krsort($storages);
foreach ($storages as $priority => $name) { foreach ($storages as $priority => $name) {
$storage = $serviceLocator->get($name); $storage = $container->get($name);
$chain->getEventManager()->attach('read', [$storage, 'read'], $priority); $chain->getEventManager()->attach('read', [$storage, 'read'], $priority);
$chain->getEventManager()->attach('write', [$storage, 'write'], $priority); $chain->getEventManager()->attach('write', [$storage, 'write'], $priority);
$chain->getEventManager()->attach('clear', [$storage, 'clear'], $priority); $chain->getEventManager()->attach('clear', [$storage, 'clear'], $priority);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Mouchard; namespace UnicaenAuth\Mouchard;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -12,17 +13,16 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -12,17 +13,16 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/ */
class MouchardCompleterAuthFactory implements FactoryInterface class MouchardCompleterAuthFactory implements FactoryInterface
{ {
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return MouchardCompleterAuth
*/
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator);
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{ {
$mouchardCompleterAuth = new MouchardCompleterAuth(); $mouchardCompleterAuth = new MouchardCompleterAuth();
$serviceUserContext = $serviceLocator->get('UnicaenAuth\Service\UserContext'); $serviceUserContext = $container->get('UnicaenAuth\Service\UserContext');
$mouchardCompleterAuth->setServiceUserContext($serviceUserContext); $mouchardCompleterAuth->setServiceUserContext($serviceUserContext);
return $mouchardCompleterAuth; return $mouchardCompleterAuth;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Options; namespace UnicaenAuth\Options;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -12,15 +13,14 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -12,15 +13,14 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/ */
class ModuleOptionsFactory implements FactoryInterface class ModuleOptionsFactory implements FactoryInterface
{ {
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) 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 = isset($config['unicaen-auth']) ? $config['unicaen-auth'] : [];
$moduleConfig = array_merge($config['zfcuser'], $moduleConfig); $moduleConfig = array_merge($config['zfcuser'], $moduleConfig);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -17,8 +18,13 @@ class BasicServiceFactory implements FactoryInterface ...@@ -17,8 +18,13 @@ class BasicServiceFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{ {
$user = $serviceLocator->get('zfcuser_user_service'); return $this->__invoke($serviceLocator, '?');
$config = $serviceLocator->get('BjyAuthorize\Config'); }
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 = new Basic($user->getAuthService());
$identityProvider->setDefaultRole($config['default_role']); $identityProvider->setDefaultRole($config['default_role']);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -12,21 +13,20 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -12,21 +13,20 @@ use Zend\ServiceManager\ServiceLocatorInterface;
*/ */
class ChainServiceFactory implements FactoryInterface class ChainServiceFactory implements FactoryInterface
{ {
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{ {
$chain = new Chain(); $chain = new Chain();
$chain->setServiceLocator($serviceLocator); $chain->setServiceLocator($container);
$providers = $this->computeProviders($serviceLocator); $providers = $this->computeProviders($container);
foreach ($providers as $priority => $name) { foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name); $provider = $container->get($name);
$chain->getEventManager()->attach('getIdentityRoles', [$provider, 'injectIdentityRoles'], $priority); $chain->getEventManager()->attach('getIdentityRoles', [$provider, 'injectIdentityRoles'], $priority);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use UnicaenApp\Options\ModuleOptions; use UnicaenApp\Options\ModuleOptions;
use Zend\Ldap\Ldap; use Zend\Ldap\Ldap;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
...@@ -19,18 +20,23 @@ class DbServiceFactory implements FactoryInterface ...@@ -19,18 +20,23 @@ class DbServiceFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $serviceLocator) 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()); $identityProvider = new Db($user->getAuthService());
$unicaenAppOptions = $serviceLocator->get('unicaen-app_module_options'); $unicaenAppOptions = $container->get('unicaen-app_module_options');
/* @var $unicaenAppOptions ModuleOptions */ /* @var $unicaenAppOptions ModuleOptions */
$ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']); $ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']);
$identityProvider->setLdap($ldap); $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->setDefaultRole($config['default_role']);
$identityProvider->setAuthenticatedRole($config['authenticated_role']); $identityProvider->setAuthenticatedRole($config['authenticated_role']);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
namespace UnicaenAuth\Provider\Identity; namespace UnicaenAuth\Provider\Identity;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
use UnicaenAuth\Acl\NamedRole;
/** /**
* LDAP identity provider factory * LDAP identity provider factory
...@@ -19,10 +19,15 @@ class LdapServiceFactory implements FactoryInterface ...@@ -19,10 +19,15 @@ class LdapServiceFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $serviceLocator) public function createService(ServiceLocatorInterface $serviceLocator)
{ {
$config = $serviceLocator->get('BjyAuthorize\Config'); return $this->__invoke($serviceLocator, '?');
$user = $serviceLocator->get('zfcuser_user_service'); }
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 = new Ldap($user->getAuthService());
$simpleIdentityProvider->setDefaultRole($config['default_role']); $simpleIdentityProvider->setDefaultRole($config['default_role']);
$simpleIdentityProvider->setAuthenticatedRole($config['authenticated_role']); $simpleIdentityProvider->setAuthenticatedRole($config['authenticated_role']);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace UnicaenAuth\Provider\Role; namespace UnicaenAuth\Provider\Role;
use BjyAuthorize\Exception\InvalidArgumentException; use BjyAuthorize\Exception\InvalidArgumentException;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -15,23 +16,26 @@ class ConfigServiceFactory implements FactoryInterface ...@@ -15,23 +16,26 @@ class ConfigServiceFactory implements FactoryInterface
{ {