complément logs et exceptions #20

Merged
mlamalle merged 4 commits from issue-19 into develop 2024-04-29 11:33:17 +02:00
3 changed files with 43 additions and 44 deletions
Showing only changes of commit 51c92a0dba - Show all commits

View File

@ -17,7 +17,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class SecurityController extends AbstractController class SecurityController extends AbstractController
{ {
#[Route('/login', name: 'app_login')] #[Route('/login', name: 'app_login')]
public function login(ParameterBagInterface $params, AuthenticationUtils $authenticationUtils, Request $request, TranslatorInterface $trans): Response public function login(ParameterBagInterface $params, AuthenticationUtils $authenticationUtils, Request $request, TranslatorInterface $trans): Response|RedirectResponse
{ {
// Si l'utilisateur est déjà connecté on le renvoie sur la page du site demandeur // Si l'utilisateur est déjà connecté on le renvoie sur la page du site demandeur
if ($this->getUser()) { if ($this->getUser()) {
@ -32,10 +32,6 @@ class SecurityController extends AbstractController
$loginForm->addError(new FormError($trans->trans('error.login', [], 'messages'))); $loginForm->addError(new FormError($trans->trans('error.login', [], 'messages')));
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_LOGIN); $request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_LOGIN);
} }
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PASSWORD)) {
$loginForm->addError(new FormError($trans->trans('error.login', [], 'messages')));
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PASSWORD);
}
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) { if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) {
$loginForm->addError(new FormError($trans->trans('error.pdo', [], 'messages'))); $loginForm->addError(new FormError($trans->trans('error.pdo', [], 'messages')));
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PDO); $request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PDO);

View File

@ -10,6 +10,7 @@ use App\SQLLogin\Exception\DataToFetchConfigurationException;
use App\SQLLogin\Exception\InvalidSQLPasswordException; use App\SQLLogin\Exception\InvalidSQLPasswordException;
use App\SQLLogin\Exception\LoginElementsConfigurationException; use App\SQLLogin\Exception\LoginElementsConfigurationException;
use App\SQLLogin\Exception\SecurityPatternConfigurationException; use App\SQLLogin\Exception\SecurityPatternConfigurationException;
use Exception;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@ -24,7 +25,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
{ {
public const LOGIN_ROUTE = 'app_login'; public const LOGIN_ROUTE = 'app_login';
public const ERROR_LOGIN = 'error_login'; public const ERROR_LOGIN = 'error_login';
public const ERROR_PASSWORD = 'error_password';
public const ERROR_PDO = 'error_pdo'; public const ERROR_PDO = 'error_pdo';
public const ERROR_SQL_LOGIN = 'error_sql_login'; public const ERROR_SQL_LOGIN = 'error_sql_login';
public const ERROR_CONFIGURATION = 'error_configuration'; public const ERROR_CONFIGURATION = 'error_configuration';
@ -80,8 +80,13 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
} catch (LoginElementsConfigurationException $e) { } catch (LoginElementsConfigurationException $e) {
$session->set(self::ERROR_CONFIGURATION, true); $session->set(self::ERROR_CONFIGURATION, true);
throw new AuthenticationException(); throw new AuthenticationException();
} catch (Exception $exception) {
$request->getSession()->set(self::ERROR_LOGIN, true);
throw new AuthenticationException();
}
if (!$remoteHashedPassword) {
throw new Exception('Erreur inconnue');
} }
if ($remoteHashedPassword) {
try { try {
// Comparaison remote hash et hash du input password + salt // Comparaison remote hash et hash du input password + salt
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt); $this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
@ -99,7 +104,7 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
return $passport; return $passport;
} catch (InvalidSQLPasswordException $e) { } catch (InvalidSQLPasswordException $e) {
$session->set(self::ERROR_PASSWORD, true); $session->set(self::ERROR_LOGIN, true);
throw new AuthenticationException(); throw new AuthenticationException();
} catch (DataToFetchConfigurationException $e) { } catch (DataToFetchConfigurationException $e) {
$session->set(self::ERROR_DATA_TO_FETCH_CONFIGURATION, true); $session->set(self::ERROR_DATA_TO_FETCH_CONFIGURATION, true);
@ -112,9 +117,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
throw new AuthenticationException(); throw new AuthenticationException();
} }
} }
$request->getSession()->set(self::ERROR_LOGIN, true);
throw new AuthenticationException();
}
protected function getLoginUrl(Request $request): string protected function getLoginUrl(Request $request): string
{ {

View File

@ -8,6 +8,7 @@ use App\SQLLogin\Exception\LoginElementsConfigurationException;
use App\SQLLogin\Exception\NullDataToFetchException; use App\SQLLogin\Exception\NullDataToFetchException;
use App\SQLLogin\SQLLoginConnect; use App\SQLLogin\SQLLoginConnect;
use App\SQLLogin\SQLLoginRequest; use App\SQLLogin\SQLLoginRequest;
use Exception;
use PDO; use PDO;
use PDOException; use PDOException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -51,7 +52,7 @@ class SQLLoginService extends AbstractController
return $datas; return $datas;
} }
public function fetchPassword($login): array|bool public function fetchPassword(string $login): array
{ {
try { try {
$dbh = $this->getConnection(); $dbh = $this->getConnection();
@ -71,16 +72,16 @@ class SQLLoginService extends AbstractController
$this->loggerInterface->critical($e->getMessage()); $this->loggerInterface->critical($e->getMessage());
throw new LoginElementsConfigurationException($e->getMessage()); throw new LoginElementsConfigurationException($e->getMessage());
} }
if ($password) { if (!$password) {
throw new Exception('Une erreur est survenue lors de la récupération des données');
}
return [ return [
$password[$this->sqlLoginRequest->getPasswordColumnName()], $password[$this->sqlLoginRequest->getPasswordColumnName()],
isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null, isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,
]; ];
} }
return false;
}
public function getConnection(): PDO public function getConnection(): PDO
{ {
// Appel du singleton // Appel du singleton