Commit b7a0327b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Fournisseur de rôle Username :

- modif parent et libellé du rôle.
- ajout config permettant de désactiver la fourniture du rôle.

Fournisseur des rôles de l'identité authentifiée : supprime le role 'user' si un autre est collecté.
parent 1a8232a4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -71,10 +71,14 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
            if (!$registry->has($role)) {
                $role = $authorizeService->getAcl()->getRole($role);
                $registry->add($role);
                $this->roles[] = $role;
                $this->roles[$role->getRoleId()] = $role;
            }
        }
        
        if (count($registry->getRoles()) > 1 && $registry->has('user')) {
            unset($this->roles['user']);
        }
        
        return $this->roles;
    }
    
+12 −1
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ class Username implements ProviderInterface
     */
    protected $authService;
    
    /**
     * @var array
     */
    protected $config = array();
    
    /**
     * @var array
     */
@@ -30,10 +35,12 @@ class Username implements ProviderInterface
    /**
     * 
     * @param AuthenticationService $authService
     * @param array $config
     */
    public function __construct(AuthenticationService $authService)
    public function __construct(AuthenticationService $authService, $config = null)
    {
        $this->authService = $authService;
        $this->config      = $config;
    }
    
    /**
@@ -41,6 +48,10 @@ class Username implements ProviderInterface
     */
    public function getRoles()
    {
        if (isset($this->config['enabled']) && !$this->config['enabled']) {
            return array();
        }
        
        if (null === $this->roles) {
            $this->roles = array();
            
+11 −1
Original line number Diff line number Diff line
@@ -20,8 +20,18 @@ class UsernameServiceFactory implements FactoryInterface
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('BjyAuthorize\Config');

        if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Username'])) {
            throw new InvalidArgumentException(
                'Config for "UnicaenAuth\Provider\Role\Username" not set'
            );
        }

        $providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Username'];
        
        $authService = $serviceLocator->get('zfcuser_auth_service'); /* @var $authService \Zend\Authentication\AuthenticationService */
        
        return new Username($authService);
        return new Username($authService, $providerConfig);
    }
}
 No newline at end of file