diff --git a/src/opnsense/mvc/app/library/OPNsense/Auth/AuthenticationFactory.php b/src/opnsense/mvc/app/library/OPNsense/Auth/AuthenticationFactory.php new file mode 100644 index 000000000..82b907c90 --- /dev/null +++ b/src/opnsense/mvc/app/library/OPNsense/Auth/AuthenticationFactory.php @@ -0,0 +1,116 @@ +object(); + if ($authserver == null || (isset($configObj->system->webgui->authmode) && + (string)$configObj->system->webgui->authmode == $authserver)) { + foreach ($configObj->system->children() as $key => $value) { + if ($key == 'user' && !empty($value->user_dn)) { + $result[(string)$value->name] = (string)$value->user_dn; + } + } + } + return $result; + } + + /** + * request list of configured servers, the factory needs to be aware of it's options and settings to + * be able to instantiate useful connectors. + * @return array list of configured servers + */ + public function listServers() + { + $servers = array(); + $servers['Local Database'] = array("name" => "Local Database", "type" => "local"); + $configObj = Config::getInstance()->object(); + foreach ($configObj->system->children() as $key => $value) { + if ($key == 'authserver' && !empty($value->type) && !empty($value->name)) { + $authServerSettings = array(); + foreach ($value as $itemKey => $itemValue) { + $authServerSettings[$itemKey] = (string)$itemValue; + } + $servers[$authServerSettings['name']] = $authServerSettings; + } + } + + return $servers; + } + + /** + * get new authenticator + * @param $authserver authentication server name + * @return IAuthConnector|null + */ + public function get($authserver) + { + $localUserMap = array(); + $servers = $this->listServers(); + + // create a new auth connector + if (isset($servers[$authserver]['type'])) { + switch ($servers[$authserver]['type']) { + case 'local': + $authObject = new Local(); + break; + case 'ldap': + $authObject = new LDAP(); + $localUserMap = $this->fetchUserDNs(); + break; + default: + $authObject = null; + } + if ($authObject != null) { + $props = $servers[$authserver]; + // when a local user exist and has a different (distinguished) name on the authenticator we already + // know of, we send the mapping to the authenticator as property "local_users". + $props['local_users'] = $localUserMap; + $authObject->setProperties($props); + return $authObject; + } + } + + return null; + } +} diff --git a/src/opnsense/mvc/app/library/OPNsense/Auth/IAuthConnector.php b/src/opnsense/mvc/app/library/OPNsense/Auth/IAuthConnector.php new file mode 100644 index 000000000..dd90e401d --- /dev/null +++ b/src/opnsense/mvc/app/library/OPNsense/Auth/IAuthConnector.php @@ -0,0 +1,51 @@ +