Module.php 7.94 KB
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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();
        
60
61
62
63
        // transmission des ACL aux aides de vue de navigation
        $authorizeService = $services->get('BjyAuthorize\Service\Authorize'); /* @var $authorizeService \BjyAuthorize\Service\Authorize */
        \Zend\View\Helper\Navigation::setDefaultAcl($authorizeService->getAcl());
        \Zend\View\Helper\Navigation::setDefaultRole($authorizeService->getIdentity());
Bertrand Gauthier's avatar
Bertrand Gauthier committed
64
65
66
67
68

        /* @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
Bertrand Gauthier's avatar
Bertrand Gauthier committed
69
        if ($options->getCas()) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
70
71
72
73
74
75
76
77
            /* @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(
Bertrand Gauthier's avatar
Bertrand Gauthier committed
78
                        'route' => '/auth',
Bertrand Gauthier's avatar
Bertrand Gauthier committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
                        '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'));
                },
133
134
                'userProfile' => function (HelperPluginManager $sm) {
                    $helper = new View\Helper\UserProfile($sm->getServiceLocator()->get('zfcuser_auth_service'));
Bertrand Gauthier's avatar
Bertrand Gauthier committed
135
//                    $helper->setIdentityProvider($sm->getServiceLocator()->get('BjyAuthorize\Service\Authorize')->getIdentityProvider());
136
137
                    return $helper;
                },
Bertrand Gauthier's avatar
Bertrand Gauthier committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
                '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(
Bertrand Gauthier's avatar
Bertrand Gauthier committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//                '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();
//                },
Bertrand Gauthier's avatar
Bertrand Gauthier committed
175
176
177
                'unicaen-auth_user_service' => function () {
                    return new Service\User();
                },
Bertrand Gauthier's avatar
Bertrand Gauthier committed
178
179
180
181
182
183
184
185
186
187
188
189
//                'zfcuser_auth_service' => function ($sm) {
//                    return new \Zend\Authentication\AuthenticationService(
//                        $sm->get('UnicaenAuth\Authentication\Storage\Mixed'),
//                        $sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
//                    );
//                },
//                '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;
//                },
Bertrand Gauthier's avatar
Bertrand Gauthier committed
190
191
192
193
                'ZfcUser\Authentication\Adapter\AdapterChain' => 'UnicaenAuth\Authentication\Adapter\AdapterChainServiceFactory',
            ),
        );
    }
194
}