attributes->get('_route') && $request->isMethod('POST'); } public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): RedirectResponse { return new RedirectResponse($this->baseUrl.'/connect/login-accept'); } public function onAuthenticationFailure(Request $request, AuthenticationException $exception): RedirectResponse { $request->getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception); return new RedirectResponse($this->baseUrl.'/login'); } public function authenticate(Request $request): SelfValidatingPassport { $form = $request->request->all(key: 'login'); $login = $form['login']; $plaintextPassword = $form['password']; $session = $request->getSession(); try { $datas = $this->sqlLoginService->fetchPasswordAndDatas($login); } catch (EmptyResultException $e) { $session->set(self::ERROR_LOGIN, true); throw new AuthenticationException(); } catch (DataToFetchConfigurationException|\PDOException $e) { \Sentry\captureException($e); $session->set(self::TECHNICAL_ERROR, true); throw new AuthenticationException(); } $remoteHashedPassword = $datas[$this->sqlLoginRequest->getPasswordColumnName()]; unset($datas[$this->sqlLoginRequest->getPasswordColumnName()]); $remoteSalt = null; if ($this->sqlLoginRequest->getSaltColumnName() && isset($datas[$this->sqlLoginRequest->getSaltColumnName()])) { $remoteSalt = $datas[$this->sqlLoginRequest->getSaltColumnName()]; unset($datas[$this->sqlLoginRequest->getSaltColumnName()]); } if (null === $remoteHashedPassword) { $remoteHashedPassword = ''; } try { // Comparaison remote hash et hash du input password + salt $this->passwordHasher->verify($remoteHashedPassword, $plaintextPassword, $remoteSalt); } catch (InvalidSQLPasswordException $e) { $session->set(self::ERROR_LOGIN, true); throw new AuthenticationException(); } catch (SecurityPatternConfigurationException $e) { \Sentry\captureException($e); $session->set(self::TECHNICAL_ERROR, true); throw new AuthenticationException(); } $user = new User($login, $remoteHashedPassword, $datas); $loader = function (string $userIdentifier) use ($user): UserInterface { if ($user->getLogin() !== $userIdentifier) { throw new UserNotFoundException(sprintf('User "%s" not found.', $userIdentifier)); } return $user; }; $passport = new SelfValidatingPassport(new UserBadge($login, $loader)); $passport->setAttribute('attributes', $user->getAttributes()); return $passport; } protected function getLoginUrl(Request $request): string { return $this->baseUrl.'/login'; } }