2017-11-18 11:33:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LibreNMS\Authentication;
|
|
|
|
|
|
|
|
use Dapphp\Radius\Radius;
|
|
|
|
use LibreNMS\Config;
|
|
|
|
use LibreNMS\Exceptions\AuthenticationException;
|
|
|
|
|
2018-02-06 15:20:34 -06:00
|
|
|
class RadiusAuthorizer 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-18 11:33:03 +01:00
|
|
|
|
|
|
|
/** @var Radius $radius */
|
|
|
|
protected $radius;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->radius = new Radius(Config::get('radius.hostname'), Config::get('radius.secret'), Config::get('radius.suffix'), Config::get('radius.timeout'), Config::get('radius.port'));
|
|
|
|
}
|
|
|
|
|
2019-03-05 00:24:14 -06:00
|
|
|
public function authenticate($credentials)
|
2017-11-18 11:33:03 +01:00
|
|
|
{
|
|
|
|
global $debug;
|
|
|
|
|
2019-03-05 00:24:14 -06:00
|
|
|
if (empty($credentials['username'])) {
|
2017-11-18 11:33:03 +01:00
|
|
|
throw new AuthenticationException('Username is required');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
$this->radius->setDebug(true);
|
|
|
|
}
|
|
|
|
|
2019-03-05 00:24:14 -06:00
|
|
|
$password = $credentials['password'] ?? null;
|
|
|
|
if ($this->radius->accessRequest($credentials['username'], $password) === true) {
|
|
|
|
$this->addUser($credentials['username'], $password, Config::get('radius.default_level', 1));
|
2017-11-18 11:33:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new AuthenticationException();
|
|
|
|
}
|
|
|
|
}
|