DbServiceFactory.php 1.21 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Provider\Identity;

5
6
use UnicaenApp\Options\ModuleOptions;
use Zend\Ldap\Ldap;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Db identity provider factory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
 */
class DbServiceFactory implements FactoryInterface
{
    /**
     * {@inheritDoc}
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
22
23
24
25
26
27
28
29
        $user             = $serviceLocator->get('zfcuser_user_service');
        $identityProvider = new Db($user->getAuthService());

        $unicaenAppOptions = $serviceLocator->get('unicaen-app_module_options');
        /* @var $unicaenAppOptions ModuleOptions */

        $ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']);
        $identityProvider->setLdap($ldap);
30

31
32
33
        $identityProvider->setServiceRole($serviceLocator->get('UnicaenAuth\Service\Role'));

        $config            = $serviceLocator->get('BjyAuthorize\Config');
34
35
36
37
38
39
        $identityProvider->setDefaultRole($config['default_role']);
        $identityProvider->setAuthenticatedRole($config['authenticated_role']);

        return $identityProvider;
    }
}