Commit 3a328aee authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Ajout de la possibilité de filtrer par les routes plutôt que les les contrôleurs/actions

parent f1cc09e6
......@@ -2,7 +2,6 @@
namespace UnicaenAuth;
use UnicaenAuth\Guard\PrivilegeController;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
......@@ -12,7 +11,7 @@ use Zend\ModuleManager\Feature\ServiceProviderInterface;
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class Module implements ConfigProviderInterface, ServiceProviderInterface
class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
{
/**
*
......
......@@ -9,7 +9,7 @@ use UnicaenApp\Traits\SessionContainerTrait;
/**
* Description of ControllerGuard
* Description of PrivilegeController
*
* @author Laurent LECLUSE <laurent.lecluse at unicaen.fr>
*/
......@@ -30,9 +30,6 @@ class PrivilegeController extends Controller
protected function privilegesToRoles(array $rules)
{
// $session = $this->getSessionContainer();
// if (! isset($session->rules)){
$pr = $this->getPrivilegeProvider()->getPrivilegesRoles();
foreach ($rules as $index => $rule) {
......@@ -56,9 +53,6 @@ class PrivilegeController extends Controller
}
return $rules;
// $session->rules = $rules;
// }
// return $session->rules;
}
......
<?php
namespace UnicaenAuth\Guard;
use BjyAuthorize\Guard\Route;
use Zend\ServiceManager\ServiceLocatorInterface;
use UnicaenAuth\Provider\Privilege\PrivilegeProviderAwareTrait;
use UnicaenApp\Traits\SessionContainerTrait;
/**
* Description of PrivilegeRoute
*
* @author Laurent LECLUSE <laurent.lecluse at unicaen.fr>
*/
class PrivilegeRoute extends Route
{
use PrivilegeProviderAwareTrait;
use SessionContainerTrait;
public function __construct(array $rules, ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
parent::__construct($this->privilegesToRoles($rules), $serviceLocator);
}
protected function privilegesToRoles(array $rules)
{
$pr = $this->getPrivilegeProvider()->getPrivilegesRoles();
foreach ($rules as $index => $rule) {
if (isset($rule['privileges'])) {
$rolesCount = 0;
$privileges = (array)$rule['privileges'];
$rule['roles'] = isset($rule['roles']) ? (array)$rule['roles'] : [];
foreach ($pr as $privilege => $roles) {
if (in_array($privilege, $privileges)) {
$rolesCount += count($roles);
$rule['roles'] = array_unique(array_merge($rule['roles'], $roles));
}
}
unset($rule['privileges']);
if (0 < count($rule['roles'])) {
$rules[$index] = $rule;
}else{
unset($rules[$index]);
}
}
}
return $rules;
}
/**
* Pour récupérer le serviceLocator depuis les traits de service
*
* @return ServiceLocatorInterface
*/
protected function getServiceLocator()
{
return $this->serviceLocator;
}
public static function getResourceId($route)
{
return 'route/'.$route;
}
}
\ No newline at end of file
Markdown is supported
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