Commit fa319b5a authored by Bertrand Gauthier's avatar Bertrand Gauthier

Corrections pour passer à ZF3.

parent 4a780e4c
Pipeline #3988 passed with stage
in 18 seconds
......@@ -149,22 +149,22 @@ return [
* You may omit the 'action' index to allow access to the entire controller
*/
'BjyAuthorize\Guard\Controller' => [
['controller' => 'index', 'action' => 'index', 'roles' => []],
['controller' => 'zfcuser', 'roles' => []],
['controller' => 'Application\Controller\Index', 'roles' => []],
['controller' => 'index', 'action' => 'index', 'roles' => 'guest'],
['controller' => 'zfcuser', 'roles' => 'guest'],
['controller' => 'Application\Controller\Index', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'etab', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'apropos', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'contact', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'plan', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'mentions-legales', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'informatique-et-libertes', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'refresh-session', 'roles' => []],
['controller' => 'UnicaenAuth\Controller\Utilisateur', 'action' => 'selectionner-profil', 'roles' => []],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'etab', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'apropos', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'contact', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'plan', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'mentions-legales', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'informatique-et-libertes', 'roles' => 'guest'],
['controller' => 'UnicaenApp\Controller\Application', 'action' => 'refresh-session', 'roles' => 'guest'],
['controller' => 'UnicaenAuth\Controller\Utilisateur', 'action' => 'selectionner-profil', 'roles' => 'guest'],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'shibboleth', 'roles' => []],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'requestPasswordReset', 'roles' => []],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'changePassword', 'roles' => []],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'shibboleth', 'roles' => 'guest'],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'requestPasswordReset', 'roles' => 'guest'],
['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'changePassword', 'roles' => 'guest'],
],
],
],
......@@ -427,6 +427,7 @@ return [
'unicaen-auth_user_service' => 'UnicaenAuth\Service\User', // pour la compatibilité
'authUserContext' => 'UnicaenAuth\Service\UserContext', // pour la compatibilité
'AuthUserContext' => 'UnicaenAuth\Service\UserContext', // pour la compatibilité
],
'invokables' => [
'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy',
......
......@@ -8,6 +8,7 @@ use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\User;
use Zend\Authentication\Exception\UnexpectedValueException;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\EventManager\Event;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
......@@ -77,12 +78,14 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface
/**
* Réalise l'authentification.
*
* @param \Zend\EventManager\Event|AuthEvent $e
* @param Event $e
* @throws UnexpectedValueException
* @see ChainableAdapter
*/
public function authenticate(\Zend\EventManager\Event $e)
public function authenticate(Event $e)
{
$e = $e->getTarget();
// if ($e->getIdentity()) {
// return;
// }
......@@ -128,10 +131,10 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface
/**
*
* @param AuthEvent $e
* @param Event $e
* @see ChainableAdapter
*/
public function logout(AuthEvent $e)
public function logout(Event $e)
{
if (!$this->getOptions()->getCas()) {
return; // NB: l'authentification CAS est désactivée ssi le tableau des options est vide
......
......@@ -45,14 +45,14 @@ class Db extends \ZfcUser\Authentication\Adapter\Db implements ServiceLocatorAwa
*/
public function authenticate(\Zend\EventManager\Event $e)
{
if ($e->getIdentity()) {
if ($e->getTarget()->getIdentity()) {
return;
}
try {
$result = parent::authenticate($e);
}
catch (ServiceNotFoundException $e) {
catch (ServiceNotFoundException $snfe) {
return false;
}
......
......@@ -14,7 +14,6 @@ use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use ZfcUser\Authentication\Adapter\AbstractAdapter;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
use ZfcUser\Authentication\Adapter\ChainableAdapter;
/**
......@@ -79,14 +78,16 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface
/**
*
* @param AuthEvent|\Zend\EventManager\Event $e
* @param Event $e
* @return boolean
* @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface
* @throws \Zend\Ldap\Exception\LdapException
* @see ChainableAdapter
*/
public function authenticate(\Zend\EventManager\Event $e)
public function authenticate(Event $e)
{
$e = $e->getTarget();
if ($this->isSatisfied()) {
try {
$storage = $this->getStorage()->read();
......@@ -197,10 +198,11 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface
// Obtenir le message LDAP
// $msg = preg_replace('/\[0x\d* \((.*)\):/','$1', $event->getParam('result')->getMessages()[1]);
$eventClasse = new Event('authentication.ldap.error');
$eventClasse->setTarget($this)->setParams([
$eventClasse->setTarget($this);
$eventClasse->setParams([
'result' => $result
]);
$this->getEventManager()->trigger($eventClasse);
$this->getEventManager()->triggerEvent($eventClasse);
}
$success = $result->isValid();
......
......@@ -69,7 +69,8 @@ class Chain implements StorageInterface, EventManagerAwareInterface
}
$e = $this->getEvent();
$this->getEventManager()->trigger('read', $e);
$e->setName('read');
$this->getEventManager()->triggerEvent($e);
$identity = $e->getContents();
......@@ -95,8 +96,9 @@ class Chain implements StorageInterface, EventManagerAwareInterface
$this->getStorage()->write($contents);
$e = $this->getEvent();
$e->setName('write');
$e->setParams(compact('contents'));
$this->getEventManager()->trigger('write', $e);
$this->getEventManager()->triggerEvent($e);
}
/**
......@@ -110,7 +112,8 @@ class Chain implements StorageInterface, EventManagerAwareInterface
$this->getStorage()->clear();
$e = $this->getEvent();
$this->getEventManager()->trigger('clear', $e);
$e->setName('clear');
$this->getEventManager()->triggerEvent($e);
}
/**
......
......@@ -4,6 +4,7 @@ namespace UnicaenAuth\Authentication\Storage;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\EventManager\EventManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -31,6 +32,11 @@ class ChainServiceFactory implements FactoryInterface
{
$chain = new Chain();
/** @var EventManager $eventManager */
$eventManager = $container->get('EventManager');
$chain->setEventManager($eventManager);
/** @var ModuleOptions $options */
$options = $container->get('unicaen-auth_module_options');
......
......@@ -5,7 +5,6 @@ namespace UnicaenAuth\Authentication\Storage;
use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper;
use UnicaenAuth\Entity\Ldap\People;
use UnicaenAuth\Options\ModuleOptions;
use Zend\Authentication\Exception\InvalidArgumentException;
use Zend\Authentication\Storage\Session;
use Zend\Authentication\Storage\StorageInterface;
......@@ -41,7 +40,7 @@ class Ldap implements ChainableStorage
*
* Behavior is undefined when storage is empty.
*
* @throws InvalidArgumentException If reading contents from storage is impossible
* @param ChainEvent $e
* @return People
*/
public function read(ChainEvent $e)
......@@ -54,8 +53,7 @@ class Ldap implements ChainableStorage
}
/**
*
* @return null
* @return People|null
*/
protected function findIdentity()
{
......@@ -85,13 +83,11 @@ class Ldap implements ChainableStorage
return $this->resolvedIdentity;
}
/**
* Writes $contents to storage
*
* @param mixed $contents
* @throws InvalidArgumentException If writing $contents to storage is impossible
* @return void
* @param ChainEvent $e
*/
public function write(ChainEvent $e)
{
......@@ -104,8 +100,7 @@ class Ldap implements ChainableStorage
/**
* Clears contents from storage
*
* @throws InvalidArgumentException If clearing contents from storage is impossible
* @return void
* @param ChainEvent $e
*/
public function clear(ChainEvent $e)
{
......@@ -163,6 +158,7 @@ class Ldap implements ChainableStorage
/**
* @param ModuleOptions $options
* @return Ldap
*/
public function setOptions(ModuleOptions $options = null)
{
......
......@@ -97,10 +97,11 @@ class Chain implements ProviderInterface, EventManagerAwareInterface
$this->roles = [];
$e = $this->getEvent();
$e->setName('getIdentityRoles');
$e->clearRoles();
// collecte des rôles
$this->getEventManager()->trigger('getIdentityRoles', $e);
$this->getEventManager()->triggerEvent($e);
$roles = $e->getRoles(); /** @var RoleInterface[] $roles */
$registry = new Registry();
......
......@@ -5,6 +5,7 @@ namespace UnicaenAuth\Provider\Identity;
use BjyAuthorize\Service\Authorize;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Service\UserContext;
use Zend\EventManager\EventManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -25,13 +26,17 @@ class ChainServiceFactory implements FactoryInterface
$chain = new Chain();
/** @var UserContext $userContextService */
$userContextService = $container->get('AuthUserContext')->getSelectedIdentityRole();
$userContextService = $container->get('AuthUserContext');
/* @var $authorizeService Authorize */
$authorizeService = $container->get('BjyAuthorize\Service\Authorize');
/** @var EventManager $eventManager */
$eventManager = $container->get('EventManager');
$chain->setUserContextService($userContextService);
$chain->setAuthorizeService($authorizeService);
$chain->setEventManager($eventManager);
$providers = $this->computeProviders($container);
......
<?php
/**
* BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
*
* @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace UnicaenAuth\Service;
......
<?php
/**
* BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
*
* @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace UnicaenAuth\Service;
use BjyAuthorize\Provider\Identity\ProviderInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -24,16 +19,21 @@ class AuthorizeServiceFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new AuthorizeService($container->get('BjyAuthorize\Config'), $container);
// /** @var ProviderInterface $identityProvider */
// $identityProvider = $container->get('BjyAuthorize\Provider\Identity\ProviderInterface');
/** @var UserContext $serviceUserContext */
$serviceUserContext = $container->get('UnicaenAuth\Service\UserContext');
$service->setServiceUserContext($serviceUserContext);
// $service->setIdentityProvider($identityProvider);
return $service;
}
......
......@@ -150,7 +150,7 @@ class User implements EventManagerAwareInterface
$event->setShibUser($userData);
}
$this->getEventManager()->trigger($event);
$this->getEventManager()->triggerEvent($event);
}
/**
......
......@@ -351,7 +351,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
$event
->setRole($role)
->setTarget($this);
$this->getEventManager()->trigger($event);
$this->getEventManager()->triggerEvent($event);
}
/**
......
......@@ -2,19 +2,19 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\View\HelperPluginManager;
class LdapConnectViewHelperFactory
{
/**
* @param HelperPluginManager $hpm
* @param ContainerInterface $container
* @return LdapConnectViewHelper
*/
public function __invoke(HelperPluginManager $hpm)
public function __invoke(ContainerInterface $container)
{
/** @var ModuleOptions $moduleOptions */
$moduleOptions = $hpm->get('unicaen-auth_module_options');
$moduleOptions = $container->get('unicaen-auth_module_options');
$ldapArrayConfig = $moduleOptions->getLdap();
$ldapEnabled = isset($ldapArrayConfig['enabled']) && (bool) $ldapArrayConfig['enabled'];
......
......@@ -2,19 +2,19 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\View\HelperPluginManager;
class LocalConnectViewHelperFactory
{
/**
* @param HelperPluginManager $hpm
* @param ContainerInterface $container
* @return LocalConnectViewHelper
*/
public function __invoke(HelperPluginManager $hpm)
public function __invoke(ContainerInterface $container)
{
/** @var ModuleOptions $moduleOptions */
$moduleOptions = $hpm->get('unicaen-auth_module_options');
$moduleOptions = $container->get('unicaen-auth_module_options');
$config = $moduleOptions->getLocal();
$enabled = isset($config['enabled']) && (bool) $config['enabled'];
......
......@@ -2,19 +2,19 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Service\ShibService;
use Zend\View\HelperPluginManager;
class ShibConnectViewHelperFactory
{
/**
* @param HelperPluginManager $hpm
* @param ContainerInterface $container
* @return ShibConnectViewHelper
*/
public function __invoke(HelperPluginManager $hpm)
public function __invoke(ContainerInterface $container)
{
/** @var ShibService $shibService */
$shibService = $hpm->get(ShibService::class);
$shibService = $container->get(ShibService::class);
$helper = new ShibConnectViewHelper();
$helper->setShibService($shibService);
......
......@@ -2,8 +2,8 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Service\UserContext;
use Zend\View\HelperPluginManager;
/**
* Description of UserProfileFactory
......@@ -15,12 +15,12 @@ class UserProfileSelectFactory
/**
* Create service
*
* @param HelperPluginManager $helperPluginManager
* @param ContainerInterface $container
* @return UserProfileSelect
*/
public function __invoke(HelperPluginManager $helperPluginManager)
public function __invoke(ContainerInterface $container)
{
$serviceLocator = $helperPluginManager;
$serviceLocator = $container;
/** @var UserContext $userContextService */
$userContextService = $serviceLocator->get('AuthUserContext');
......
......@@ -2,8 +2,8 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Service\UserContext;
use Zend\View\HelperPluginManager;
/**
*
......@@ -15,12 +15,12 @@ class UserProfileSelectRadioItemFactory
/**
* Create service
*
* @param HelperPluginManager $helperPluginManager
* @param ContainerInterface $container
* @return UserProfileSelectRadioItem
*/
public function __invoke(HelperPluginManager $helperPluginManager)
public function __invoke(ContainerInterface $container)
{
$serviceLocator = $helperPluginManager;
$serviceLocator = $container;
/** @var UserContext $userContextService */
$userContextService = $serviceLocator->get('AuthUserContext');
......
......@@ -2,28 +2,28 @@
namespace UnicaenAuth\View\Helper;
use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\UserContext;
use Zend\View\Helper\Url;
use Zend\View\HelperPluginManager;
class UserUsurpationHelperFactory
{
/**
* @param HelperPluginManager $hpm
* @param ContainerInterface $container
* @return UserUsurpationHelper
*/
public function __invoke(HelperPluginManager $hpm)
public function __invoke(ContainerInterface $container)
{
/** @var Url $urlHelper */
$urlHelper = $hpm->get('url');
$urlHelper = $container->get('ViewHelperManager')->get('url');
$url = $urlHelper->__invoke('utilisateur/default', ['action' => 'usurper-identite']);
/** @var UserContext $userContextService */
$userContextService = $hpm->get('authUserContext');
$userContextService = $container->get('AuthUserContext');
/** @var ModuleOptions $moduleOptions */
$moduleOptions = $hpm->get('unicaen-auth_module_options');
$moduleOptions = $container->get('unicaen-auth_module_options');
$usurpationAllowed = in_array(
$userContextService->getIdentityUsername(),
......
Markdown is supported
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