do not hard-require the token provider
The provider might need DB access and therefore depenedency resolution fails on the setup page where we cannot inject the db implementation. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
6f74ecd94a
commit
21d3fe5883
3 changed files with 25 additions and 9 deletions
|
@ -40,21 +40,21 @@ class Store implements IStore {
|
|||
/** @var ISession */
|
||||
private $session;
|
||||
|
||||
/** @var IProvider */
|
||||
private $tokenProvider;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var IProvider|null */
|
||||
private $tokenProvider;
|
||||
|
||||
/**
|
||||
* @param ISession $session
|
||||
* @param IProvider $tokenProvider
|
||||
* @param ILogger $logger
|
||||
* @param IProvider $tokenProvider
|
||||
*/
|
||||
public function __construct(ISession $session, IProvider $tokenProvider, ILogger $logger) {
|
||||
public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) {
|
||||
$this->session = $session;
|
||||
$this->tokenProvider = $tokenProvider;
|
||||
$this->logger = $logger;
|
||||
$this->tokenProvider = $tokenProvider;
|
||||
|
||||
Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
|
||||
}
|
||||
|
@ -84,6 +84,10 @@ class Store implements IStore {
|
|||
* @throws CredentialsUnavailableException
|
||||
*/
|
||||
public function getLoginCredentials() {
|
||||
if (is_null($this->tokenProvider)) {
|
||||
throw new CredentialsUnavailableException();
|
||||
}
|
||||
|
||||
$trySession = false;
|
||||
try {
|
||||
$sessionId = $this->session->getId();
|
||||
|
|
|
@ -250,9 +250,13 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
});
|
||||
$this->registerService(Store::class, function(Server $c) {
|
||||
$session = $c->getSession();
|
||||
$tokenProvider = $c->query('OC\Authentication\Token\DefaultTokenProvider');
|
||||
if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
|
||||
$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
|
||||
} else {
|
||||
$tokenProvider = null;
|
||||
}
|
||||
$logger = $c->getLogger();
|
||||
return new Store($session, $tokenProvider, $logger);
|
||||
return new Store($session, $logger, $tokenProvider);
|
||||
});
|
||||
$this->registerAlias(IStore::class, Store::class);
|
||||
$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
|
||||
|
|
|
@ -58,7 +58,7 @@ class StoreTest extends TestCase {
|
|||
$this->tokenProvider = $this->createMock(IProvider::class);
|
||||
$this->logger = $this->createMock(ILogger::class);
|
||||
|
||||
$this->store = new Store($this->session, $this->tokenProvider, $this->logger);
|
||||
$this->store = new Store($this->session, $this->logger, $this->tokenProvider);
|
||||
}
|
||||
|
||||
public function testAuthenticate() {
|
||||
|
@ -81,6 +81,14 @@ class StoreTest extends TestCase {
|
|||
$this->store->setSession($session);
|
||||
}
|
||||
|
||||
public function testGetLoginCredentialsNoTokenProvider() {
|
||||
$this->store = new Store($this->session, $this->logger, null);
|
||||
|
||||
$this->expectException(CredentialsUnavailableException::class);
|
||||
|
||||
$this->store->getLoginCredentials();
|
||||
}
|
||||
|
||||
public function testGetLoginCredentials() {
|
||||
$uid = 'uid';
|
||||
$user = 'user123';
|
||||
|
|
Loading…
Reference in a new issue