Skip to content
Snippets Groups Projects
Commit 0b51e685 authored by Conrad Lara's avatar Conrad Lara
Browse files

Issue #3487347 by rosk0, cmlara: Admin cannot disable TFA for a user

parent 96fe336f
Branches
Tags
1 merge request!99Issue #3487347 by rosk0, cmlara: Admin cannot disable TFA for a user
Pipeline #353807 failed
...@@ -92,6 +92,7 @@ final class TfaLoginController { ...@@ -92,6 +92,7 @@ final class TfaLoginController {
*/ */
public function accessSelfOrAdmin(RouteMatchInterface $route, AccountInterface $account): AccessResult { public function accessSelfOrAdmin(RouteMatchInterface $route, AccountInterface $account): AccessResult {
$target_user = $route->getParameter('user'); $target_user = $route->getParameter('user');
$permission = $route->getRouteObject()?->getOption('_tfa_permission');
// Start with a positive access result that can be cached based on the // Start with a positive access result that can be cached based on the
// current route, which includes both route name and parameters. // current route, which includes both route name and parameters.
...@@ -131,6 +132,18 @@ final class TfaLoginController { ...@@ -131,6 +132,18 @@ final class TfaLoginController {
} }
$is_admin = $account->hasPermission('administer tfa for other users'); $is_admin = $account->hasPermission('administer tfa for other users');
// Permission might not be there only on the "tfa.entry" route. Otherwise,
// must be present.
if ($is_self && isset($permission)) {
if (is_string($permission)) {
return $access->andIf(AccessResult::allowedIf($target_user->hasPermission($permission)));
}
else {
throw new \InvalidArgumentException('The "permission" parameter must be a string.');
}
}
$is_self_or_admin = AccessResult::allowedIf($is_self || $is_admin); $is_self_or_admin = AccessResult::allowedIf($is_self || $is_admin);
return $access->andIf($is_self_or_admin); return $access->andIf($is_self_or_admin);
......
...@@ -38,9 +38,9 @@ tfa.overview: ...@@ -38,9 +38,9 @@ tfa.overview:
_title: 'TFA' _title: 'TFA'
requirements: requirements:
_custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin' _custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin'
_permission: 'setup own tfa'
options: options:
_admin_route: TRUE _admin_route: TRUE
_tfa_permission: 'setup own tfa'
tfa.validation.setup: tfa.validation.setup:
path: '/user/{user}/security/tfa/{method}' path: '/user/{user}/security/tfa/{method}'
...@@ -49,9 +49,9 @@ tfa.validation.setup: ...@@ -49,9 +49,9 @@ tfa.validation.setup:
_title: 'TFA setup' _title: 'TFA setup'
requirements: requirements:
_custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin' _custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin'
_permission: 'setup own tfa'
options: options:
_admin_route: TRUE _admin_route: TRUE
_tfa_permission: 'setup own tfa'
tfa.disable: tfa.disable:
path: '/user/{user}/security/tfa/disable' path: '/user/{user}/security/tfa/disable'
...@@ -60,10 +60,10 @@ tfa.disable: ...@@ -60,10 +60,10 @@ tfa.disable:
_title: 'TFA disable' _title: 'TFA disable'
requirements: requirements:
_custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin' _custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin'
_permission: 'disable own tfa'
user: \d+ user: \d+
options: options:
_admin_route: TRUE _admin_route: TRUE
_tfa_permission: 'disable own tfa'
tfa.plugin.reset: tfa.plugin.reset:
path: '/user/{user}/security/tfa/{method}/{reset}' path: '/user/{user}/security/tfa/{method}/{reset}'
...@@ -72,6 +72,6 @@ tfa.plugin.reset: ...@@ -72,6 +72,6 @@ tfa.plugin.reset:
_title: 'TFA setup' _title: 'TFA setup'
requirements: requirements:
_custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin' _custom_access: '\Drupal\tfa\Controller\TfaLoginController::accessSelfOrAdmin'
_permission: 'setup own tfa'
options: options:
_admin_route: TRUE _admin_route: TRUE
_tfa_permission: 'setup own tfa'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment