Commit 124850bb authored by Bertrand Gauthier's avatar Bertrand Gauthier

Merge branch 'zf-3.x'

parents 2ed36d74 6973a6e4
Pipeline #5257 failed with stage
in 9 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.
......@@ -118,7 +118,21 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
public function getServiceConfig()
{
return [
//========== repris du module zf-commons/zfc-user-doctrine-orm abandonné =========
'aliases' => array(
'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager',
),
//===========================================
'factories' => [
//========== repris du module zf-commons/zfc-user-doctrine-orm abandonné =========
'zfcuser_module_options' => function ($sm) {
$config = $sm->get('Configuration');
return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
},
//===========================================
// verrue pour forcer le label de l'identifiant qqsoit l'options 'auth_identity_fields'
'zfcuser_login_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
......
This diff is collapsed.
<?php
use UnicaenAuth\Authentication\Storage\DbFactory;
use UnicaenAuth\Authentication\Storage\LdapFactory;
use UnicaenAuth\Authentication\Storage\ShibFactory;
use UnicaenAuth\Controller\AuthControllerFactory;
use UnicaenAuth\Controller\DroitsControllerFactory;
use UnicaenAuth\Controller\UtilisateurControllerFactory;
use UnicaenAuth\Form\Droits\RoleFormFactory;
use UnicaenAuth\Guard\PrivilegeControllerFactory;
use UnicaenAuth\Guard\PrivilegeRouteFactory;
use UnicaenAuth\Provider\Rule\PrivilegeRuleProviderFactory;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\ShibServiceFactory;
use UnicaenAuth\Service\UserContextFactory;
use UnicaenAuth\Service\UserFactory;
use UnicaenAuth\Service\UserMapperFactory;
use UnicaenAuth\View\Helper\LdapConnectViewHelper;
use UnicaenAuth\View\Helper\LdapConnectViewHelperFactory;
use UnicaenAuth\View\Helper\LocalConnectViewHelper;
use UnicaenAuth\View\Helper\LocalConnectViewHelperFactory;
use UnicaenAuth\View\Helper\ShibConnectViewHelper;
use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory;
use UnicaenAuth\View\Helper\UserConnection;
use UnicaenAuth\View\Helper\UserConnectionFactory;
use UnicaenAuth\View\Helper\UserCurrent;
use UnicaenAuth\View\Helper\UserCurrentFactory;
use UnicaenAuth\View\Helper\UserInfo;
use UnicaenAuth\View\Helper\UserInfoFactory;
use UnicaenAuth\View\Helper\UserProfile;
use UnicaenAuth\View\Helper\UserProfileFactory;
use UnicaenAuth\View\Helper\UserProfileSelect;
use UnicaenAuth\View\Helper\UserProfileSelectFactory;
use UnicaenAuth\View\Helper\UserProfileSelectRadioItem;
use UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory;
use UnicaenAuth\View\Helper\UserStatus;
use UnicaenAuth\View\Helper\UserStatusFactory;
use UnicaenAuth\View\Helper\UserUsurpationHelper;
use UnicaenAuth\View\Helper\UserUsurpationHelperFactory;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\Proxy\LazyServiceFactory;
$settings = [
......@@ -140,22 +170,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'],
],
],
],
......@@ -411,20 +441,24 @@ return [
],
],
],
//
//( ! ) Warning: Declaration of
// Application\Service\UserContextServiceAwareTrait::setUserContextService(Application\Service\UserContextService $userContextService)
// should be compatible with
// UnicaenAuth\Controller\UtilisateurController::setUserContextService(UnicaenAuth\Service\UserContext $userContextService)
// in /var/www/sygal/module/Application/src/Application/Controller/UtilisateurController.php on line 34
'service_manager' => [
'aliases' => [
'Zend\Authentication\AuthenticationService' => 'zfcuser_auth_service',
'UnicaenAuth\Privilege\PrivilegeProvider' => 'UnicaenAuth\Service\Privilege',
'\UnicaenAuth\Guard\PrivilegeController' => 'UnicaenAuth\Guard\PrivilegeController',
'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\Authentication\Storage\Db' => 'UnicaenAuth\Authentication\Storage\Db',
'UnicaenAuth\Authentication\Storage\Ldap' => 'UnicaenAuth\Authentication\Storage\Ldap',
'UnicaenAuth\Authentication\Storage\Shib' => 'UnicaenAuth\Authentication\Storage\Shib',
'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy',
'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User',
'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService',
],
'abstract_factories' => [
......@@ -449,6 +483,24 @@ return [
'UnicaenAuth\Service\UserContext' => UserContextFactory::class,
'zfcuser_user_mapper' => UserMapperFactory::class,
'MouchardCompleterAuth' => 'UnicaenAuth\Mouchard\MouchardCompleterAuthFactory',
'UnicaenAuth\Authentication\Storage\Db' => DbFactory::class,
'UnicaenAuth\Authentication\Storage\Ldap' => LdapFactory::class,
'UnicaenAuth\Authentication\Storage\Shib' => ShibFactory::class,
'UnicaenAuth\Service\User' => UserFactory::class,
'UnicaenAuth\Guard\PrivilegeController' => PrivilegeControllerFactory::class,
'UnicaenAuth\Guard\PrivilegeRoute' => PrivilegeRouteFactory::class,
'UnicaenAuth\Provider\Rule\PrivilegeRuleProvider' => PrivilegeRuleProviderFactory::class,
],
'lazy_services' => [
// Mapping services to their class names is required since the ServiceManager is not a declarative DIC.
'class_map' => [
'zfcuser_auth_service' => AuthenticationService::class,
],
],
'delegators' => [
'zfcuser_auth_service' => [
LazyServiceFactory::class,
],
],
'shared' => [
'MouchardCompleterAuth' => false,
......@@ -460,33 +512,48 @@ return [
'controllers' => [
'invokables' => [
'UnicaenAuth\Controller\Utilisateur' => 'UnicaenAuth\Controller\UtilisateurController',
'UnicaenAuth\Controller\Droits' => 'UnicaenAuth\Controller\DroitsController',
],
'factories' => [
'UnicaenAuth\Controller\Auth' => AuthControllerFactory::class,
'UnicaenAuth\Controller\Utilisateur' => UtilisateurControllerFactory::class,
'UnicaenAuth\Controller\Droits' => DroitsControllerFactory::class,
],
],
'form_elements' => [
'invokables' => [
'UnicaenAuth\Form\Droits\Role' => 'UnicaenAuth\Form\Droits\RoleForm',
],
'factories' => [
'UnicaenAuth\Form\Droits\Role' => RoleFormFactory::class,
],
],
'view_helpers' => [
'aliases' => [
'userConnection' => UserConnection::class,
'userCurrent' => UserCurrent::class,
'userStatus' => UserStatus::class,
'userProfile' => UserProfile::class,
'userInfo' => UserInfo::class,
'userProfileSelect' => UserProfileSelect::class,
'userProfileSelectRadioItem' => UserProfileSelectRadioItem::class,
'userUsurpation' => UserUsurpationHelper::class,
'localConnect' => LocalConnectViewHelper::class,
'ldapConnect' => LdapConnectViewHelper::class,
'shibConnect' => ShibConnectViewHelper::class,
],
'factories' => [
'userConnection' => 'UnicaenAuth\View\Helper\UserConnectionFactory',
'userCurrent' => 'UnicaenAuth\View\Helper\UserCurrentFactory',
'userStatus' => 'UnicaenAuth\View\Helper\UserStatusFactory',
'userProfile' => 'UnicaenAuth\View\Helper\UserProfileFactory',
'userInfo' => 'UnicaenAuth\View\Helper\UserInfoFactory',
'userProfileSelect' => 'UnicaenAuth\View\Helper\UserProfileSelectFactory',
'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory',
'userUsurpation' => UserUsurpationHelperFactory::class,
'localConnect' => LocalConnectViewHelperFactory::class,
'ldapConnect' => LdapConnectViewHelperFactory::class,
'shibConnect' => ShibConnectViewHelperFactory::class,
UserConnection::class => UserConnectionFactory::class,
UserCurrent::class => UserCurrentFactory::class,
UserStatus::class => UserStatusFactory::class,
UserProfile::class => UserProfileFactory::class,
UserInfo::class => UserInfoFactory::class,
UserProfileSelect::class => UserProfileSelectFactory::class,
UserProfileSelectRadioItem::class => UserProfileSelectRadioItemFactory::class,
UserUsurpationHelper::class => UserUsurpationHelperFactory::class,
LocalConnectViewHelper::class => LocalConnectViewHelperFactory::class,
LdapConnectViewHelper::class => LdapConnectViewHelperFactory::class,
ShibConnectViewHelper::class => ShibConnectViewHelperFactory::class,
],
'invokables' => [
'appConnection' => 'UnicaenAuth\View\Helper\AppConnection',
......
......@@ -35,7 +35,7 @@ La commande ci-dessus fonctionne seulement si le binaire composer.phar se trouve
'modules' => array(
'Application',
'ZfcBase', 'DoctrineModule', 'DoctrineORMModule', 'ZfcUser', 'ZfcUserDoctrineORM', 'BjyAuthorize',
'ZfcBase', 'DoctrineModule', 'DoctrineORMModule', 'ZfcUser', 'BjyAuthorize',
'UnicaenApp', 'AssetManager',
'UnicaenAuth',
// ...
......
<?php
translate("Username");
translate("Password");
translate("Email");
translate("Display Name");
translate("Password Verify");
translate("Authentication failed. Please try again.");
\ No newline at end of file
_("Username");
_("Password");
_("Email");
_("Display Name");
_("Password Verify");
_("Authentication failed. Please try again.");
\ No newline at end of file
......@@ -3,16 +3,15 @@
namespace UnicaenAuth\Assertion;
use BjyAuthorize\Service\Authorize;
use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface;
use UnicaenApp\ServiceManager\ServiceLocatorAwareTrait;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\Plugin\FlashMessenger;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Assertion\AssertionInterface;
use Zend\Permissions\Acl\Resource\ResourceInterface;
use Zend\Permissions\Acl\Role\RoleInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
/**
* Description of AbstractAssertion
......@@ -296,44 +295,63 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw
return true;
}
/**
* @var MvcEvent
*/
private $mvcEvent;
/**
* @param MvcEvent $mvcEvent
*/
public function setMvcEvent(MvcEvent $mvcEvent)
{
$this->mvcEvent = $mvcEvent;
}
/**
* @return MvcEvent
*/
protected function getMvcEvent()
{
$application = $this->getServiceLocator()->get('Application');
/* @var $application Application */
return $application->getMvcEvent();
return $this->mvcEvent;
}
/**
* @var Authorize
*/
private $serviceAuthorize;
/**
* @param Authorize $serviceAuthorize
*/
public function setServiceAuthorize(Authorize $serviceAuthorize)
{
$this->serviceAuthorize = $serviceAuthorize;
}
/**
* @return Authorize
*/
private function getServiceAuthorize()
{
$serviceAuthorize = $this->getServiceLocator()->get('BjyAuthorize\Service\Authorize');
/* @var $serviceAuthorize Authorize */
return $serviceAuthorize;
return $this->serviceAuthorize;
}
/**
* @param FlashMessenger $fm
* @deprecated Merci d'abandonner cette méthode : SoC violation !
*/
public function setFlashMessenger(FlashMessenger $fm)
{
$this->fm = $fm;
}
/**
* @return FlashMessenger
* @deprecated Merci d'abandonner cette méthode : SoC violation !
*/
protected function flashMessenger()
{
if (!$this->fm){
$this->fm = $this->getServiceLocator()->get('controllerpluginmanager')->get('flashmessenger');
}
return $this->fm;
}
}
\ No newline at end of file
......@@ -2,11 +2,16 @@
namespace UnicaenAuth\Authentication\Adapter;
use Interop\Container\ContainerInterface;
use UnicaenApp\Exception\LogicException;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\User;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\Router\Http\TreeRouteStack;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper;
/**
* Description of AbstractFactory
......@@ -15,28 +20,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':
......@@ -59,14 +58,69 @@ class AbstractFactory implements AbstractFactoryInterface
break;
}
$this->injectDependencies($adapter, $container);
if ($adapter instanceof EventManagerAwareInterface) {
/** @var EventManager $eventManager */
$eventManager = $serviceLocator->get('event_manager');
$eventManager = $container->get('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);
}
return $adapter;
}
/**
* @param Ldap|Db|Cas $adapter
* @param ContainerInterface $container
*/
private function injectDependencies($adapter, ContainerInterface $container)
{
switch (true) {
case $adapter instanceof Ldap:
/** @var User $userService */
$userService = $container->get('unicaen-auth_user_service');
$adapter->setUserService($userService);
/** @var LdapPeopleMapper $ldapPeopleMapper */
$ldapPeopleMapper = $container->get('ldap_people_mapper');
$adapter->setLdapPeopleMapper($ldapPeopleMapper);
$options = array_merge(
$container->get('zfcuser_module_options')->toArray(),
$container->get('unicaen-auth_module_options')->toArray());
$adapter->setOptions(new ModuleOptions($options));
/** @var \UnicaenApp\Options\ModuleOptions $appModuleOptions */
$appModuleOptions = $container->get('unicaen-app_module_options');
$adapter->setAppModuleOptions($appModuleOptions);
break;
case $adapter instanceof Cas:
/** @var User $userService */
$userService = $container->get('unicaen-auth_user_service');
$adapter->setUserService($userService);
/** @var TreeRouteStack $router */
$router = $container->get('router');
$adapter->setRouter($router);
$options = array_merge(
$container->get('zfcuser_module_options')->toArray(),
$container->get('unicaen-auth_module_options')->toArray());
$adapter->setOptions(new ModuleOptions($options));
/** @var LdapPeopleMapper $ldapPeopleMapper */
$ldapPeopleMapper = $container->get('ldap_people_mapper');
$adapter->setLdapPeopleMapper($ldapPeopleMapper);
break;
default:
break;
}
}
}
\ No newline at end of file
......@@ -8,14 +8,13 @@ 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\EventInterface;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\Router\Http\TreeRouteStack;
use ZfcUser\Authentication\Adapter\AbstractAdapter;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
use ZfcUser\Authentication\Adapter\ChainableAdapter;
/**
......@@ -23,13 +22,8 @@ use ZfcUser\Authentication\Adapter\ChainableAdapter;
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, EventManagerAwareInterface
class Cas extends AbstractAdapter implements EventManagerAwareInterface
{
/**
* @var ServiceManager
*/
protected $serviceManager;
/**
* @var EventManager
*/
......@@ -55,16 +49,46 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event
*/
protected $ldapPeopleMapper;
/**
* @var User
*/
private $userService;
/**
* @param User $userService
*/
public function setUserService(User $userService)
{
$this->userService = $userService;
}
/**