2019-10-26 23:22:27 +02:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-10-26 23:22:27 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-10-26 23:22:27 +02:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-10-26 23:22:27 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Security;
|
|
|
|
|
|
|
|
use App\Entity\UserSystem\User;
|
|
|
|
use Symfony\Component\Security\Core\Exception\AccountStatusException;
|
2022-11-15 00:25:56 +01:00
|
|
|
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
|
2019-10-26 23:22:27 +02:00
|
|
|
use Symfony\Component\Security\Core\Exception\DisabledException;
|
|
|
|
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
2022-11-15 00:25:56 +01:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-10-26 23:22:27 +02:00
|
|
|
|
2020-01-05 22:49:00 +01:00
|
|
|
final class UserChecker implements UserCheckerInterface
|
2019-10-26 23:22:27 +02:00
|
|
|
{
|
2022-11-15 00:25:56 +01:00
|
|
|
private TranslatorInterface $translator;
|
|
|
|
|
|
|
|
public function __construct(TranslatorInterface $translator)
|
2019-10-26 23:22:27 +02:00
|
|
|
{
|
2022-11-15 00:25:56 +01:00
|
|
|
$this->translator = $translator;
|
2019-10-26 23:22:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the user account before authentication.
|
|
|
|
*
|
|
|
|
* @throws AccountStatusException
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
public function checkPreAuth(UserInterface $user): void
|
2019-10-26 23:22:27 +02:00
|
|
|
{
|
|
|
|
// TODO: Implement checkPreAuth() method.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the user account after authentication.
|
|
|
|
*
|
|
|
|
* @throws AccountStatusException
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
public function checkPostAuth(UserInterface $user): void
|
2019-10-26 23:22:27 +02:00
|
|
|
{
|
2020-08-21 21:36:22 +02:00
|
|
|
if (!$user instanceof User) {
|
2019-10-26 23:22:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if user is disabled. Then dont allow login
|
|
|
|
if ($user->isDisabled()) {
|
2022-11-15 00:25:56 +01:00
|
|
|
//throw new DisabledException();
|
|
|
|
throw new CustomUserMessageAccountStatusException($this->translator->trans('user.login_error.user_disabled'));
|
2019-10-26 23:22:27 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
}
|