Skip to content
Snippets Groups Projects
Commit 81ccb133 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Possibilité de retourner la liste de tous les rôles issus de l'ensemble des...

Possibilité de retourner la liste de tous les rôles issus de l'ensemble des fournisseurs de rôles depuis le service Authorize "augmenté".

Utilisation de la liste pour retrouver un rôle à partir de son ID dans le UserContext.
parent b2842c20
Branches
Tags
No related merge requests found
...@@ -20,7 +20,7 @@ abstract class AbstractService implements ServiceLocatorAwareInterface ...@@ -20,7 +20,7 @@ abstract class AbstractService implements ServiceLocatorAwareInterface
/** /**
* @return \BjyAuthorize\Service\Authorize * @return \UnicaenAuth\Service\AuthorizeService
*/ */
protected function getServiceAuthorize() protected function getServiceAuthorize()
{ {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
namespace UnicaenAuth\Service; namespace UnicaenAuth\Service;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait; use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
/** /**
...@@ -26,11 +27,14 @@ class AuthorizeService extends \BjyAuthorize\Service\Authorize ...@@ -26,11 +27,14 @@ class AuthorizeService extends \BjyAuthorize\Service\Authorize
protected $loading; protected $loading;
public function getServiceLocator() public function getServiceLocator()
{ {
return $this->serviceLocator; return $this->serviceLocator;
} }
/** /**
* @deprecated this method will be removed in BjyAuthorize 1.4.x+, * @deprecated this method will be removed in BjyAuthorize 1.4.x+,
* please retrieve the identity from the * please retrieve the identity from the
...@@ -42,9 +46,30 @@ class AuthorizeService extends \BjyAuthorize\Service\Authorize ...@@ -42,9 +46,30 @@ class AuthorizeService extends \BjyAuthorize\Service\Authorize
{ {
$this->loaded && $this->loaded->__invoke(); $this->loaded && $this->loaded->__invoke();
if ($this->loading) return 'bjyauthorize-identity'; if ($this->loading) return 'bjyauthorize-identity';
return $this->getServiceUserContext()->getSelectedIdentityRole(); return $this->getServiceUserContext()->getSelectedIdentityRole();
} }
/**
* Retourne la liste des rôles fournis par l'ensemble des providers
*/
public function getRoles()
{
$roles = [];
foreach ($this->roleProviders as $provider) {
$r = $provider->getRoles();
foreach ($r as $role) {
$roles[$role->getRoleId()] = $role;
}
}
return $roles;
}
/** /**
* Initializes the service * Initializes the service
* *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace UnicaenAuth\Service; namespace UnicaenAuth\Service;
use BjyAuthorize\Acl\Role;
use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Traits\SessionContainerTrait; use UnicaenApp\Traits\SessionContainerTrait;
use UnicaenAuth\Provider\Identity\Chain; use UnicaenAuth\Provider\Identity\Chain;
...@@ -136,6 +137,7 @@ class UserContext extends AbstractService ...@@ -136,6 +137,7 @@ class UserContext extends AbstractService
*/ */
public function getSelectedIdentityRole() public function getSelectedIdentityRole()
{ {
if ($this->getNextSelectedIdentityRole()) { if ($this->getNextSelectedIdentityRole()) {
$this->getSessionContainer()->selectedIdentityRole = $this->getNextSelectedIdentityRole(); $this->getSessionContainer()->selectedIdentityRole = $this->getNextSelectedIdentityRole();
} }
...@@ -148,7 +150,14 @@ class UserContext extends AbstractService ...@@ -148,7 +150,14 @@ class UserContext extends AbstractService
$roleId = $this->getSessionContainer()->selectedIdentityRole; $roleId = $this->getSessionContainer()->selectedIdentityRole;
if ($roleId) { if ($roleId) {
$role = $this->normalizedIdentityRole($roleId);
$roles = $this->getServiceAuthorize()->getRoles(); // Récupération de tous les rôles du provider
if (isset($roles[$roleId])) {
$role = $roles[$roleId];
}else{
$role = null;
}
if ($this->isRoleValid($role)) { if ($this->isRoleValid($role)) {
return $role; return $role;
} }
...@@ -227,33 +236,6 @@ class UserContext extends AbstractService ...@@ -227,33 +236,6 @@ class UserContext extends AbstractService
/**
* Recherche le role spécifié parmi les rôles connus au format objets.
*
* @param RoleInterface|string $role
*
* @return RoleInterface Role trouvé au format objet dans la mesure du possible
*/
protected function normalizedIdentityRole($role)
{
if (!$role || is_object($role)) {
return $role;
}
foreach ($this->getIdentityRoles() as $r) {
if ($r instanceof RoleInterface && $role === $r->getRoleId()) {
return $r;
}
if ($role === $r) {
return $r;
}
}
return $role;
}
/** /**
* Teste si le rôle spécifié fait partie des rôles disponibles. * Teste si le rôle spécifié fait partie des rôles disponibles.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment