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

Correction de bug lorsqu'on veut utiliser des règles sans fixer de privilège

parent 26f0b32c
......@@ -3,6 +3,8 @@
namespace UnicaenAuth\Provider\Rule;
use BjyAuthorize\Provider\Rule\ProviderInterface;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Privilege\Privileges;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use UnicaenAuth\Provider\Privilege\PrivilegeProviderAwareTrait;
......@@ -42,16 +44,16 @@ class PrivilegeRuleProvider implements ProviderInterface
foreach ($config as $grant => $rules) {
foreach ($rules as $index => $rule) {
if (is_array($rule)) {
$privileges = (array)$rule['privileges'];
$privileges = isset($rule['privileges']) ? (array)$rule['privileges'] : [];
$ressources = $rule['resources'];
$assertion = isset($rule['assertion']) ? $rule['assertion'] : null;
$bjyRoles = isset($rule['roles']) ? (array)$rule['roles'] : [];
foreach ($pr as $privilege => $roles) {
if (in_array($privilege, $privileges)) {
$bjyRoles = array_unique(array_merge($bjyRoles, $roles));
}
}
$bjyRule = [
$bjyRoles,
$ressources,
......@@ -60,15 +62,18 @@ class PrivilegeRuleProvider implements ProviderInterface
if ($assertion) $bjyRule[3] = $assertion;
$config[$grant][$index] = $bjyRule;
}
}
}
// Mise en place des droits pour tester les privilèges en tant que ressources
$rules = $config;
if (!isset($rules['allow'])) $rules['allow'] = [];
foreach ($pr as $privilege => $roles) {
$rules[empty($roles) ? 'deny' : 'allow'][] = [
$roles,
'privilege/' . $privilege,
Privileges::getResourceId($privilege),
];
}
......
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