Select Git revision
Bertrand Gauthier authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Module.php 8.27 KiB
<?php
namespace UnicaenAuth;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
use Zend\View\HelperPluginManager;
/**
* Point d'entrée du module d'authentification Unicaen.
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class Module implements ConfigProviderInterface, ViewHelperProviderInterface, ServiceProviderInterface
{
/**
*
* @return array
* @see ConfigProviderInterface
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
/**
*
* @return array
* @see AutoloaderProviderInterface
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
/**
* This method is called once the MVC bootstrapping is complete,
* after the "loadModule.post" event, once $application->bootstrap() is called.
*
* @param EventInterface $e
* @see BootstrapListenerInterface
*/
public function onBootstrap(\Zend\EventManager\EventInterface $e) /* @var \Zend\Mvc\MvcEvent $e */
{
$application = $e->getApplication();
/* @var $services \Zend\ServiceManager\ServiceManager */
$services = $application->getServiceManager();
// /* @var $vhm HelperPluginManager */
// $vhm = $services->get('view_helper_manager');
// /* @var $nvh Navigation */
// $nvh = $vhm->get('navigation');
// /* @var $authorizeService \BjyAuthorize\Service\Authorize */
// $authorizeService = $services->get('BjyAuthorize\Service\Authorize');
// $nvh->setAcl($authorizeService->getAcl())->setRole($authorizeService->getIdentity());
/* @var $options Options\ModuleOptions */
$options = $services->get('unicaen-auth_module_options');
// si l'auth CAS est demandée, modif de la route de connexion pour zapper le formulaire
if ($options->getCasAuthenticationActivated()) {
/* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */
$router = $services->get('router');
$router->addRoutes(array(
// remplace les routes existantes (cf. config du module)
'zfcuser' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/utilisateur',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'login' => array(
'type' => 'Literal',
'options' => array(
'route' => '/connexion',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'authenticate', // zappe l'action 'login'
),
),
),
'logout' => array(
'type' => 'Literal',
'options' => array(
'route' => '/deconnexion',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'logout',
),
),
),
),
)
));
}
}
/**
*
* @return array
* @see ViewHelperProviderInterface
*/
public function getViewHelperConfig()
{
return array(
'factories' => array(
'appConnection' => function (HelperPluginManager $sm) {
return new View\Helper\AppConnection();
},
'userConnection' => function (HelperPluginManager $sm) {
return new View\Helper\UserConnection($sm->getServiceLocator()->get('zfcuser_auth_service'));
},
'userCurrent' => function (HelperPluginManager $sm) {
return new View\Helper\UserCurrent($sm->getServiceLocator()->get('zfcuser_auth_service'));
},
'userStatus' => function (HelperPluginManager $sm) {
return new View\Helper\UserStatus($sm->getServiceLocator()->get('zfcuser_auth_service'));
},
'userProfile' => function (HelperPluginManager $sm) {
$helper = new View\Helper\UserProfile($sm->getServiceLocator()->get('zfcuser_auth_service'));
// $helper->setIdentityProvider($sm->getServiceLocator()->get('BjyAuthorize\Service\Authorize')->getIdentityProvider());
return $helper;
},
'userInfo' => function (HelperPluginManager $sm) {
$helper = new View\Helper\UserInfo($sm->getServiceLocator()->get('zfcuser_auth_service'));
$helper->setServiceStructure($sm->getServiceLocator()->get('ldap_structure_service'));
return $helper;
},
),
);
}
/**
*
* @return array
* @see ServiceProviderInterface
*/
public function getServiceConfig()
{
return array(
'factories' => array(
'unicaen-auth_module_options' => function($sm) {
$config = $sm->get('Configuration');
return new Options\ModuleOptions(isset($config['unicaen-auth']) ? $config['unicaen-auth'] : array());
},
'UnicaenAuth\Authentication\Adapter\Db' => function() {
return new Authentication\Adapter\Db();
},
'UnicaenAuth\Authentication\Adapter\Ldap' => function() {
return new Authentication\Adapter\Ldap();
},
'UnicaenAuth\Authentication\Adapter\Cas' => function() {
return new Authentication\Adapter\Cas();
},
'UnicaenAuth\Authentication\Storage\Db' => function() {
return new Authentication\Storage\Db();
},
'UnicaenAuth\Authentication\Storage\Ldap' => function() {
return new Authentication\Storage\Ldap();
},
'unicaen-auth_user_service' => function () {
return new Service\User();
},
'zfcuser_auth_service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
$sm->get('UnicaenAuth\Authentication\Storage\Mixed'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
},
'UnicaenAuth\View\UnauthorizedStrategy' => function (\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) {
$config = $serviceLocator->get('Config');
return new View\UnauthorizedStrategy($config['bjyauthorize']['template']);
},
'UnicaenAuth\Authentication\Storage\Mixed' => function($sm) {
$storage = new Authentication\Storage\Mixed();
$storage->setLdapStorage($sm->get('UnicaenAuth\Authentication\Storage\Ldap'))
->setDbStorage($sm->get('UnicaenAuth\Authentication\Storage\Db'));
return $storage;
},
'ZfcUser\Authentication\Adapter\AdapterChain' => 'UnicaenAuth\Authentication\Adapter\AdapterChainServiceFactory',
),
);
}
}