mirror of
https://github.com/nextcloud/server.git
synced 2026-03-21 10:00:33 -04:00
chore: Move away from deprecated method in TwoFactorMiddleware
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
91334643dc
commit
d68face43f
2 changed files with 5 additions and 7 deletions
|
|
@ -11,7 +11,6 @@ namespace OC\Core\Middleware;
|
|||
|
||||
use Exception;
|
||||
use OC\AppFramework\Http\Attributes\TwoFactorSetUpDoneRequired;
|
||||
use OC\AppFramework\Middleware\MiddlewareUtils;
|
||||
use OC\Authentication\Exceptions\TwoFactorAuthRequiredException;
|
||||
use OC\Authentication\Exceptions\UserAlreadyLoggedInException;
|
||||
use OC\Authentication\TwoFactorAuth\Manager;
|
||||
|
|
@ -23,6 +22,7 @@ use OCP\AppFramework\Controller;
|
|||
use OCP\AppFramework\Http\Attribute\NoTwoFactorRequired;
|
||||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
||||
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
|
@ -36,7 +36,7 @@ class TwoFactorMiddleware extends Middleware {
|
|||
private Session $userSession,
|
||||
private ISession $session,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private MiddlewareUtils $middlewareUtils,
|
||||
private IControllerMethodReflector $reflector,
|
||||
private IRequest $request,
|
||||
) {
|
||||
}
|
||||
|
|
@ -46,9 +46,7 @@ class TwoFactorMiddleware extends Middleware {
|
|||
* @param string $methodName
|
||||
*/
|
||||
public function beforeController($controller, $methodName) {
|
||||
$reflectionMethod = new ReflectionMethod($controller, $methodName);
|
||||
|
||||
if ($this->middlewareUtils->hasAnnotationOrAttribute($reflectionMethod, 'NoTwoFactorRequired', NoTwoFactorRequired::class)) {
|
||||
if ($this->reflector->hasAnnotationOrAttribute('NoTwoFactorRequired', NoTwoFactorRequired::class)) {
|
||||
// Route handler explicitly marked to work without finished 2FA are
|
||||
// not blocked
|
||||
return;
|
||||
|
|
@ -59,6 +57,7 @@ class TwoFactorMiddleware extends Middleware {
|
|||
return;
|
||||
}
|
||||
|
||||
$reflectionMethod = new ReflectionMethod($controller, $methodName);
|
||||
if ($controller instanceof TwoFactorChallengeController
|
||||
&& $this->userSession->getUser() !== null
|
||||
&& !$reflectionMethod->getAttributes(TwoFactorSetUpDoneRequired::class)) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ namespace Test\Core\Middleware;
|
|||
|
||||
use OC\AppFramework\Http\Attributes\TwoFactorSetUpDoneRequired;
|
||||
use OC\AppFramework\Http\Request;
|
||||
use OC\AppFramework\Middleware\MiddlewareUtils;
|
||||
use OC\AppFramework\Utility\ControllerMethodReflector;
|
||||
use OC\Authentication\Exceptions\TwoFactorAuthRequiredException;
|
||||
use OC\Authentication\Exceptions\UserAlreadyLoggedInException;
|
||||
|
|
@ -102,7 +101,7 @@ class TwoFactorMiddlewareTest extends TestCase {
|
|||
$this->createMock(IConfig::class)
|
||||
);
|
||||
|
||||
$this->middleware = new TwoFactorMiddleware($this->twoFactorManager, $this->userSession, $this->session, $this->urlGenerator, new MiddlewareUtils($this->reflector, $this->logger), $this->request);
|
||||
$this->middleware = new TwoFactorMiddleware($this->twoFactorManager, $this->userSession, $this->session, $this->urlGenerator, $this->reflector, $this->request);
|
||||
}
|
||||
|
||||
public function testBeforeControllerNotLoggedIn(): void {
|
||||
|
|
|
|||
Loading…
Reference in a new issue