feat (gestion exception) #19: modification fetchPassword
Some checks reported warnings
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
Some checks reported warnings
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
This commit is contained in:
@ -10,6 +10,7 @@ use App\SQLLogin\Exception\DataToFetchConfigurationException;
|
||||
use App\SQLLogin\Exception\InvalidSQLPasswordException;
|
||||
use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||
use App\SQLLogin\Exception\SecurityPatternConfigurationException;
|
||||
use Exception;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@ -24,7 +25,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||
{
|
||||
public const LOGIN_ROUTE = 'app_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_CONFIGURATION = 'error_configuration';
|
||||
@ -80,40 +80,42 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||
} 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();
|
||||
}
|
||||
if ($remoteHashedPassword) {
|
||||
try {
|
||||
// Comparaison remote hash et hash du input password + salt
|
||||
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
|
||||
$attributes = $this->sqlLoginService->fetchDatas($login);
|
||||
$user = new User($login, $remoteHashedPassword, $attributes, $rememberMe);
|
||||
if (!$remoteHashedPassword) {
|
||||
throw new Exception('Erreur inconnue');
|
||||
}
|
||||
try {
|
||||
// Comparaison remote hash et hash du input password + salt
|
||||
$this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt);
|
||||
$attributes = $this->sqlLoginService->fetchDatas($login);
|
||||
$user = new User($login, $remoteHashedPassword, $attributes, $rememberMe);
|
||||
|
||||
$loader = function (string $userIdentifier) use ($user) {
|
||||
return $user->getLogin() == $userIdentifier ? $user : null;
|
||||
};
|
||||
$passport = new SelfValidatingPassport(new UserBadge($login, $loader));
|
||||
if ($rememberMe) {
|
||||
$passport->addBadge(new RememberMeBadge());
|
||||
}
|
||||
$passport->setAttribute('attributes', $user->getAttributes());
|
||||
|
||||
return $passport;
|
||||
} catch (InvalidSQLPasswordException $e) {
|
||||
$session->set(self::ERROR_PASSWORD, true);
|
||||
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();
|
||||
$loader = function (string $userIdentifier) use ($user) {
|
||||
return $user->getLogin() == $userIdentifier ? $user : null;
|
||||
};
|
||||
$passport = new SelfValidatingPassport(new UserBadge($login, $loader));
|
||||
if ($rememberMe) {
|
||||
$passport->addBadge(new RememberMeBadge());
|
||||
}
|
||||
$passport->setAttribute('attributes', $user->getAttributes());
|
||||
|
||||
return $passport;
|
||||
} catch (InvalidSQLPasswordException $e) {
|
||||
$session->set(self::ERROR_LOGIN, true);
|
||||
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
|
||||
|
Reference in New Issue
Block a user