Skip to content
Snippets Groups Projects
Commit 1a8232a4 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Ajour d'un Fournisseur de rôle retournant le rôle correspondant à...

Ajour d'un Fournisseur de rôle retournant le rôle correspondant à l'identifiant de connexion de d'utilisateur (username).
Cela est utile lorsque l'on veut gérer les habilitations d'un utilisateur unique sur des ressources.
parent 55a9cb1c
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,12 @@ $bjyauthorize = array(
'object_manager' => 'doctrine.entitymanager.orm_default',
'role_entity_class' => 'UnicaenAuth\Entity\Db\Role',
),
/**
* Fournit le rôle correspondant à l'identifiant de connexion de l'utilisateur.
* Cela est utile lorsque l'on veut gérer les habilitations d'un utilisateur unique
* sur des ressources.
*/
'UnicaenAuth\Provider\Role\Username' => array(),
),
// strategy service name for the strategy listener to be used when permission-related errors are detected
......@@ -175,6 +181,7 @@ return array(
'UnicaenAuth\Provider\Identity\Db' => 'UnicaenAuth\Provider\Identity\DbServiceFactory',
'UnicaenAuth\Provider\Role\Config' => 'UnicaenAuth\Provider\Role\ConfigServiceFactory',
'UnicaenAuth\Provider\Role\DbRole' => 'UnicaenAuth\Provider\Role\DbRoleServiceFactory',
'UnicaenAuth\Provider\Role\Username' => 'UnicaenAuth\Provider\Role\UsernameServiceFactory',
),
),
'controllers' => array(
......
......@@ -39,6 +39,7 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider
if ($identity instanceof User) {
$roles = $identity->getRoles();
$roles[] = $identity->getUsername();
}
else {
$roles = array();
......
......@@ -39,6 +39,7 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider//
if ($identity instanceof People) {
$roles = $identity->getRoles();
$roles[] = $identity->getUsername();
}
else {
$roles = array();
......
<?php
namespace UnicaenAuth\Provider\Role;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Zend\Authentication\AuthenticationService;
use ZfcUser\Entity\UserInterface;
/**
* Fournisseur de rôle retournant le rôle correspondant à l'identifiant de connexion
* de d'utilisateur (username).
*
* Cela est utile lorsque l'on veut gérer les habilitations d'un utilisateur unique
* sur des ressources.
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class Username implements ProviderInterface
{
/**
* @var AuthenticationService
*/
protected $authService;
/**
* @var array
*/
protected $roles;
/**
*
* @param AuthenticationService $authService
*/
public function __construct(AuthenticationService $authService)
{
$this->authService = $authService;
}
/**
* @return \Zend\Permissions\Acl\Role\RoleInterface[]
*/
public function getRoles()
{
if (null === $this->roles) {
$this->roles = array();
if ($this->authService->hasIdentity()) {
$identity = $this->authService->getIdentity();
if (isset($identity['ldap'])) {
$identity = $identity['ldap'];
}
elseif (isset($identity['db'])) {
$identity = $identity['db'];
}
if ($identity instanceof UserInterface) {
$role = new \UnicaenAuth\Acl\NamedRole($identity->getUsername(), 'user', "Authentifié(e)");
$this->roles[] = $role;
}
}
}
return $this->roles;
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\Provider\Role;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UsernameServiceFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UsernameServiceFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Username
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$authService = $serviceLocator->get('zfcuser_auth_service'); /* @var $authService \Zend\Authentication\AuthenticationService */
return new Username($authService);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment