Files
librenms-librenms/LibreNMS/Authentication/HttpAuthAuthorizer.php
Tony Murray 5141fc4872 refactor: Share code between all mysql based authorizers (#8174)
* Share code between all mysql based authorizers
I plan to update the mysql password encryption and this will allow the code to be changed in a single location.
It also reduces a lot of duplication.

* Fix tests, I suspect reauthenticate will work for these...
Do not allow password updates for several authorizers
2018-02-06 21:20:34 +00:00

69 lines
1.5 KiB
PHP

<?php
namespace LibreNMS\Authentication;
use LibreNMS\Config;
use LibreNMS\Exceptions\AuthenticationException;
class HttpAuthAuthorizer extends MysqlAuthorizer
{
protected static $HAS_AUTH_USERMANAGEMENT = 1;
protected static $CAN_UPDATE_USER = 1;
protected static $CAN_UPDATE_PASSWORDS = 0;
protected static $AUTH_IS_EXTERNAL = 1;
public function authenticate($username, $password)
{
if ($this->userExists($username)) {
return true;
}
throw new AuthenticationException('No matching user found and http_auth_guest is not set');
}
public function userExists($username, $throw_exception = false)
{
if (parent::userExists($username)) {
return true;
}
if (Config::has('http_auth_guest') && parent::userExists(Config::get('http_auth_guest'))) {
return true;
}
return false;
}
public function getUserlevel($username)
{
$user_level = parent::getUserlevel($username);
if ($user_level) {
return $user_level;
}
if (Config::has('http_auth_guest')) {
return parent::getUserlevel(Config::get('http_auth_guest'));
}
return 0;
}
public function getUserid($username)
{
$user_id = parent::getUserid($username);
if ($user_id) {
return $user_id;
}
if (Config::has('http_auth_guest')) {
return parent::getUserid(Config::get('http_auth_guest'));
}
return -1;
}
}