Merge pull request #4065 from Icinga/fix/cli-fake-auth

CLI: Setup fake auth
This commit is contained in:
Johannes Meyer 2020-03-11 09:40:01 +01:00 committed by GitHub
commit 6741217c7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Application;
use Icinga\Application\Platform;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Authentication\Auth;
use Icinga\Cli\Params;
use Icinga\Cli\Loader;
use Icinga\Cli\Screen;
@ -12,6 +13,7 @@ use Icinga\Application\Logger;
use Icinga\Application\Benchmark;
use Icinga\Data\ConfigObject;
use Icinga\Exception\ProgrammingError;
use Icinga\User;
require_once __DIR__ . '/ApplicationBootstrap.php';
@ -43,7 +45,8 @@ class Cli extends ApplicationBootstrap
->setupLogger()
->setupModuleManager()
->setupUserBackendFactory()
->loadSetupModuleIfNecessary();
->loadSetupModuleIfNecessary()
->setupFakeAuthentication();
}
/**
@ -87,6 +90,13 @@ class Cli extends ApplicationBootstrap
return $this;
}
protected function setupFakeAuthentication()
{
Auth::getInstance()->setUser(new User('cli'));
return $this;
}
public function cliLoader()
{
if ($this->cliLoader === null) {

View File

@ -256,6 +256,23 @@ class Auth
return $this->user;
}
/**
* Set the authenticated user
*
* Note that this method just sets the authenticated user and thus bypasses our default authentication process in
* {@link setAuthenticated()}.
*
* @param User $user
*
* @return $this
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* Try to authenticate the user with the current session
*