Skip to content

Commit

Permalink
ENH Disable temporary sudo mode after login
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 11, 2025
1 parent 506aef4 commit dcb7304
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default:
- SilverStripe\Framework\Tests\Behaviour\CmsUiContext
- SilverStripe\BehatExtension\Context\BasicContext
- SilverStripe\BehatExtension\Context\EmailContext
- SilverStripe\BehatExtension\Context\FixtureContext
- '%paths.modules.silverstripe-mfa%/tests/Behat/features/files/'
- SilverStripe\MFA\Tests\Behat\Context\LoginContext
- SilverStripe\CMS\Tests\Behaviour\ThemeContext
extensions:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3",
"silverstripe/documentation-lint": "^1",
"silverstripe/frameworktest": "^1",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
},
Expand Down
7 changes: 7 additions & 0 deletions src/Authenticator/LoginHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ public function redirectAfterSuccessfulLogin(): HTTPResponse
}
$request->getSession()->clear(static::SESSION_KEY . '.mustLogin');

// Deactivate sudo mode that was activated in doLogin()
$service = $this->getSudoModeService();
// Check if the service has a deactivate method, because it is not defined on the interface
if (method_exists($service, 'deactivate')) {
call_user_func([$service, 'deactivate'], $this->getRequest()->getSession());
}

// Delegate to parent logic
return parent::redirectAfterSuccessfulLogin();
}
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion tests/Behat/features/mfa-enabled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Feature: MFA is enabled for the site
So that my site will be more secure

Background:
Given I am logged in with "ADMIN" permissions
Given I add an extension "SilverStripe\FrameworkTest\SudoMode\ActivateSudoModeServiceExtension" to the "SilverStripe\Security\SudoMode\SudoModeService" class
And I am logged in with "ADMIN" permissions
And I go to "/admin"
Then I should see the CMS

Expand Down

0 comments on commit dcb7304

Please sign in to comment.