complément logs et exceptions #20
|
@ -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()) {
|
||||||
|
@ -29,16 +29,24 @@ class SecurityController extends AbstractController
|
||||||
$error = $authenticationUtils->getLastAuthenticationError();
|
$error = $authenticationUtils->getLastAuthenticationError();
|
||||||
if ($error) {
|
if ($error) {
|
||||||
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_LOGIN)) {
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_LOGIN)) {
|
||||||
$loginForm->get('login')->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)) {
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) {
|
||||||
$loginForm->get('password')->addError(new FormError($trans->trans('error.password', [], 'messages')));
|
$loginForm->addError(new FormError($trans->trans('error.pdo', [], 'messages')));
|
||||||
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PASSWORD);
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PDO);
|
||||||
}
|
}
|
||||||
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_SQL_LOGIN)) {
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_CONFIGURATION)) {
|
||||||
$loginForm->addError(new FormError($trans->trans('error.sql_login', [], 'messages')));
|
$loginForm->addError(new FormError($trans->trans('error.configuration', [], 'messages')));
|
||||||
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_SQL_LOGIN);
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_CONFIGURATION);
|
||||||
|
}
|
||||||
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_DATA_TO_FETCH_CONFIGURATION)) {
|
||||||
|
$loginForm->addError(new FormError($trans->trans('error.data_to_fetch_configuration', [], 'messages')));
|
||||||
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_DATA_TO_FETCH_CONFIGURATION);
|
||||||
|
}
|
||||||
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_SECURITY_PATTERN_CONFIGURATION)) {
|
||||||
|
$loginForm->addError(new FormError($trans->trans('error.security_pattern_configuration', [], 'messages')));
|
||||||
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_SECURITY_PATTERN_CONFIGURATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@ namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class InvalidSQLLoginConfigurationException extends Exception
|
class DataToFetchConfigurationException extends Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class DatabaseConnectionException extends Exception
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class LoginElementsConfigurationException extends Exception
|
||||||
|
{
|
||||||
|
}
|
|
@ -4,6 +4,6 @@ namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class InvalidSQLLoginException extends Exception
|
class NullDataToFetchException extends Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class NullPasswordColumnNameException extends Exception
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\SQLLogin\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class SecurityPatternConfigurationException extends Exception
|
||||||
|
{
|
||||||
|
}
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\SQLLogin;
|
namespace App\SQLLogin;
|
||||||
|
|
||||||
|
use App\SQLLogin\Exception\NullDataToFetchException;
|
||||||
|
|
||||||
class SQLLoginRequest
|
class SQLLoginRequest
|
||||||
{
|
{
|
||||||
public const DATA_TO_FETCH = 'data_to_fetch';
|
public const DATA_TO_FETCH = 'data_to_fetch';
|
||||||
|
@ -67,25 +69,30 @@ class SQLLoginRequest
|
||||||
public function getRequestScope()
|
public function getRequestScope()
|
||||||
{
|
{
|
||||||
$scope = '';
|
$scope = '';
|
||||||
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
if (!$this->config[self::DATA_TO_FETCH]) {
|
||||||
|
|||||||
$scope .= $data.',';
|
throw new NullDataToFetchException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
||||||
|
$scope .= $data . ',';
|
||||||
|
}
|
||||||
|
// On enlève la dernière virgule
|
||||||
$scope = substr($scope, 0, -1);
|
$scope = substr($scope, 0, -1);
|
||||||
|
|
||||||
return 'SELECT '.$scope.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';';
|
return 'SELECT ' . $scope . ' FROM ' . $this->getTableName() . ' WHERE ' . $this->getLoginColumnName() . ' = :' . $this->getLoginColumnName() . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construction de la string pour la requête préparée selon la configuration yaml
|
* Construction de la string pour la requête préparée selon la configuration yaml
|
||||||
* intègre la récupération du mot de passe hashé, du salt et de besoin d'upgrade de la méthode de hashage
|
* intègre la récupération du mot de passe hashé, du salt et de besoin d'upgrade de la méthode de hashage
|
||||||
*/
|
*/
|
||||||
public function getRequestPassword()
|
public function getRequestPassword(): string
|
||||||
{
|
{
|
||||||
$fields = $this->getPasswordColumnName();
|
$fields = $this->getPasswordColumnName();
|
||||||
if (!empty($this->getSaltColumnName())) {
|
if (!empty($this->getSaltColumnName())) {
|
||||||
$fields .= ', '.$this->getSaltColumnName();
|
$fields .= ', ' . $this->getSaltColumnName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'SELECT '.$fields.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';';
|
return 'SELECT ' . $fields . ' FROM ' . $this->getTableName() . ' WHERE ' . $this->getLoginColumnName() . ' = :' . $this->getLoginColumnName() . ';';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
namespace App\Security\Hasher;
|
namespace App\Security\Hasher;
|
||||||
|
|
||||||
use App\SQLLogin\Exception\InvalidSQLLoginConfigurationException;
|
|
||||||
use App\SQLLogin\Exception\InvalidSQLPasswordException;
|
use App\SQLLogin\Exception\InvalidSQLPasswordException;
|
||||||
|
use App\SQLLogin\Exception\SecurityPatternConfigurationException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\PasswordHasher\Exception\InvalidPasswordException;
|
use Symfony\Component\PasswordHasher\Exception\InvalidPasswordException;
|
||||||
use Symfony\Component\PasswordHasher\Hasher\CheckPasswordLengthTrait;
|
use Symfony\Component\PasswordHasher\Hasher\CheckPasswordLengthTrait;
|
||||||
use Symfony\Component\PasswordHasher\LegacyPasswordHasherInterface;
|
use Symfony\Component\PasswordHasher\LegacyPasswordHasherInterface;
|
||||||
|
@ -19,7 +20,7 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
||||||
protected array $hashAlgoLegacy;
|
protected array $hashAlgoLegacy;
|
||||||
protected array $securityPattern;
|
protected array $securityPattern;
|
||||||
|
|
||||||
public function __construct(?string $pepper, string $hashAlgoLegacy, string $securityPattern)
|
public function __construct(?string $pepper, string $hashAlgoLegacy, string $securityPattern, private LoggerInterface $loggerInterface)
|
||||||
{
|
{
|
||||||
$this->pepper = $pepper;
|
$this->pepper = $pepper;
|
||||||
$this->hashAlgoLegacy = explode(',', $hashAlgoLegacy);
|
$this->hashAlgoLegacy = explode(',', $hashAlgoLegacy);
|
||||||
|
@ -88,7 +89,8 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
||||||
|
|
||||||
foreach ($this->securityPattern as $term) {
|
foreach ($this->securityPattern as $term) {
|
||||||
if (self::PEPPER_PATTERN !== $term && self::PASSWORD_PATTERN !== $term && self::SALT_PATTERN !== $term) {
|
if (self::PEPPER_PATTERN !== $term && self::PASSWORD_PATTERN !== $term && self::SALT_PATTERN !== $term) {
|
||||||
throw new InvalidSQLLoginConfigurationException();
|
$this->loggerInterface->critical('La configuration du security pattern est invalide, les termes autorisés sont : '.self::PASSWORD_PATTERN.', '.self::SALT_PATTERN.' et '.self::PEPPER_PATTERN);
|
||||||
|
throw new SecurityPatternConfigurationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$completedPlainPassword = '';
|
$completedPlainPassword = '';
|
||||||
|
|
|
@ -5,26 +5,31 @@ namespace App\Security;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Security\Hasher\PasswordEncoder;
|
use App\Security\Hasher\PasswordEncoder;
|
||||||
use App\Service\SQLLoginService;
|
use App\Service\SQLLoginService;
|
||||||
|
use App\SQLLogin\Exception\DatabaseConnectionException;
|
||||||
|
use App\SQLLogin\Exception\DataToFetchConfigurationException;
|
||||||
use App\SQLLogin\Exception\InvalidSQLPasswordException;
|
use App\SQLLogin\Exception\InvalidSQLPasswordException;
|
||||||
use PDOException;
|
use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||||
|
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\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
|
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
|
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
||||||
|
|
||||||
class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
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_SQL_LOGIN = 'error_sql_login';
|
public const ERROR_SQL_LOGIN = 'error_sql_login';
|
||||||
|
public const ERROR_CONFIGURATION = 'error_configuration';
|
||||||
|
public const ERROR_DATA_TO_FETCH_CONFIGURATION = 'error_data_to_fetch_configuration';
|
||||||
|
public const ERROR_SECURITY_PATTERN_CONFIGURATION = 'error_security_pattern_configuration';
|
||||||
|
|
||||||
protected string $baseUrl;
|
protected string $baseUrl;
|
||||||
private SQLLoginService $sqlLoginService;
|
private SQLLoginService $sqlLoginService;
|
||||||
|
@ -47,62 +52,74 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||||
return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST');
|
return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response
|
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): RedirectResponse
|
||||||
{
|
{
|
||||||
return new RedirectResponse($this->baseUrl.'/connect/login-accept');
|
return new RedirectResponse($this->baseUrl . '/connect/login-accept');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): RedirectResponse
|
||||||
{
|
{
|
||||||
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
|
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
|
||||||
|
|
||||||
return new RedirectResponse($this->baseUrl.'/login');
|
return new RedirectResponse($this->baseUrl . '/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authenticate(Request $request): Passport
|
public function authenticate(Request $request): SelfValidatingPassport
|
||||||
{
|
{
|
||||||
$form = $request->request->get('login');
|
$form = $request->request->get('login');
|
||||||
$login = $form['login'];
|
$login = $form['login'];
|
||||||
$plaintextPassword = $form['password'];
|
$plaintextPassword = $form['password'];
|
||||||
$rememberMe = isset($form['_remember_me']) ? true : false;
|
$rememberMe = isset($form['_remember_me']) ? true : false;
|
||||||
|
$session = $request->getSession();
|
||||||
try {
|
try {
|
||||||
// requête préparée
|
// requête préparée
|
||||||
list($remoteHashedPassword, $remoteSalt) = $this->sqlLoginService->fetchPassword($login);
|
list($remoteHashedPassword, $remoteSalt) = $this->sqlLoginService->fetchPassword($login);
|
||||||
} catch (PDOException $e) {
|
} catch (DatabaseConnectionException $e) {
|
||||||
$request->getSession()->set(self::ERROR_SQL_LOGIN, true);
|
$session->set(self::ERROR_PDO, true);
|
||||||
|
throw new AuthenticationException();
|
||||||
|
} catch (LoginElementsConfigurationException $e) {
|
||||||
|
$session->set(self::ERROR_CONFIGURATION, true);
|
||||||
|
throw new AuthenticationException();
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$request->getSession()->set(self::ERROR_LOGIN, true);
|
||||||
throw new AuthenticationException();
|
throw new AuthenticationException();
|
||||||
}
|
}
|
||||||
if ($remoteHashedPassword) {
|
if (!$remoteHashedPassword) {
|
||||||
try {
|
throw new Exception('Erreur inconnue');
|
||||||
// Comparaison remote hash et hash du input password + salt
|
}
|
||||||
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
|
try {
|
||||||
$attributes = $this->sqlLoginService->fetchDatas($login);
|
// Comparaison remote hash et hash du input password + salt
|
||||||
$user = new User($login, $remoteHashedPassword, $attributes, $rememberMe);
|
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
|
||||||
|
$attributes = $this->sqlLoginService->fetchDatas($login);
|
||||||
$loader = function (string $userIdentifier) use ($user) {
|
$user = new User($login, $remoteHashedPassword, $attributes, $rememberMe);
|
||||||
return $user->getLogin() == $userIdentifier ? $user : null;
|
|
||||||
};
|
$loader = function (string $userIdentifier) use ($user) {
|
||||||
$passport = new SelfValidatingPassport(new UserBadge($login, $loader));
|
return $user->getLogin() == $userIdentifier ? $user : null;
|
||||||
if ($rememberMe) {
|
};
|
||||||
$passport->addBadge(new RememberMeBadge());
|
$passport = new SelfValidatingPassport(new UserBadge($login, $loader));
|
||||||
}
|
if ($rememberMe) {
|
||||||
$passport->setAttribute('attributes', $user->getAttributes());
|
$passport->addBadge(new RememberMeBadge());
|
||||||
|
}
|
||||||
vcarroy
commented
Le type de $passport ne correspond pas au return type de la méthode. Le type de $passport ne correspond pas au return type de la méthode.
rmasson
commented
ok ok
|
|||||||
return $passport;
|
$passport->setAttribute('attributes', $user->getAttributes());
|
||||||
} catch (InvalidSQLPasswordException $e) {
|
|
||||||
$request->getSession()->set(self::ERROR_PASSWORD, true);
|
return $passport;
|
||||||
throw new AuthenticationException();
|
} catch (InvalidSQLPasswordException $e) {
|
||||||
} catch (PDOException $e) {
|
$session->set(self::ERROR_LOGIN, true);
|
||||||
$request->getSession()->set(self::ERROR_SQL_LOGIN, true);
|
throw new AuthenticationException();
|
||||||
throw new AuthenticationException();
|
} catch (DataToFetchConfigurationException $e) {
|
||||||
}
|
$session->set(self::ERROR_DATA_TO_FETCH_CONFIGURATION, true);
|
||||||
|
throw new AuthenticationException();
|
||||||
|
} catch (DatabaseConnectionException $e) {
|
||||||
|
$session->set(self::ERROR_PDO, true);
|
||||||
|
throw new AuthenticationException();
|
||||||
|
} catch (SecurityPatternConfigurationException $e) {
|
||||||
|
$session->set(self::ERROR_SECURITY_PATTERN_CONFIGURATION, true);
|
||||||
|
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
|
||||||
{
|
{
|
||||||
return $this->baseUrl.'/login';
|
return $this->baseUrl . '/login';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,63 +2,87 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\SQLLogin\Exception\DatabaseConnectionException;
|
||||||
|
use App\SQLLogin\Exception\DataToFetchConfigurationException;
|
||||||
|
use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||||
|
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 Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
||||||
class SQLLoginService extends AbstractController
|
class SQLLoginService extends AbstractController
|
||||||
{
|
{
|
||||||
public SQLLoginRequest $sqlLoginRequest;
|
public SQLLoginRequest $sqlLoginRequest;
|
||||||
|
|
||||||
public function __construct(SQLLoginRequest $sqlLoginRequest)
|
public function __construct(SQLLoginRequest $sqlLoginRequest, private LoggerInterface $loggerInterface)
|
||||||
{
|
{
|
||||||
$this->sqlLoginRequest = $sqlLoginRequest;
|
$this->sqlLoginRequest = $sqlLoginRequest;
|
||||||
|
$this->loggerInterface = $loggerInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchDatas(string $login)
|
public function fetchDatas(string $login): array
|
||||||
vcarroy
commented
typer $login (mixed possible) typer $login (mixed possible)
rmasson
commented
ok ok
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbh = $this->getConnection();
|
$dbh = $this->getConnection();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$this->loggerInterface->critical($e->getMessage());
|
||||||
|
throw new DatabaseConnectionException($e->getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
// forge de la requête
|
// forge de la requête
|
||||||
$request = $this->sqlLoginRequest->getRequestScope();
|
$request = $this->sqlLoginRequest->getRequestScope();
|
||||||
|
} catch (NullDataToFetchException $e) {
|
||||||
|
throw new DataToFetchConfigurationException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Préparation de la requête
|
// Préparation de la requête
|
||||||
$query = $dbh->prepare($request);
|
$query = $dbh->prepare($request);
|
||||||
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
||||||
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
\Sentry\captureException($e);
|
$this->loggerInterface->critical($e->getMessage());
|
||||||
|
throw new DataToFetchConfigurationException($e->getMessage());
|
||||||
throw new PDOException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $datas;
|
return $datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
vcarroy
commented
typer $login (mixed possible) typer $login (mixed possible)
rmasson
commented
ok ok
|
|||||||
public function fetchPassword(string $login)
|
public function fetchPassword(string $login): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbh = $this->getConnection();
|
$dbh = $this->getConnection();
|
||||||
$request = $this->sqlLoginRequest->getRequestPassword();
|
} catch (PDOException $e) {
|
||||||
|
$this->loggerInterface->critical($e->getMessage());
|
||||||
|
throw new DatabaseConnectionException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// forge de la requête
|
||||||
|
$request = $this->sqlLoginRequest->getRequestPassword();
|
||||||
|
|
||||||
|
try {
|
||||||
$query = $dbh->prepare($request);
|
$query = $dbh->prepare($request);
|
||||||
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
||||||
$password = $query->fetch(PDO::FETCH_ASSOC);
|
$password = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
\Sentry\captureException($e);
|
$this->loggerInterface->critical($e->getMessage());
|
||||||
throw new PDOException();
|
throw new LoginElementsConfigurationException($e->getMessage());
|
||||||
}
|
}
|
||||||
if ($password) {
|
if (!$password) {
|
||||||
return [
|
throw new Exception('Une erreur est survenue lors de la récupération des données');
|
||||||
$password[$this->sqlLoginRequest->getPasswordColumnName()],
|
|
||||||
isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return [
|
||||||
|
$password[$this->sqlLoginRequest->getPasswordColumnName()],
|
||||||
|
isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConnection()
|
public function getConnection(): PDO
|
||||||
{
|
{
|
||||||
// Appel du singleton
|
// Appel du singleton
|
||||||
$sqlLogin = SQLLoginConnect::getInstance();
|
$sqlLogin = SQLLoginConnect::getInstance();
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="fXVg5Zq" resname="error.login">
|
<trans-unit id="fXVg5Zq" resname="error.login">
|
||||||
<source>error.login</source>
|
<source>error.login</source>
|
||||||
<target>Incorrect login</target>
|
<target>Incorrect login or password</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="8VJKwdK" resname="error.password">
|
|
||||||
<source>error.password</source>
|
|
||||||
<target>Incorrect password</target>
|
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="36t19qm" resname="error.sql_login">
|
<trans-unit id="36t19qm" resname="error.sql_login">
|
||||||
<source>error.sql_login</source>
|
<source>error.sql_login</source>
|
||||||
|
@ -21,6 +17,18 @@
|
||||||
<source>error.pdo</source>
|
<source>error.pdo</source>
|
||||||
<target>Connection to database encountered a problem</target>
|
<target>Connection to database encountered a problem</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="1QRR4uA" resname="error.configuration">
|
||||||
|
<source>error.configuration</source>
|
||||||
|
<target>Identification data references do not exist in the database</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="4EPIhsV" resname="error.data_to_fetch_configuration">
|
||||||
|
<source>error.data_to_fetch_configuration</source>
|
||||||
|
<target>Data references to be transmitted do not exist</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="6iuTNs3" resname="error.security_pattern_configuration">
|
||||||
|
<source>error.security_pattern_configuration</source>
|
||||||
|
<target>The security pattern is not allowed</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="fXVg5Zq" resname="error.login">
|
<trans-unit id="fXVg5Zq" resname="error.login">
|
||||||
<source>error.login</source>
|
<source>error.login</source>
|
||||||
<target>Login incorrect ou inconnu</target>
|
<target>Login ou mot de passe inconnu</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="8VJKwdK" resname="error.password">
|
|
||||||
<source>error.password</source>
|
|
||||||
<target>Mot de passe incorrect</target>
|
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="36t19qm" resname="error.sql_login">
|
<trans-unit id="36t19qm" resname="error.sql_login">
|
||||||
<source>error.sql_login</source>
|
<source>error.sql_login</source>
|
||||||
|
@ -19,7 +15,19 @@
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="lBole_G" resname="error.pdo">
|
<trans-unit id="lBole_G" resname="error.pdo">
|
||||||
<source>error.pdo</source>
|
<source>error.pdo</source>
|
||||||
<target>La connexion à la base de déonnées à rencontré un problème</target>
|
<target>La connexion à la base de données a rencontré un problème</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="1QRR4uA" resname="error.configuration">
|
||||||
|
<source>error.configuration</source>
|
||||||
|
<target>Les références de données d'identification n'existent pas dans la base de données</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="4EPIhsV" resname="error.data_to_fetch_configuration">
|
||||||
|
<source>error.data_to_fetch_configuration</source>
|
||||||
|
<target>Les références de données à transmettre n'existent pas</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="6iuTNs3" resname="error.security_pattern_configuration">
|
||||||
|
<source>error.security_pattern_configuration</source>
|
||||||
|
<target>Le patron de sécurité n'est pas autorisé</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
|
|
Loading…
Reference in New Issue
Inverser cette condition
ok