Commit c94cb52c authored by Guillaume Wauquier's avatar Guillaume Wauquier
Browse files

simplication du Gendarme

parent 10906ff0
......@@ -55,9 +55,11 @@ class Gendarme implements AuthorizationCheckerInterface
if (!is_array($attribute)) {
$attribute = [$attribute];
}
foreach ($attribute as $attr) {
$role_simple = strlen($attr) === 7 ? substr($attr, 0, -1) : $attr;
$n = strlen($attr) === 7 ? (int)substr($attr, -1) : 0;
foreach ($tab_roles as $role) {
$matches = [];
......@@ -65,6 +67,7 @@ class Gendarme implements AuthorizationCheckerInterface
$niveau = (int)$matches[1];
}
}
$ok = $this->isGranted($role_simple) && ($n <= $niveau);
if ($ok) {
return $ok;
......@@ -106,28 +109,16 @@ class Gendarme implements AuthorizationCheckerInterface
if ($this->exceptionOnNoToken) {
throw new AuthenticationCredentialsNotFoundException('The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');
}
$token = new NullToken();
} else {
if ($this->alwaysAuthenticate || !$token->isAuthenticated()) {
$this->tokenStorage->setToken($token = $this->authenticationManager->authenticate($token));
}
}
if (!is_array($attributes)) {
$attributes = [$attributes];
}
$tab_lien = $this->sac->get('app.liens_role_objet');
$tab_attr = [];
foreach ($attributes as &$at) {
if (isset($tab_lien[$at])) {
foreach ($tab_lien[$at] as $a) {
$tab_attr[] = 'ROLE_' . $a;
}
}
}
return $this->accessDecisionManager->decide($token, ['ROLE_USER'], $subject);
return $this->accessDecisionManager->decide($token, $attributes, $subject);
}
......
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