Compare commits
No commits in common. "fe4d683c202dfbf38c1a992c406df2e2a009940b" and "27f957124b8c64ddf21153c2a00b4c19478932a2" have entirely different histories.
fe4d683c20
...
27f957124b
@ -4,13 +4,12 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
class CustomErrorController extends AbstractController
|
class CustomErrorController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(path: '/error', name: 'custom_error_controller')]
|
#[Route(path: '/error', name: 'custom_error_controller')]
|
||||||
public function show(FlattenException $exception): Response
|
public function show(FlattenException $exception)
|
||||||
{
|
{
|
||||||
$statusCode = $exception->getStatusCode();
|
$statusCode = $exception->getStatusCode();
|
||||||
$message = $exception->getMessage();
|
$message = $exception->getMessage();
|
||||||
|
@ -4,7 +4,6 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ class LocaleController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: 'locale/{locale?}', name: 'locale_change')]
|
#[Route(path: 'locale/{locale?}', name: 'locale_change')]
|
||||||
public function changeLocal(?string $locale, Request $request): RedirectResponse
|
public function changeLocal(?string $locale, Request $request)
|
||||||
{
|
{
|
||||||
if (empty($locale)) {
|
if (empty($locale)) {
|
||||||
$locale = $this->params->get('default_locale');
|
$locale = $this->params->get('default_locale');
|
||||||
|
@ -8,18 +8,18 @@ use App\Hydra\HydraService;
|
|||||||
use App\SQLLogin\SQLLoginRequest;
|
use App\SQLLogin\SQLLoginRequest;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||||
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
|
||||||
class MainController extends AbstractController
|
class MainController extends AbstractController
|
||||||
{
|
{
|
||||||
private HydraService $hydra;
|
public HydraService $hydra;
|
||||||
private Client $client;
|
public Client $client;
|
||||||
private SessionInterface $session;
|
public SessionInterface $session;
|
||||||
|
|
||||||
public function __construct(SessionInterface $session, HydraService $hydra, Client $client)
|
public function __construct(SessionInterface $session, HydraService $hydra, Client $client)
|
||||||
{
|
{
|
||||||
@ -33,7 +33,6 @@ class MainController extends AbstractController
|
|||||||
{
|
{
|
||||||
return $this->hydra->handleLoginRequest($request);
|
return $this->hydra->handleLoginRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Route de Healthcheck (notament pour kubernetes)
|
* Route de Healthcheck (notament pour kubernetes)
|
||||||
*/
|
*/
|
||||||
@ -44,7 +43,7 @@ class MainController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/connect/login-accept', name: 'app_login_accept', methods: ['GET'])]
|
#[Route('/connect/login-accept', name: 'app_login_accept', methods: ['GET'])]
|
||||||
public function loginAccept(SQLLoginRequest $sqlLoginRequest): RedirectResponse
|
public function loginAccept(Request $request, SQLLoginRequest $sqlLoginRequest): RedirectResponse
|
||||||
{
|
{
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class SecurityController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/logout', name: 'logout')]
|
#[Route('/logout', name: 'logout')]
|
||||||
public function logout(Request $request): void
|
public function logout(Request $request)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
|||||||
|
|
||||||
class User implements UserInterface
|
class User implements UserInterface
|
||||||
{
|
{
|
||||||
private array $attributes = [];
|
protected array $attributes = [];
|
||||||
private string $login;
|
private string $login;
|
||||||
private string $password;
|
private string $password;
|
||||||
private bool $rememberMe;
|
private bool $rememberMe;
|
||||||
|
@ -16,7 +16,7 @@ class LocaleSubscriber implements EventSubscriberInterface
|
|||||||
$this->defaultLocale = $defaultLocale;
|
$this->defaultLocale = $defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onKernelRequest(RequestEvent $event): void
|
public function onKernelRequest(RequestEvent $event)
|
||||||
{
|
{
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
if (!$request->hasPreviousSession()) {
|
if (!$request->hasPreviousSession()) {
|
||||||
@ -32,7 +32,7 @@ class LocaleSubscriber implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubscribedEvents(): array
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
KernelEvents::REQUEST => [['onKernelRequest', 20]],
|
KernelEvents::REQUEST => [['onKernelRequest', 20]],
|
||||||
|
@ -14,10 +14,10 @@ class SQLLoginRequest
|
|||||||
public const TABLE_NAME = 'table_name';
|
public const TABLE_NAME = 'table_name';
|
||||||
public const SUBJECT_REWRITE_EXPRESSION = 'subject_rewrite_expression';
|
public const SUBJECT_REWRITE_EXPRESSION = 'subject_rewrite_expression';
|
||||||
|
|
||||||
private array $config;
|
protected array $config;
|
||||||
private string $dsn;
|
protected string $dsn;
|
||||||
private string $user;
|
protected string $user;
|
||||||
private string $password;
|
protected string $password;
|
||||||
|
|
||||||
public function __construct(string $dsn, string $user, string $password, array $config = [])
|
public function __construct(string $dsn, string $user, string $password, array $config = [])
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ class SQLLoginRequest
|
|||||||
return $this->config[self::SUBJECT_REWRITE_EXPRESSION];
|
return $this->config[self::SUBJECT_REWRITE_EXPRESSION];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequestScope(): string
|
public function getRequestScope()
|
||||||
{
|
{
|
||||||
$scope = '';
|
$scope = '';
|
||||||
if (!$this->config[self::DATA_TO_FETCH]) {
|
if (!$this->config[self::DATA_TO_FETCH]) {
|
||||||
@ -80,12 +80,12 @@ class SQLLoginRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
||||||
$scope .= $data.',';
|
$scope .= $data . ',';
|
||||||
}
|
}
|
||||||
// On enlève la dernière virgule
|
// 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() . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,9 +96,9 @@ class SQLLoginRequest
|
|||||||
{
|
{
|
||||||
$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() . ';';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
|||||||
/**
|
/**
|
||||||
* Pas utilisé, mais on doit le garder pour le implements
|
* Pas utilisé, mais on doit le garder pour le implements
|
||||||
*/
|
*/
|
||||||
public function hash(string $plainPassword, ?string $salt = null): string
|
public function hash(string $plainPassword, string $salt = null): string
|
||||||
{
|
{
|
||||||
if ($this->isPasswordTooLong($plainPassword)) {
|
if ($this->isPasswordTooLong($plainPassword)) {
|
||||||
throw new InvalidPasswordException();
|
throw new InvalidPasswordException();
|
||||||
@ -39,7 +39,7 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
|||||||
return hash($plainPassword.$salt, $this->hashAlgoLegacy[0]);
|
return hash($plainPassword.$salt, $this->hashAlgoLegacy[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verify(string $hashedPassword, string $plainPassword, ?string $salt = null): bool
|
public function verify(string $hashedPassword, string $plainPassword, string $salt = null): bool
|
||||||
{
|
{
|
||||||
if ('' === $plainPassword || $this->isPasswordTooLong($plainPassword)) {
|
if ('' === $plainPassword || $this->isPasswordTooLong($plainPassword)) {
|
||||||
return false;
|
return false;
|
||||||
@ -76,8 +76,10 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne la string à hasher en fonction du pattern indiqué
|
* Retourne la string à hasher en fonction du pattern indiqué
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getPasswordToHash(string $plainTextPassword, ?string $salt = null): string
|
protected function getPasswordToHash($plainTextPassword, $salt)
|
||||||
{
|
{
|
||||||
$arrayRef = [
|
$arrayRef = [
|
||||||
self::PASSWORD_PATTERN => $plainTextPassword,
|
self::PASSWORD_PATTERN => $plainTextPassword,
|
||||||
@ -99,7 +101,7 @@ class PasswordEncoder implements LegacyPasswordHasherInterface
|
|||||||
return $completedPlainPassword;
|
return $completedPlainPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function compareSsha(string $hashPassword, string $plainPassword): bool
|
protected function compareSsha($hashPassword, $plainPassword)
|
||||||
{
|
{
|
||||||
$base_64_hash_with_salt = substr($hashPassword, 6);
|
$base_64_hash_with_salt = substr($hashPassword, 6);
|
||||||
$hash_with_salt = base64_decode($base_64_hash_with_salt);
|
$hash_with_salt = base64_decode($base_64_hash_with_salt);
|
||||||
|
@ -31,7 +31,7 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
|||||||
public const ERROR_DATA_TO_FETCH_CONFIGURATION = 'error_data_to_fetch_configuration';
|
public const ERROR_DATA_TO_FETCH_CONFIGURATION = 'error_data_to_fetch_configuration';
|
||||||
public const ERROR_SECURITY_PATTERN_CONFIGURATION = 'error_security_pattern_configuration';
|
public const ERROR_SECURITY_PATTERN_CONFIGURATION = 'error_security_pattern_configuration';
|
||||||
|
|
||||||
private string $baseUrl;
|
protected string $baseUrl;
|
||||||
private SQLLoginService $sqlLoginService;
|
private SQLLoginService $sqlLoginService;
|
||||||
private PasswordEncoder $passwordHasher;
|
private PasswordEncoder $passwordHasher;
|
||||||
|
|
||||||
@ -54,14 +54,14 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
|||||||
|
|
||||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): RedirectResponse
|
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): RedirectResponse
|
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): SelfValidatingPassport
|
public function authenticate(Request $request): SelfValidatingPassport
|
||||||
@ -86,7 +86,7 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null === $remoteHashedPassword) {
|
if (null === $remoteHashedPassword) {
|
||||||
$remoteHashedPassword = '';
|
$remoteHashedPassword = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -122,6 +122,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
|||||||
|
|
||||||
protected function getLoginUrl(Request $request): string
|
protected function getLoginUrl(Request $request): string
|
||||||
{
|
{
|
||||||
return $this->baseUrl.'/login';
|
return $this->baseUrl . '/login';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class SQLLoginUserProvider implements UserProviderInterface
|
|||||||
return $this->loadUserByIdentifier($username, null);
|
return $this->loadUserByIdentifier($username, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refreshUser(UserInterface $user): UserInterface|null
|
public function refreshUser(UserInterface $user)
|
||||||
{
|
{
|
||||||
if (!$user instanceof User) {
|
if (!$user instanceof User) {
|
||||||
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
|
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
|
||||||
@ -40,7 +40,7 @@ class SQLLoginUserProvider implements UserProviderInterface
|
|||||||
return $this->loadUserByIdentifier($user->getUserIdentifier(), $user);
|
return $this->loadUserByIdentifier($user->getUserIdentifier(), $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsClass(string $class): bool
|
public function supportsClass(string $class)
|
||||||
{
|
{
|
||||||
return User::class === $class || is_subclass_of($class, User::class);
|
return User::class === $class || is_subclass_of($class, User::class);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||||||
|
|
||||||
class SQLLoginService extends AbstractController
|
class SQLLoginService extends AbstractController
|
||||||
{
|
{
|
||||||
private SQLLoginRequest $sqlLoginRequest;
|
public SQLLoginRequest $sqlLoginRequest;
|
||||||
|
|
||||||
public function __construct(SQLLoginRequest $sqlLoginRequest, private LoggerInterface $loggerInterface)
|
public function __construct(SQLLoginRequest $sqlLoginRequest, private LoggerInterface $loggerInterface)
|
||||||
{
|
{
|
||||||
@ -56,7 +56,6 @@ class SQLLoginService extends AbstractController
|
|||||||
if (false === $datas) {
|
if (false === $datas) {
|
||||||
throw new Exception(sprintf('La requête sql "%s" a renvoyé un résultat incorrect.', $request));
|
throw new Exception(sprintf('La requête sql "%s" a renvoyé un résultat incorrect.', $request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $datas;
|
return $datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +83,13 @@ class SQLLoginService extends AbstractController
|
|||||||
if (!$password) {
|
if (!$password) {
|
||||||
throw new Exception('Une erreur est survenue lors de la récupération des données');
|
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,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getConnection(): PDO
|
public function getConnection(): PDO
|
||||||
{
|
{
|
||||||
// Appel du singleton
|
// Appel du singleton
|
||||||
$sqlLogin = SQLLoginConnect::getInstance();
|
$sqlLogin = SQLLoginConnect::getInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user