From 6bf68abde26d972c2a9165f73b5b8c40301650d3 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 5 Jul 2023 21:46:33 +0330 Subject: [PATCH 1/3] refactor core/Middleware Signed-off-by: Hamid Dehnavi --- core/Middleware/TwoFactorMiddleware.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/Middleware/TwoFactorMiddleware.php b/core/Middleware/TwoFactorMiddleware.php index f421528dff718..b188510a13305 100644 --- a/core/Middleware/TwoFactorMiddleware.php +++ b/core/Middleware/TwoFactorMiddleware.php @@ -59,8 +59,11 @@ public function __construct( /** * @param Controller $controller * @param string $methodName + * @throws TwoFactorAuthRequiredException + * @throws UserAlreadyLoggedInException + * @throws Exception */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($this->reflector->hasAnnotation('NoTwoFactorRequired')) { // Route handler explicitly marked to work without finished 2FA are // not blocked @@ -111,7 +114,11 @@ public function beforeController($controller, $methodName) { // TODO: dont check/enforce 2FA if a auth token is used } - private function checkTwoFactor(Controller $controller, $methodName, IUser $user) { + /** + * @throws UserAlreadyLoggedInException + * @throws TwoFactorAuthRequiredException + */ + private function checkTwoFactor(Controller $controller, $methodName, IUser $user): void { // If two-factor auth is in progress disallow access to any controllers // defined within "LoginController". $needsSecondFactor = $this->twoFactorManager->needsSecondFactor($user); @@ -129,7 +136,7 @@ private function checkTwoFactor(Controller $controller, $methodName, IUser $user } } - public function afterException($controller, $methodName, Exception $exception) { + public function afterException($controller, $methodName, Exception $exception): RedirectResponse { if ($exception instanceof TwoFactorAuthRequiredException) { $params = []; if (isset($this->request->server['REQUEST_URI'])) { From 1efe84d732328ac014b7003f6a01645fd031793e Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Tue, 18 Jul 2023 12:11:45 +0330 Subject: [PATCH 2/3] Update core/Middleware/TwoFactorMiddleware.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Middleware/TwoFactorMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Middleware/TwoFactorMiddleware.php b/core/Middleware/TwoFactorMiddleware.php index b188510a13305..d9c5c12aac410 100644 --- a/core/Middleware/TwoFactorMiddleware.php +++ b/core/Middleware/TwoFactorMiddleware.php @@ -118,7 +118,7 @@ public function beforeController(Controller $controller, string $methodName): vo * @throws UserAlreadyLoggedInException * @throws TwoFactorAuthRequiredException */ - private function checkTwoFactor(Controller $controller, $methodName, IUser $user): void { + private function checkTwoFactor(Controller $controller, string $methodName, IUser $user): void { // If two-factor auth is in progress disallow access to any controllers // defined within "LoginController". $needsSecondFactor = $this->twoFactorManager->needsSecondFactor($user); From c54570b407e94726a7f3ece3eb2504837cd86016 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Tue, 18 Jul 2023 12:11:50 +0330 Subject: [PATCH 3/3] Update core/Middleware/TwoFactorMiddleware.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Middleware/TwoFactorMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Middleware/TwoFactorMiddleware.php b/core/Middleware/TwoFactorMiddleware.php index d9c5c12aac410..89351d25daac0 100644 --- a/core/Middleware/TwoFactorMiddleware.php +++ b/core/Middleware/TwoFactorMiddleware.php @@ -136,7 +136,7 @@ private function checkTwoFactor(Controller $controller, string $methodName, IUse } } - public function afterException($controller, $methodName, Exception $exception): RedirectResponse { + public function afterException(Controller $controller, string $methodName, Exception $exception): RedirectResponse { if ($exception instanceof TwoFactorAuthRequiredException) { $params = []; if (isset($this->request->server['REQUEST_URI'])) {