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
...@@ -71,10 +71,14 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan ...@@ -71,10 +71,14 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
if (!$registry->has($role)) { if (!$registry->has($role)) {
$role = $authorizeService->getAcl()->getRole($role); $role = $authorizeService->getAcl()->getRole($role);
$registry->add($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; return $this->roles;
} }
......
...@@ -22,6 +22,11 @@ class Username implements ProviderInterface ...@@ -22,6 +22,11 @@ class Username implements ProviderInterface
*/ */
protected $authService; protected $authService;
/**
* @var array
*/
protected $config = array();
/** /**
* @var array * @var array
*/ */
...@@ -30,10 +35,12 @@ class Username implements ProviderInterface ...@@ -30,10 +35,12 @@ class Username implements ProviderInterface
/** /**
* *
* @param AuthenticationService $authService * @param AuthenticationService $authService
* @param array $config
*/ */
public function __construct(AuthenticationService $authService) public function __construct(AuthenticationService $authService, $config = null)
{ {
$this->authService = $authService; $this->authService = $authService;
$this->config = $config;
} }
/** /**
...@@ -41,6 +48,10 @@ class Username implements ProviderInterface ...@@ -41,6 +48,10 @@ class Username implements ProviderInterface
*/ */
public function getRoles() public function getRoles()
{ {
if (isset($this->config['enabled']) && !$this->config['enabled']) {
return array();
}
if (null === $this->roles) { if (null === $this->roles) {
$this->roles = array(); $this->roles = array();
......
...@@ -20,8 +20,18 @@ class UsernameServiceFactory implements FactoryInterface ...@@ -20,8 +20,18 @@ class UsernameServiceFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $serviceLocator) 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 */ $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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment