diff --git a/src/etc/inc/authgui.inc b/src/etc/inc/authgui.inc index 17fa8e884..ac56fc1d9 100644 --- a/src/etc/inc/authgui.inc +++ b/src/etc/inc/authgui.inc @@ -94,21 +94,11 @@ function session_auth(&$Login_Error) /* Validate incoming login request */ if (isset($_POST['login']) && !empty($_POST['usernamefld']) && !empty($_POST['passwordfld'])) { - // authenticate using config settings, or local if failed - $authservers = !empty($config['system']['webgui']['authmode']) ? - explode(',', $config['system']['webgui']['authmode']) : array('Local Database'); - $is_authenticated = false; - $authenticator = null; - - foreach ($authservers as $authserver) { - $authenticator = get_authenticator(auth_get_authserver($authserver)); - if ($authenticator != null && $authenticator->authenticate($_POST['usernamefld'], $_POST['passwordfld'])) { - $is_authenticated = true; - break; - } - } + $authFactory = new \OPNsense\Auth\AuthenticationFactory(); + $is_authenticated = $authFactory->authenticate("WebGui", $_POST['usernamefld'], $_POST['passwordfld']); if ($is_authenticated) { + $authenticator = $authFactory->lastUsedAuth; // Generate a new id to avoid session fixation session_regenerate_id(); // XXX: eventually we should replace the login flow for a service based one (IService). diff --git a/src/opnsense/mvc/app/library/OPNsense/Auth/Services/WebGui.php b/src/opnsense/mvc/app/library/OPNsense/Auth/Services/WebGui.php new file mode 100644 index 000000000..1be7b66c3 --- /dev/null +++ b/src/opnsense/mvc/app/library/OPNsense/Auth/Services/WebGui.php @@ -0,0 +1,93 @@ +object(); + if (!empty((string)$configObj->system->webgui->authmode)) { + $result = explode(',', (string)$configObj->system->webgui->authmode); + } else { + $result[] = 'Local Database'; + } + return $result; + } + + /** + * {@inheritdoc} + */ + public function setUserName($username) + { + $this->username = $username; + } + + /** + * {@inheritdoc} + */ + public function getUserName() + { + return $this->username; + } + + /** + * {@inheritdoc} + */ + public function checkConstraints() + { + // no constraints + return true; + } +}