Authorize only API tokens when 2FA is enabled
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Kanboard\Api\Middleware;
|
|||||||
use JsonRPC\Exception\AccessDeniedException;
|
use JsonRPC\Exception\AccessDeniedException;
|
||||||
use JsonRPC\Exception\AuthenticationFailureException;
|
use JsonRPC\Exception\AuthenticationFailureException;
|
||||||
use JsonRPC\MiddlewareInterface;
|
use JsonRPC\MiddlewareInterface;
|
||||||
|
use Kanboard\Auth\ApiAccessTokenAuth;
|
||||||
use Kanboard\Core\Base;
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,9 +49,21 @@ class AuthenticationMiddleware extends Base implements MiddlewareInterface
|
|||||||
*/
|
*/
|
||||||
private function isUserAuthenticated($username, $password)
|
private function isUserAuthenticated($username, $password)
|
||||||
{
|
{
|
||||||
return $username !== 'jsonrpc' &&
|
if ($username === 'jsonrpc') {
|
||||||
! $this->userLockingModel->isLocked($username) &&
|
return false;
|
||||||
$this->authenticationManager->passwordAuthentication($username, $password);
|
}
|
||||||
|
|
||||||
|
if ($this->userLockingModel->isLocked($username)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->userModel->has2FA($username)) {
|
||||||
|
$this->logger->info('This API user ('.$username.') as 2FA enabled: only API keys are authorized');
|
||||||
|
$this->authenticationManager->reset();
|
||||||
|
$this->authenticationManager->register(new ApiAccessTokenAuth($this->container));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->authenticationManager->passwordAuthentication($username, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class AuthenticationManager extends Base
|
|||||||
*/
|
*/
|
||||||
private $providers = array();
|
private $providers = array();
|
||||||
|
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
$this->providers = [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new authentication provider
|
* Register a new authentication provider
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ class UserModel extends Base
|
|||||||
->exists();
|
->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function has2FA($username)
|
||||||
|
{
|
||||||
|
return $this->db->table(self::TABLE)
|
||||||
|
->eq('username', $username)
|
||||||
|
->eq('is_active', 1)
|
||||||
|
->eq('twofactor_activated', 1)
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the user exists
|
* Return true if the user exists
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace Kanboard\ServiceProvider;
|
namespace Kanboard\ServiceProvider;
|
||||||
|
|
||||||
use Kanboard\Auth\ApiAccessTokenAuth;
|
|
||||||
use Pimple\Container;
|
use Pimple\Container;
|
||||||
use Pimple\ServiceProviderInterface;
|
use Pimple\ServiceProviderInterface;
|
||||||
use Kanboard\Core\Security\AuthenticationManager;
|
use Kanboard\Core\Security\AuthenticationManager;
|
||||||
use Kanboard\Core\Security\AccessMap;
|
use Kanboard\Core\Security\AccessMap;
|
||||||
use Kanboard\Core\Security\Authorization;
|
use Kanboard\Core\Security\Authorization;
|
||||||
use Kanboard\Core\Security\Role;
|
use Kanboard\Core\Security\Role;
|
||||||
|
use Kanboard\Auth\ApiAccessTokenAuth;
|
||||||
use Kanboard\Auth\RememberMeAuth;
|
use Kanboard\Auth\RememberMeAuth;
|
||||||
use Kanboard\Auth\DatabaseAuth;
|
use Kanboard\Auth\DatabaseAuth;
|
||||||
use Kanboard\Auth\LdapAuth;
|
use Kanboard\Auth\LdapAuth;
|
||||||
|
|||||||
Reference in New Issue
Block a user