2017-11-18 11:33:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace LibreNMS\Authentication;
|
|
|
|
|
|
|
|
|
|
use LibreNMS\Config;
|
|
|
|
|
use LibreNMS\Exceptions\AuthenticationException;
|
|
|
|
|
|
2018-02-06 15:20:34 -06:00
|
|
|
class HttpAuthAuthorizer extends MysqlAuthorizer
|
2017-11-18 11:33:03 +01:00
|
|
|
{
|
|
|
|
|
protected static $HAS_AUTH_USERMANAGEMENT = 1;
|
|
|
|
|
protected static $CAN_UPDATE_USER = 1;
|
2018-02-06 15:20:34 -06:00
|
|
|
protected static $CAN_UPDATE_PASSWORDS = 0;
|
2017-11-29 02:40:17 +00:00
|
|
|
protected static $AUTH_IS_EXTERNAL = 1;
|
2017-11-18 11:33:03 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-02-06 15:20:34 -06:00
|
|
|
if (parent::userExists($username)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-11-18 11:33:03 +01:00
|
|
|
|
2018-02-06 15:20:34 -06:00
|
|
|
if (Config::has('http_auth_guest') && parent::userExists(Config::get('http_auth_guest'))) {
|
|
|
|
|
return true;
|
2017-11-18 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 15:20:34 -06:00
|
|
|
return false;
|
2017-11-18 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getUserlevel($username)
|
|
|
|
|
{
|
2018-02-06 15:20:34 -06:00
|
|
|
$user_level = parent::getUserlevel($username);
|
2017-11-18 11:33:03 +01:00
|
|
|
|
|
|
|
|
if ($user_level) {
|
|
|
|
|
return $user_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Config::has('http_auth_guest')) {
|
2018-02-06 15:20:34 -06:00
|
|
|
return parent::getUserlevel(Config::get('http_auth_guest'));
|
2017-11-18 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getUserid($username)
|
|
|
|
|
{
|
2018-02-06 15:20:34 -06:00
|
|
|
$user_id = parent::getUserid($username);
|
2017-11-18 11:33:03 +01:00
|
|
|
|
|
|
|
|
if ($user_id) {
|
|
|
|
|
return $user_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Config::has('http_auth_guest')) {
|
2018-02-06 15:20:34 -06:00
|
|
|
return parent::getUserid(Config::get('http_auth_guest'));
|
2017-11-18 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|