From 6dc6daec55d4f86f73be55134dd924811f067798 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 13 Dec 2023 14:43:40 +0100 Subject: [PATCH] User authentication configuration A central location for the configuration should make it easier to disable certain unwanted functions in SSO plugins. --- .../UserAuthenticationConfiguration.class.php | 22 ++++++++++ ...thenticationConfigurationFactory.class.php | 43 +++++++++++++++++++ .../event/ConfigurationLoading.class.php | 32 ++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php create mode 100644 wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php create mode 100644 wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php new file mode 100644 index 0000000000..1f3f27b47f --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php @@ -0,0 +1,22 @@ + + */ +final class UserAuthenticationConfiguration +{ + public function __construct( + public readonly bool $canRegister = true, + public readonly bool $canLogin = true, + public readonly bool $canChangeUsername = true, + public readonly bool $canChangeEmail = true, + public readonly bool $canChangePassword = true, + ) { + } +} diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php new file mode 100644 index 0000000000..51e1433662 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php @@ -0,0 +1,43 @@ + + */ +final class UserAuthenticationConfigurationFactory extends SingletonFactory +{ + private UserAuthenticationConfiguration $configuration; + + #[\Override] + protected function init() + { + $this->configuration = $this->getDefaultConfiguration(); + + $event = new ConfigurationLoading(); + EventHandler::getInstance()->fire($event); + if ($event->getConfigration()) { + $this->configuration = $event->getConfigration(); + } + } + + public function getConfigration(): UserAuthenticationConfiguration + { + return $this->configuration; + } + + private function getDefaultConfiguration(): UserAuthenticationConfiguration + { + return new UserAuthenticationConfiguration( + !\REGISTER_DISABLED, + ); + } +} diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php new file mode 100644 index 0000000000..eba6168c44 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php @@ -0,0 +1,32 @@ + + */ +final class ConfigurationLoading implements IEvent +{ + private UserAuthenticationConfiguration $configuration; + + public function register(UserAuthenticationConfiguration $configuration): void + { + if (isset($this->configuration)) { + throw new \BadMethodCallException("A configuration has already been loaded"); + } + + $this->configuration = $configuration; + } + + public function getConfigration(): ?UserAuthenticationConfiguration + { + return $this->configuration ?? null; + } +} -- 2.20.1