From 60255db1da3198ea86294c770ae41dedca878573 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 17 Feb 2021 11:25:46 +0100 Subject: [PATCH] Add PoC events to user authentication --- .../files/lib/acp/form/LoginForm.class.php | 9 ++++ .../lib/action/FacebookAuthAction.class.php | 3 ++ .../lib/action/GithubAuthAction.class.php | 3 ++ .../lib/action/GoogleAuthAction.class.php | 3 ++ .../lib/action/TwitterAuthAction.class.php | 3 ++ .../files/lib/form/LoginForm.class.php | 9 ++++ .../MultifactorAuthenticationForm.class.php | 5 +++ .../authentication/UserLoggedIn.class.php | 36 +++++++++++++++ .../UserMultifactorRequested.class.php | 33 ++++++++++++++ .../UserMultifactorSucceeded.class.php | 45 +++++++++++++++++++ 10 files changed, 149 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/user/authentication/UserLoggedIn.class.php create mode 100644 wcfsetup/install/files/lib/system/user/authentication/UserMultifactorRequested.class.php create mode 100644 wcfsetup/install/files/lib/system/user/authentication/UserMultifactorSucceeded.class.php diff --git a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php index 7d36887dec..ed038fb849 100755 --- a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php @@ -8,6 +8,7 @@ use wcf\data\user\User; use wcf\data\user\UserProfile; use wcf\form\AbstractCaptchaForm; use wcf\system\application\ApplicationHandler; +use wcf\system\event\EventHandler; use wcf\system\exception\NamedUserException; use wcf\system\exception\UserInputException; use wcf\system\request\LinkHandler; @@ -15,6 +16,8 @@ use wcf\system\request\RequestHandler; use wcf\system\request\RouteHandler; use wcf\system\user\authentication\EmailUserAuthentication; use wcf\system\user\authentication\UserAuthenticationFactory; +use wcf\system\user\authentication\UserLoggedIn; +use wcf\system\user\authentication\UserMultifactorRequested; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\StringUtil; @@ -224,6 +227,12 @@ class LoginForm extends AbstractCaptchaForm // change user $needsMultifactor = WCF::getSession()->changeUserAfterMultifactorAuthentication($this->user); + if ($needsMultifactor) { + EventHandler::getInstance()->fire(new UserMultifactorRequested($this->user)); + } else { + EventHandler::getInstance()->fire(new UserLoggedIn($this->user)); + } + if (!$needsMultifactor) { WCF::getSession()->registerReauthentication(); } diff --git a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php index 901a855584..e038193efc 100644 --- a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php @@ -5,9 +5,11 @@ namespace wcf\action; use GuzzleHttp\Psr7\Request; use wcf\data\user\User; use wcf\form\RegisterForm; +use wcf\system\event\EventHandler; use wcf\system\exception\NamedUserException; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; +use wcf\system\user\authentication\UserLoggedIn; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\JSON; @@ -132,6 +134,7 @@ final class FacebookAuthAction extends AbstractOauth2Action // Perform the login. WCF::getSession()->changeUser($user); + EventHandler::getInstance()->fire(new UserLoggedIn($user)); WCF::getSession()->update(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); diff --git a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php index a8a034e3b1..98e5de3657 100644 --- a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php @@ -6,9 +6,11 @@ use GuzzleHttp\Psr7\Request; use Psr\Http\Client\ClientExceptionInterface; use wcf\data\user\User; use wcf\form\RegisterForm; +use wcf\system\event\EventHandler; use wcf\system\exception\NamedUserException; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; +use wcf\system\user\authentication\UserLoggedIn; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\JSON; @@ -124,6 +126,7 @@ final class GithubAuthAction extends AbstractOauth2Action // Perform the login. WCF::getSession()->changeUser($user); + EventHandler::getInstance()->fire(new UserLoggedIn($user)); WCF::getSession()->update(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index 078e9b6425..5cab421cfb 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -5,9 +5,11 @@ namespace wcf\action; use GuzzleHttp\Psr7\Request; use wcf\data\user\User; use wcf\form\RegisterForm; +use wcf\system\event\EventHandler; use wcf\system\exception\NamedUserException; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; +use wcf\system\user\authentication\UserLoggedIn; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\JSON; @@ -146,6 +148,7 @@ final class GoogleAuthAction extends AbstractOauth2Action // Perform the login. WCF::getSession()->changeUser($user); + EventHandler::getInstance()->fire(new UserLoggedIn($user)); WCF::getSession()->update(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); diff --git a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php index 447450027a..efb7ff0976 100644 --- a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php @@ -4,11 +4,13 @@ namespace wcf\action; use ParagonIE\ConstantTime\Hex; use wcf\data\user\User; +use wcf\system\event\EventHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\NamedUserException; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\SystemException; use wcf\system\request\LinkHandler; +use wcf\system\user\authentication\UserLoggedIn; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\HTTPRequest; @@ -104,6 +106,7 @@ class TwitterAuthAction extends AbstractAction } // perform login else { WCF::getSession()->changeUser($user); + EventHandler::getInstance()->fire(new UserLoggedIn($user)); WCF::getSession()->update(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); } diff --git a/wcfsetup/install/files/lib/form/LoginForm.class.php b/wcfsetup/install/files/lib/form/LoginForm.class.php index 95fadd5b49..9f7c028640 100644 --- a/wcfsetup/install/files/lib/form/LoginForm.class.php +++ b/wcfsetup/install/files/lib/form/LoginForm.class.php @@ -2,7 +2,10 @@ namespace wcf\form; +use wcf\system\event\EventHandler; use wcf\system\request\LinkHandler; +use wcf\system\user\authentication\UserLoggedIn; +use wcf\system\user\authentication\UserMultifactorRequested; use wcf\system\WCF; /** @@ -31,6 +34,12 @@ class LoginForm extends \wcf\acp\form\LoginForm // change user $needsMultifactor = WCF::getSession()->changeUserAfterMultifactorAuthentication($this->user); + if ($needsMultifactor) { + EventHandler::getInstance()->fire(new UserMultifactorRequested($this->user)); + } else { + EventHandler::getInstance()->fire(new UserLoggedIn($this->user)); + } + $this->saved(); // redirect to url diff --git a/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php b/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php index ffeb52fef6..aa9bc2c893 100644 --- a/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php +++ b/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php @@ -6,10 +6,13 @@ use wcf\data\object\type\ObjectType; use wcf\data\user\User; use wcf\system\application\ApplicationHandler; use wcf\system\cache\runtime\UserProfileRuntimeCache; +use wcf\system\event\EventHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\NamedUserException; use wcf\system\form\builder\TemplateFormNode; use wcf\system\request\LinkHandler; +use wcf\system\user\authentication\UserLoggedIn; +use wcf\system\user\authentication\UserMultifactorSucceeded; use wcf\system\user\multifactor\IMultifactorMethod; use wcf\system\user\multifactor\Setup; use wcf\system\WCF; @@ -144,6 +147,8 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm WCF::getDB()->commitTransaction(); WCF::getSession()->applyPendingUserChange($this->user); + EventHandler::getInstance()->fire(new UserLoggedIn($this->user)); + EventHandler::getInstance()->fire(new UserMultifactorSucceeded($this->user, $setup)); WCF::getSession()->registerReauthentication(); $this->saved(); diff --git a/wcfsetup/install/files/lib/system/user/authentication/UserLoggedIn.class.php b/wcfsetup/install/files/lib/system/user/authentication/UserLoggedIn.class.php new file mode 100644 index 0000000000..1f76a76751 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/UserLoggedIn.class.php @@ -0,0 +1,36 @@ + + * @package WoltLabSuite\Core\System\User\Authentication + * @since 5.5 + */ +final class UserLoggedIn implements IEvent +{ + /** + * @var User + */ + private $user; + + public function __construct(User $user) + { + $this->user = $user; + } + + public function getUser(): User + { + return $this->user; + } +} diff --git a/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorRequested.class.php b/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorRequested.class.php new file mode 100644 index 0000000000..a4051b3221 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorRequested.class.php @@ -0,0 +1,33 @@ + + * @package WoltLabSuite\Core\System\User\Authentication + * @since 5.5 + */ +final class UserMultifactorRequested implements IEvent +{ + /** + * @var User + */ + private $user; + + public function __construct(User $user) + { + $this->user = $user; + } + + public function getUser(): User + { + return $this->user; + } +} diff --git a/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorSucceeded.class.php b/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorSucceeded.class.php new file mode 100644 index 0000000000..82fe5d479a --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/UserMultifactorSucceeded.class.php @@ -0,0 +1,45 @@ + + * @package WoltLabSuite\Core\System\User\Authentication + * @since 5.5 + */ +final class UserMultifactorSucceeded implements IEvent +{ + /** + * @var User + */ + private $user; + + /** + * @var Setup + */ + private $setup; + + public function __construct(User $user, Setup $setup) + { + $this->user = $user; + $this->setup = $setup; + } + + public function getUser(): User + { + return $this->user; + } + + public function getSetup(): Setup + { + return $this->setup; + } +} -- 2.20.1